Skip to main content
gamedev.net
🔒 Locked

bitmap backround for dialog box

Started by zacharya Jan 3, 2004 at 7:03 AM 1 replies 300+ views
Original Post
zacharya
zacharya
what should I do to get a dialog box with bitmap image background? I searched through the google and found only MFC......
being young is a treasure that can''t be valued
Xiachunyi
Xiachunyi
What you first need to do is create your dialog and allocate a resource position for your bitmap.
Example

IDD_START DIALOG DISCARDABLE 0, 0, 243, 105
STYLE DS_SETFOREGROUND | DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION
CAPTION "Dialogbox with bitmap background"
FONT 8, "MS Sans Serif"
BEGIN
//Stuff "Buttons", "Trackbars", "checkboxes", and so on
END
....
IDB_SPLASH BITMAP DISCARDABLE "Data\\splash.bmp"
...


In the paint case portion of your dialogbox you will need to draw the bitmap like so:

BOOL CALLBACK Start_Dialog(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
{
static HBITMAP hbitmap;
static HDC hdc;
static HDC image_dc;
static HBITMAP old_hbitmap;
switch(message)
{
case WM_INITDIALOG:
{

}
return FALSE;

case WM_PAINT:
{
hbitmap = (HBITMAP)LoadBitmap(GetModuleHandle(NULL),MAKEINTRESOURCE(IDB_SPLASH));
hdc = GetDC(hwnd);
image_dc = CreateCompatibleDC(hdc);
old_hbitmap = (HBITMAP)SelectObject(image_dc,hbitmap);
BitBlt(hdc,4,0,530,450,image_dc,0,0,SRCCOPY);
}
break;

Notice the arguments of BitBlt, the 530 and 450 are the clipping coodinates, size that to the size of your bitmap to show all of it. The 4 and 0 of BitBlt stipluate the starting position of your bitmap since in Windows, from upper left to lower right the coordinates increase.

When you do decide to exit the dialog, you must free your resources:

case WM_CLOSE:
case WM_DESTROY:
{
SelectObject(image_dc,old_hbitmap);
DeleteObject(hbitmap);
ReleaseDC(hwnd, hdc);
DeleteDC(image_dc);
EndDialog(hwnd,0);
}
break;


What you are simply doing is obtaining the bitmap in the resource, drawing context, creating a drawing instance, and copying the bitmap over. Note: Since you are obtaining this through the resources of your executable your compiler will include the bitmap in your executable. To have the bitmap by itself you will need to obtain a pointer to your bitmap and draw from there.

I know there is a way to include the bitmap via resource file alone without the above code but this ensure that you have full control over your bitmap/background.

Hope that helped. If you need I can send over a simple program with the implied code via e-mail.
zacharya
zacharya
thanks for your help
being young is a treasure that can''t be valued

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.