zhuang
June 23rd, 1999, 09:21 PM
I'd like to choose a different background color for my dialog box? Is there any way to do that? Any suggestion is thankful.
|
Click to See Complete Forum and Search --> : How to change the background color of a dialog? zhuang June 23rd, 1999, 09:21 PM I'd like to choose a different background color for my dialog box? Is there any way to do that? Any suggestion is thankful. Erich Ruth June 23rd, 1999, 11:10 PM 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? olivier June 24th, 1999, 03:41 AM >>If you want to change background color of 1 dialog box, declare a member variable and override the WM_CTCOLOR method ... zhuang June 24th, 1999, 12:27 PM 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 the Fresh! June 24th, 1999, 09:48 PM 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! zhuang June 26th, 1999, 12:22 AM Thanks a million to all who helped. It works great. Thanks again. codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |