displaying a bitmap in a dialog box
I need to load and display a bitmap in a dialog box but I dont know what functions to use to do this. I intend on using GDI. If anybody could answer me, I would greatly appreciate it.
HDC hOffscreenDC;HBITMAP hBitmap;POINT ptBitmapSize;BOOL CALLBACK DlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){ switch(msg) { case WM_INITDIALOG: { //create a DC to hold the bitmap hOffscreenDC = CreateCompatibleDC(GetDC(hwnd)); //load a bitmap from the given file into 'hBitmap' hBitmap = (HBITMAP)LoadImage(0, strBitmapFilename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); BITMAP bitmap; GetObject(hBitmap, sizeof(BITMAP), (void*)&bitmap); ptBitmapSize.x = bitmap.bmWidth; ptBitmapSize.y = bitmap.bmHeight; //select the bitmap onto the offscreen DC SelectObject(hOffscreenDC, hBitmap); return 0; } case WM_PAINT: { PAINTSTRUCT ps; HDC hMainDC = BeginPaint(hwnd, &ps); BitBlt(hOffscreenDC, 0, 0, ptBitmapSize.x, ptBitmapSize.y, hMainDC, 0, 0, SRCCOPY ); EndPaint(hwnd, &ps); return 0; } case WM_CLOSE: { Shutdown(); EndDialog(hwnd, 0); return 0; } default: return 0; }}void Shutdown(){ //deselect the bitmap out of the DC SelectObject(DC, 0); //delete the objects that we created DeleteDC(hOffscreenDC); DeleteObject(hBitmap);}
Note that if your dialog box is modeless (you created it with CreateDialog()) then you should remove the line "EndDialog(hwnd, 0);", and add "DestroyWindow(hwnd);" at the very end of your program (not within the DlgProc() function).
If your dialog is modal, just leave the EndDialog() in there and you should be all set.
-Mike
[edited by - doctorsixstring on January 20, 2003 4:02:57 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement