Thread: SetDialogBkColor( ) Problem in Visual C++.net

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    47

    SetDialogBkColor( ) Problem in Visual C++.net

    I've just upgrated my Visual C++ 6 to Visual C++.net and now this functions seams to not be working !!!!
    I had the following line of command in a previously bugs free running program in Visual C++ 6, declared on xxx::InitInstance()

    Code:
    SetDialogBkColor(RGB(255,200,100), RGB(1,1,1));
    that would give me sort of a yellow mustard color to my dialog window.... the problem is that when I try to run it in my new Visual C++.net compiler, although the program runs... the window comes out with the same gray color that we're used to...

    Question: How can I make SetDialogBkColor( ) to run properly in Visual C++.net ??
    Is there any other function that works better than this one, to change a dialog window default color ???
    I'm a person with a simple taste...
    I only like the best.

  2. #2
    Registered User
    Join Date
    Jul 2003
    Posts
    59
    Text from msdn

    This function is obsolete.

    Remarks
    To set the background color of the dialog box, you must handle WM_CTLCOLOR. This message changes the color of the specified dialog box only.

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    47
    I've been trying to see if I can change the color of a dialog thru WM_CTLCOLOR without success.... here's the code I've been using:
    Code:
    HBRUSH chelloDialogDlg::OnCtlColor(CDC* pDC, CWnd* pwnd, UINT nCtlColor)
    {
    HBRUSH hbr = CDialog::OnCtlColor(pDC, pwnd, nCtlColor);
    if (pwnd->GetDlgCtrlID() == IDD_DIALOG)
    {
    pDC->SetBkColor(RGB(0,255, 0));
    }
    return hbr
    }
    can someone pinpoint me what ham I doing wrong.... I manage to use this with success on edit boxes but not on Buttons or Dialog Windows.....
    I'm a person with a simple taste...
    I only like the best.

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    47
    OK guys and Girls... I've managed to answer my own question...

    To change a background color in Visual C++ .net you cannot use SetDialogBkColor cause it's a obsolet function.... nevertheless, I've manage to do it thru the WM_ERASEBKGND.
    here's the code I've used:
    Code:
    BOOL CHelloDialogDlg::OnEraseBkgnd(CDC* pDC)
    {
    CRect rect;
    GetClientRect(&rect);
    pDC->FillSolidRect(&rect , RGB(255, 0, 0));    // Makes the dialog window Bkground red
    return TRUE;
    }
    hope this might help someone else with the same question.
    I'm a person with a simple taste...
    I only like the best.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  3. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  4. Errors with including winsock 2 lib
    By gamingdl'er in forum C++ Programming
    Replies: 3
    Last Post: 12-05-2005, 08:13 PM
  5. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM