Sign in to follow this  
Cuculain

Using Win32 Picture Control in a dialog

Recommended Posts

I'm trying to display a static bitmap with a Picture Control in a dialog created using CreateDialog (vs7 C++ app), but I just can't get it to appear. Should be the simplest thing but - not. The image appears during construction of the dialog and it's correctly imported etc - I've tried all possible settings - but it's just blank when the dialog is displayed. If I put borders on the control they show so it's not obscured either. All other controls like buttons etc works like they should. Any ideas what could possibly be wrong or what I'm missing?

Share this post


Link to post
Share on other sites
I have never utilized picture controls because I simply do not need them to display pictures in dialog boxes; instead, I just add the picture myself via Bitblt.


BOOL CALLBACK My_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_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,1,0,530,450,image_dc,0,0,SRCCOPY);
}
break;
...
//Clean-up!
case IDC_DIALOG_EXIT:
{
SelectObject(image_dc,old_hbitmap);
DeleteObject(hbitmap);
ReleaseDC(hwnd, hdc);
DeleteDC(image_dc);
EndDialog(hwnd,0);
immature=TRUE;
done=TRUE;
}
break;




IDB_SPLASH is a resource reference to your bitmap. IDB_SPALSH mypic.bmp or enter in a pathname in its place for non-integration.

Hope this helps.

Share this post


Link to post
Share on other sites
Xiachunyi:
You got yourself a nice resource leak there. You should call DeleteDC/ReleaseDC/DeleteObject inside WM_PAINT too. Other than that it will work of course.

Cuculain:
Show the code snippet for loading/setting the bitmap in the picture control.

Share this post


Link to post
Share on other sites
It is, but WM_PAINT will probably be called more than once, and then you create another bitmap/dc, but only one gets deleted.

You could also put the bitmap loading code inside WM_CREATE, so it gets loaded only once. This would probably be good for performance too. The dc creating/deleting is best placed in WM_PAINT, as you did already, since on different windows version the number of DCs available is very limited.

Share this post


Link to post
Share on other sites
Well there is no code as such. I just drag a Picture Control from the Toolbox to the dialog. Using properties I assign the bitmap I want to display and it correctly shows up on the dialog being constructed.

I create the dialog like this:

HDIALOG hDialog = ::CreateDialog(NULL, MAKEINTRESOURCE(IDD_MYDIALOG), hWnd,
(DLGPROC)::DialogCallback);

ShowWindow(hDialog, SW_SHOW);

Everything, callbacks etc works fine, but the bitmap is missing when I run the app.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this