• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1482
  • Last Modified:

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.  
0
lwinkenb
Asked:
lwinkenb
  • 6
  • 4
  • 3
1 Solution
 
nonubikCommented:
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.
0
 
lwinkenbAuthor Commented:
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.
0
 
nonubikCommented:
Are there any controls overlapping with the bitmap? If so, try to change the tab order.
0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
lwinkenbAuthor Commented:
Nope, no controls overlapping.
0
 
nonubikCommented:
Try to look with Spy++ at runtime on the dialog. Is there the "picture" control? Or it's not even created?
0
 
lwinkenbAuthor Commented:
spy++ can find the picture control.  It is of the "static" class.
0
 
nonubikCommented:
And what styles does it has? Must be SS_BITMAP and WS_VISIBLE among them
0
 
lwinkenbAuthor Commented:
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
0
 
_corey_Commented:
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
0
 
lwinkenbAuthor Commented:
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.
0
 
_corey_Commented:
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
0
 
lwinkenbAuthor Commented:
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?
0
 
_corey_Commented:
Yes, you would need to call it on paint to ensure the image is always shown.

But, I am thinking since you just want to display, a simple control you can find would work.

However, for the BitBlt idea, you would setup the bitmap and a device context to hold it such as:

    bitmap = (HBITMAP)LoadImage(hInstance, MAKEINTRESOURCE(IDB_BITMAP1), IMAGE_BITMAP, 0, 0, 0);
   
    bitmapDC = CreateCompatibleDC(GetWindowDC(hWnd));
    SelectObject(bitmapDC, bitmap);

Then for a simple paint handler:

  case WM_PAINT:
    hdc = BeginPaint(hWnd, &ps);
    // TODO: Add any drawing code here...
    BitBlt(hdc, 0, 0, ps.rcPaint.right - ps.rcPaint.left, ps.rcPaint.bottom - ps.rcPaint.top, bitmapDC, 0, 0, SRCCOPY);
    EndPaint(hWnd, &ps);
    break;

You'll need to draw the image initially or cause an immediate re-paint to show it at first.  I suppose setting up the bitmap/device context before showing the window would work.  Again this might be overboard now that I see you don't want an elaborate alpha-masked splash screen.

corey
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 6
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now