Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Lord Benoit

displaying a bitmap in a dialog box

This topic is 5727 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement

      
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]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!