How can i set a bitmap as the background of a dialog? i thought of converting the bitmap into a brush and then setting the brush as the background brush with SetClassLong. But when i tried that out, i had to get to know that i can't use bitmaps larger than 8x8 pixels. so how else can i do that? create a static child window as the first child window (so that the other child windows overlap it) and fill it with the bitmap? or are there more professional methods?
Posted on 2001-09-08 08:06:38 by darester
that's not a good idea. the following way would be the easiest: just place a static control on the dialog, that has the same size as it. then put a bitmap in the static control. that's it!

Posted on 2001-09-08 08:45:28 by NOP-erator
My experience is that you can only use bitmaps of 8x8 pixels or larger.
Look here too

Posted on 2001-09-08 08:46:17 by Thomas
But the best method to do this I think is handing the WM_PAINT message of the dialog, and then paint the background with BeginPaint - BitBlt (your bitmap onto the background) - EndPaint

Posted on 2001-09-08 08:48:14 by Thomas
I use this code, it is written in C but it should be easy to translate it in win32asm. It handle WM_ERASEBKGND message. I have used StretchBlt in case users use large fonts (that makes dialog boxes to be resized, so background too).

HBITMAP hBitmap;
RECT ClientRect;


GetClientRect(hWnd, &ClientRect);


hMemDC = CreateCompatibleDC((HDC)wParam);
GetObject (hBitmap, sizeof(BITMAP), &bm);
SelectObject(hMemDC, hBitmap);

StretchBlt(((HDC)wParam, 0, 0, ClientRect.right, ClientRect.bottom,
hMemDC, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);


return 1;
Posted on 2001-09-08 09:27:29 by LuHa
this is made in NASM using NaGoA RAD IDE


;-------Bitmap for the program

call LoadBitmapA, , BITMAPAPP
mov dword , eax
call CreateCompatibleDC, NULL
mov dword , eax
call SelectObject, eax,
call GetObjectA, , BITMAP_size, Bitmap


call BeginPaint, , PaintStruct
mov dword , eax
call BitBlt, , 0, 0, , , , 0, 0, SRCCOPY
call EndPaint, , PaintStruct

mov eax,1
ret 16

Posted on 2001-09-08 10:45:34 by Nguga
Hi again.
Thanks for all the replies! It's almost working now :)
There is still one more problem: i have added a static text window with msvc++ resource editor and the background of the text remains grey.
i did the WM_ERASEBKGND method to paint the background. will this change with the other methods? will the background of the static text window also be painted? or will i have to catch the WM_ERASEBKGND message from the static text window as well and paint it's background seperately?
Posted on 2001-09-08 10:47:28 by darester
Sorry, just found another "bug":
When i stop the mouse cursor above the minimize button in the upper right corner of the window, a quick info text will pop up and this will cause a WM_ERASEBKGND message to the main dialog procedure. but the child windows (all the controls) will not receive this message because the quick info text does not overpaint them. so what can i do against that? send a WM_ERASEBKGND message to all child controls when i process the WM_ERASEBKGND message from the main dialog procedure? or is there another way to prevent overpainting the child controls?

BTW: is there normally not a clipping mechanism for those child controls?

some more info:
i have an initialization routine which loads the bitmap, creates a compatible memory dc with the size of the background bitmap, puts the bitmap in there. then it creates another compatible dc with the size of the client area of the dialog. then it copies the bitmap from the first memory dc with the size of the loaded bitmap into the second memory dc with the size of the client area. this is done by StretchBlt. by doing this, i can repaint the background later much faster because the size of the bitmap already matches the size of the client area, so i won't have to scale every time i have to repaint the background. later in the DrawBackground routine i use BitBlt to copy the background bitmap to the client area. btw: i always repaint the whole client area.
maybe i am doing something wrong? maybe there are other api routines which do that clipping stuff automatically?
Posted on 2001-09-08 11:01:03 by darester
Ok, the last problem is solved (the one with the overpainting all the child controls).
But i still have problems with my static text window.
I'd really appreciate it, if someone would help me on this one too :)
Posted on 2001-09-08 12:34:38 by darester
darester, to make a static window's background transparent you have to use WM_CTLCOLORSTATIC. Here is a little example (always in C :)):

long CtrlID;


CtrlID = GetWindowLong((HWND)lParam, GWL_ID);

if (CtrlID == IDC_STATIC)
SetBkMode((HDC)wParam, TRANSPARENT);
return (long)GetStockObject(NULL_BRUSH);

Posted on 2001-09-08 13:55:40 by LuHa
Oh cool. Thanks a lot again LuHa. I'll immediately try this one out. I'll let you know if it worked for me :)
Posted on 2001-09-09 04:26:50 by darester
Heh thanks a lot. It works fine :)
Posted on 2001-09-09 04:38:39 by darester
A little tip. If you also want to use transparent radio buttons/check boxes don't use WM_CTLCOLORBUTTON, but always WM_CTLCOLORSTATIC (don't ask me why :confused: ). I spent a full afternoon to figure it out.
Posted on 2001-09-09 04:53:51 by LuHa
radio buttons/check boxes don't use WM_CTLCOLORBUTTON, but always WM_CTLCOLORSTATIC (don't ask me why ).

the reason is pretty simple: radio buttons and check boxes consist of a static control. the static control is there, where the text is. that's why you have to use WM_CTLCOLORSTATIC

Posted on 2001-09-09 06:36:34 by NOP-erator
Yes yes, you are right, but MSDN documentation reports this:

Button Types and Styles
There are five kinds of buttons:

push buttons
check boxes
radio buttons
owner-drawn buttons
group boxes
Posted on 2001-09-09 06:49:05 by LuHa
i know, you're right, too. checkboxes and radio buttons are buttons formally, but actually consist of static controls. the text is a static control. when you want to make it transparent, you have to use WM_CTLCOLORSTATIC.
Posted on 2001-09-09 06:52:59 by NOP-erator