Affichage d'une image dans une boite de dialogue

Résolu
cs_meem Messages postés 12 Date d'inscription jeudi 17 juin 2004 Statut Membre Dernière intervention 31 juillet 2004 - 29 juil. 2004 à 12:28
cs_meem Messages postés 12 Date d'inscription jeudi 17 juin 2004 Statut Membre Dernière intervention 31 juillet 2004 - 30 juil. 2004 à 08:53
Bonjour,

J'essaie d'afficher un bitmap dans une boite de dialogue sous VC++.NET.

Voici le code que j'utilise :

void InterfaceContour::OnBnClickedButton1()
{
CImage cim;
cim.Load("bip.bmp");
cim.Draw( (HDC) *GetDC(),0,0,150,100,0,0,720,576);

}

Une image totalement noire s'affiche alors sur ma boîte de dialogue.

Quelqu'un voit-il une solution ?

D'avance merci,

Cordialement,

Meem

3 réponses

cs_thierry la fronde Messages postés 351 Date d'inscription mercredi 21 juillet 2004 Statut Membre Dernière intervention 12 août 2009
29 juil. 2004 à 15:44
Peut-être que cette fonction t'aidera ?

Fonction applicable à un CBitmap !
SetBitmap( ::LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_MONBITMAP)))

D'autres infos dans la msdn.

thierry le frondeur
3
cs_imanewin32 Messages postés 70 Date d'inscription mardi 30 mars 2004 Statut Membre Dernière intervention 12 août 2004
29 juil. 2004 à 18:55
utilise Ce code peu etre que ce t'edra:

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

//----------------------------------------------------------
// MAIN WNDPROC
//----------------------------------------------------------
LRESULT CALLBACK MainWndProc(HWND hwnd,UINT iMsg,WPARAM wParam,LPARAM lParam)
{
static int cxClient,cyClient,cxImage,cyImage;
static HDC hdcCompatible;
static HBITMAP bmp,oldBmp;

switch (iMsg)
{
case WM_CREATE:
{
HDC hdc;
BITMAP infoBmp;

hdc = GetDC(hwnd);

hdcCompatible = CreateCompatibleDC(hdc);
if(NULL (bmp LoadBitmap((HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE),MAKEINTRESOURCE(ID_BMP))))
{
return -1;
}

if(0 == GetObject(bmp,sizeof(BITMAP),(LPVOID)(&infoBmp)))
{
return -1;
}

cxImage = infoBmp.bmWidth;
cyImage = infoBmp.bmHeight;

oldBmp = SelectObject(hdcCompatible,bmp);

ReleaseDC(hwnd,hdc);

return 0;
}

case WM_SIZE:
{
cxClient = LOWORD(lParam);
cyClient = HIWORD(lParam);

InvalidateRect(hwnd,NULL,TRUE);
return 0;
}
case WM_PAINT:
{
HDC hdc;
PAINTSTRUCT ps;

hdc = BeginPaint(hwnd,&ps);

if(!BitBlt(
hdc,
(cxClient - cxImage)/2,
(cyClient - cyImage)/2,
cxImage,
cyImage,
hdcCompatible,
0,
0,
SRCCOPY
))
{
PostQuitMessage(1);
}

EndPaint(hwnd,&ps);
return 0;
}
case WM_DESTROY:
{
SelectObject(hdcCompatible,oldBmp);
DeleteObject(bmp);
DeleteDC(hdcCompatible);

PostQuitMessage(0);
return 0;
}
}

return DefWindowProc(hwnd,iMsg,wParam,lParam);
} // MainWndProc()
//----------------------------------------------------------
// WIN MAIN
//----------------------------------------------------------
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int iCmdShow)
{
MSG msg;
HWND hwnd;
WNDCLASSEX wndclass;

wndclass.cbSize = sizeof(wndclass);
wndclass.style = 0;
wndclass.lpfnWndProc = MainWndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = NULL;
wndclass.hCursor = LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE+1);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = "JCD_BITMAP";
wndclass.hIconSm = NULL;

if(0 == RegisterClassEx(&wndclass))
{
return -1;
}
if(NULL (hwnd CreateWindow("JCD_BITMAP","Comment afficher une Bitmap ...",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL)))
{
return -1;
}

ShowWindow(hwnd,iCmdShow);
UpdateWindow(hwnd);

while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
} // WinMain()
3
cs_meem Messages postés 12 Date d'inscription jeudi 17 juin 2004 Statut Membre Dernière intervention 31 juillet 2004
30 juil. 2004 à 08:53
Merci à tous les deux !

Cordialement,

Meem
0
Rejoignez-nous