Go4Expert

Go4Expert (http://www.go4expert.com/)
-   MFC (http://www.go4expert.com/forums/mfc/)
-   -   customize background mfc dlg (http://www.go4expert.com/forums/customize-background-mfc-dlg-t725/)

fenomeno83 14Apr2006 19:24

customize background mfc dlg
 
how can i customize background of mfc dialog box?
a simple example?

shabbir 17Apr2006 10:29

Re: customize background mfc dlg
 
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));


shabbir 17Apr2006 10:48

Re: customize background mfc dlg
 
Sample attached in reply to your other thread customize font mfc dlg

fenomeno83 19Apr2006 16:27

Re: customize background mfc dlg
 
Thanks

shabbir 19Apr2006 18:27

Re: customize background mfc dlg
 
Quote:

Originally Posted by fenomeno83
Thanks

My pleasure.


All times are GMT +5.5. The time now is 00:40.