Voici le code que j'avais l'intention de poster:
#include <windows.h> #include <olectl.h> void AfficheImage(char* path, HWND hwndcible) { HRESULT hres; IPicture* pic; HDC hdc; RECT rect; int hauteur, largeur; WCHAR wpath[260]; MultiByteToWideChar(0,0,path,-1,wpath,260); hres = OleLoadPicturePath(wpath, 0,0, 0, &IID_IPicture, (void**)&pic); hdc=GetDC(hwndcible); GetClientRect(hwndcible,&rect); hres=pic->lpVtbl->get_Width(pic,&largeur); hres=pic->lpVtbl->get_Height(pic,&hauteur); hres=pic->lpVtbl->Render(pic,hdc,0,0,rect.right,rect.bottom,0,hauteur,largeur,-hauteur,0); ReleaseDC(hwndcible,hdc); pic->lpVtbl->Release(pic); } BOOL WINAPI DialogPProc( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) { static HWND hStatic,hBouton; switch(message) { case WM_INITDIALOG: hStatic=CreateWindowEx(0,"STATIC","",WS_VISIBLE | WS_CHILD ,10,80,300,200,hDlg,0,0,0); hBouton=CreateWindowEx(0,"BUTTON","Afficher",WS_VISIBLE | WS_CHILD ,10,10,60,20,hDlg,0,0,0); break; case WM_COMMAND: if((HWND)lParam==hBouton) AfficheImage("c:\\image.jpg",hStatic); break; case WM_CLOSE: EndDialog(hDlg,0); break; default: break; } return 0; } int WINAPI WinMain(HINSTANCE hinst, HINSTANCE prev, LPSTR cmd, int show) { LPDLGTEMPLATE lpdt; CoInitialize(0); lpdt = ( LPDLGTEMPLATE) GlobalAlloc(GPTR, 512); if (!lpdt) return 1; lpdt->style = WS_SYSMENU | DS_CENTER ; lpdt->x 0; lpdt->y 0; lpdt->cx =300; lpdt->cy = 200; DialogBoxIndirectParam(0,lpdt,0,(DLGPROC)DialogPProc,(LPARAM) 0); GlobalFree((HGLOBAL) lpdt); CoUninitialize(); return 0; }
Ici j'utilise la méthode Render() pour afficher l'image directement dans le Device Context d'un STATIC. La fonction AfficheImage() prend en paramètres le chemin de l'image et le HWND du controle sur lequel l'image sera affichée.
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question