Link to home
Start Free TrialLog in
Avatar of lwinkenb
lwinkenb

asked on

Transparent bitmap on a dialog

I can't seem to figure out how to place a bitmap on a dialog, and make it's background transparent.  I'm using win32 (no MFC).

Basically, I just need a function so I could do something like:

DrawBitmap(hwnd, IDB_BITMAP1, top, left, cr);
Where hwnd is the dialog handle to draw on, IDB_BITMAP1 is the bitmap resource, top and left are the top-left coordinate of where to draw the bitmap, and cr is the COLORREF to make transparent.  
Avatar of nonubik
nonubik

Just make a static control with the SS_BITMAP type and load bitmap into it. With MFC can use CStatic::SetBitmap method. Of course, you need to have a transparent bitmap.
Avatar of lwinkenb

ASKER

I placed a "Picture" control on the dialog in the resource editor (using VC++ 6.0).  For "type" I selected Bitmap.  For "image" I select IDB_BITMAP1.  I then made sure the "Visible" check mark was checked.

I can see my bitmap on the dialog in the resource editor, but when I run the program, the bitmap is not visible.
Are there any controls overlapping with the bitmap? If so, try to change the tab order.
Nope, no controls overlapping.
Try to look with Spy++ at runtime on the dialog. Is there the "picture" control? Or it's not even created?
spy++ can find the picture control.  It is of the "static" class.
And what styles does it has? Must be SS_BITMAP and WS_VISIBLE among them
This is what the .rc file has for the dialog:

IDD_DIALOG_ABOUT DIALOG DISCARDABLE  0, 0, 236, 129
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "About Dialog"
FONT 8, "MS Sans Serif"
BEGIN
    DEFPUSHBUTTON   "OK",IDOK,179,7,50,14
    CONTROL         108,IDC_STATIC,"Static",SS_BITMAP,31,28,112,78
END
Are you trying to create a splash screen effect?

All you really need for that is to create a borderless window, and BitBlt an image to that window's HDC.  I suppose an image wrapper object would work as well.

To create the right kind of window, you just need WS_POPUP, so that nothing but the client area shows.  However, be sure to close the window after a period of time or the user will have to manually close the process.

corey
I'm not trying to create a splash screen.  I just want a regular dialog window with a bitmap on it.  

>>BitBlt an image to that window's HDC.
I don't really understand what that means.
My mistake then, when you mentioned wanting a transparent background, that gave me this impression.

BitBlt, a Win32 API call that allows you do copy direct from one HDC to another.  http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps_0fzo.asp ["BitBlt"]

But I digress apparantly.

corey
If I were to use BitBlt, where would I call the BitBlt() function?  Would I just need to call it once in WM_INITDIALOG, or would I need to call it in WM_PAINT?  Also what function gets me the DC of the bitmap?
ASKER CERTIFIED SOLUTION
Avatar of _corey_
_corey_

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial