CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 1999
    Posts
    81

    How to change the background color of a dialog?


    I'd like to choose a different background color for my dialog box? Is there any way to do that? Any suggestion is thankful.


  2. #2
    Join Date
    May 1999
    Location
    Miami, Florida
    Posts
    242

    Re: How to change the background color of a dialog?

    To set default background and text color for dialog and message boxes, you can call

    CWinApp::SetDialogBkColor(COLORREF clrCtlBk, COLORREF clrCtlText)

    The first argument is background color, second is text color. Call this member function from within the InitInstance member function. For example, the following code sets all application's dialogs to display a red backgroun and green text.

    BOOL CTextEditApp::InitInstance()
    {
    SetDialogBkColor(RGB(255,0,0), RGB(0,255,0));
    ...

    If you want to change background color of 1 dialog box, declare a member variable

    protected:
    CBrush m_brush;

    Then add this line in the OnInitDialog function

    BOOL CTestDlg::OnInitDialog()
    {
    m_brush.CreateSolidBrush(RGB(255,255,255));
    ...

    Does this help?


  3. #3
    Join Date
    May 1999
    Location
    Paris, France
    Posts
    216

    Re: How to change the background color of a dialog?

    >>If you want to change background color of 1 dialog box, declare a member variable
    and override the WM_CTCOLOR method ...


  4. #4
    Join Date
    Jun 1999
    Posts
    81

    Re: How to change the background color of a dialog?


    The first method works fine. In second method, I followed your instructions and refered to the reply by olivier, i.e. initializing the m_brush in OnInitDialog:

    m_brush.CreateSolidBrush(RGB(255,0,0));
    and overiding the OnCtlColor as follows

    HBRUSH CCatchDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
    {
    HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
    pDC->SelectObject(&m_brush);
    return hbr;
    }

    The color was not changed. Any mistakes here?



    Regards,

    Zenger Huang


  5. #5
    Join Date
    Jun 1999
    Posts
    33

    Re: How to change the background color of a dialog?

    Try this:

    HBRUSH CCatchDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
    {
    //HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
    //pDC->SelectObject(&m_brush);
    return m_brush;
    }

    Hope this helps.
    the Fresh!

    Heaven is a Playground!

  6. #6
    Join Date
    Jun 1999
    Posts
    81

    Re: How to change the background color of a dialog?

    Thanks a million to all who helped. It works great. Thanks again.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured