Click here to Skip to main content
15,881,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am workin on (win32 )dialog based project.
is there any way to change background of dialog box with image.
i don't want to use mfc implementation shuld be in win32 only.
Posted
Updated 4-Jan-12 18:25pm
v2

In the OnPaint funtion under else add this
C++
else
{

    CPaintDC dc(this);
    CRect rect;
    GetClientRect(&rect);
    //ScreenToClient(rect);
    BITMAP bmp;
    HBITMAP hBmp = ::LoadBitmap(::AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP2));
    ::GetObject(hBmp, sizeof(bmp), &bmp);
    HDC hDC = ::CreateCompatibleDC(NULL);
    SelectObject(hDC, hBmp);
    ::BitBlt(dc.m_hDC, 0, 0, rect.Width(), rect.Height(), hDC, 0, 0, SRCCOPY);
    CDialog::OnPaint();
}
 
Share this answer
 
Comments
enhzflep 22-Feb-12 7:21am    
While the intent is clear to those familiar with this operation, did you miss the part of the original post that reads "i don't want to use mfc implementation shuld be in win32 only."?

Anyhow, the biggest part of the process you've missed is the getting of the HDC and the HWND. Not such a big deal I guess. My 3+
Here a link you can start with - Using Skins Without MFC[^]
 
Share this answer
 
I cannot remember any Win32 API to Change the background. But How about drawing an image on the dialog in the WM_PAINT message

You will gel help on this link[^] on how to load BITMAP
 
Share this answer
 
Don't do that!

It looks nice in theory, but in practice it does open a large door to a lot of issues (see big font/small font problem).

Another example, is that dialog resources are in DLU (dialog logical units) and are not 1-1 convertible to pixels; so if you want to move UI in the resource editor, you will probably misplace them, and on the other side, if you want perfect positioning you will have to do it by code.

good luck anyway

M.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900