customize background mfc dlg

fenomeno83's Avatar
Light Poster
how can i customize background of mfc dialog box?
a simple example?
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Just drawing on the dc in the PAINT method will do your job.

Here is the default PAINT method of the default dialog based MFC
Code: CPP
if (IsIconic())
    {
        CPaintDC dc(this); // device context for painting

        SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

        // Center icon in client rectangle
        int cxIcon = GetSystemMetrics(SM_CXICON);
        int cyIcon = GetSystemMetrics(SM_CYICON);
        CRect rect;
        GetClientRect(&rect);
        int x = (rect.Width() - cxIcon + 1) / 2;
        int y = (rect.Height() - cyIcon + 1) / 2;

        // Draw the icon
        dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
        CDialog::OnPaint();
    }
Just replace it with
Code: CPP
if (IsIconic())
    {
        CPaintDC dc(this); // device context for painting

        SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

        // Center icon in client rectangle
        int cxIcon = GetSystemMetrics(SM_CXICON);
        int cyIcon = GetSystemMetrics(SM_CYICON);
        CRect rect;
        GetClientRect(&rect);
        int x = (rect.Width() - cxIcon + 1) / 2;
        int y = (rect.Height() - cyIcon + 1) / 2;

        // Draw the icon
        dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
        CPaintDC dc(this); // device context for painting

        CRect rc;
        GetClientRect(&rc);
        dc.FillSolidRect(rc,RGB(98,84,84));
       
        CDialog::OnPaint();
    }
We just added the following lines
Code: CPP
CPaintDC dc(this); // device context for painting

        CRect rc;
        GetClientRect(&rc);
        dc.FillSolidRect(rc,RGB(98,84,84));
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Sample attached in reply to your other thread customize font mfc dlg
0
fenomeno83's Avatar
Light Poster
Thanks

Last edited by fenomeno83; 19Apr2006 at 17:53..
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Quote:
Originally Posted by fenomeno83
Thanks
My pleasure.