Affiche jpg contenu dans exe (win32)

Description

sur demande du forum.
JPG est contenu dans exe en tant que ressource binaire.
Demo FindResource, LoadResource, LockResource, SizeofResource.
Affichage sur zone client de la dialogbox.
Pas de quoi fouetter un chat (le jpg).

Source / Exemple :


#include <windows.h>
#include "resource.h"
#include "bnJpg32.h"

HBITMAP hbmp = 0;
int cxdib, cydib, cxcli, cycli;

void __stdcall LoadBinJpg(HWND hdlg)
{
  HGLOBAL hgbl;
  BYTE *pdata;
  RECT rct;
  HRSRC hrsrc;
  BITMAP bmp;
  GetClientRect(hdlg, &rct);
  cxcli = rct.right; cycli = rct.bottom;
  hrsrc = FindResource(0, (LPCTSTR)IDR_BINJPG1, "BINJPG");
  hgbl = LoadResource(0, hrsrc);
  if(hgbl) {
    pdata = (BYTE*) LockResource(hgbl);
    if(pdata) {
      hbmp = bnBmpFromMemory(pdata, SizeofResource(0, hrsrc));
      if(hbmp) {
        if(GetObject(hbmp, sizeof(bmp), &bmp)) {
          cxdib = bmp.bmWidth; cydib = bmp.bmHeight;
        }
      }
    }
    FreeResource(hgbl);
  }
}

void __stdcall onPaint(HWND hdlg)
{
  PAINTSTRUCT ps;
  HDC hdc, memdc;
  hdc = BeginPaint(hdlg, &ps);
  if(hbmp) {
    memdc = CreateCompatibleDC(hdc);
    SelectObject(memdc, hbmp);
    StretchBlt(hdc, 0, 0, cxcli, cycli, memdc, 0, 0, cxdib, cydib, SRCCOPY);
    DeleteDC(memdc);
  }
  EndPaint(hdlg, &ps);
}

BOOL CALLBACK AppDlgProc(HWND hdlg, UINT mssg, WPARAM wParam, LPARAM lParam)
{
  switch(mssg) {
    case WM_INITDIALOG:
      SetClassLong(hdlg, GCL_HICON, (long)LoadIcon(0, IDI_APPLICATION));
      LoadBinJpg(hdlg);
      return 1;
    case WM_PAINT:
      onPaint(hdlg);
      return 0;
    case WM_COMMAND:
      switch(wParam) {
        case IDOK:
          
          return 0;
        case IDCANCEL: EndDialog(hdlg, 0);
      }
  }
  return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR, int)
{
  DialogBoxParam(hInstance, (LPCTSTR)IDD_APP, 0, AppDlgProc, 0);
  return 0;
}

Conclusion :


zip contient projet complet format VS 2003.
Utilisation libre dans vos progs de la dll jointe a condition de mentionner l'auteur.

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.