SetBkColor does not seem to work in OnInitDialog
-
hi, i have a dialog box with a static control. the problem is that when i try to use setbkcolor for the static control in oninitdialog of the dialog box, it does not produce any results. i have tried to use GetDC() for the static control to get the DC. and then tried to set the background color of the static control. can any one give me a solution? regards, kevin
-
hi, i have a dialog box with a static control. the problem is that when i try to use setbkcolor for the static control in oninitdialog of the dialog box, it does not produce any results. i have tried to use GetDC() for the static control to get the DC. and then tried to set the background color of the static control. can any one give me a solution? regards, kevin
Look into using the WM_CTLCOLOR Message http://support.microsoft.com/default.aspx?scid=kb;en-us;32685
-
hi, i have a dialog box with a static control. the problem is that when i try to use setbkcolor for the static control in oninitdialog of the dialog box, it does not produce any results. i have tried to use GetDC() for the static control to get the DC. and then tried to set the background color of the static control. can any one give me a solution? regards, kevin
You could also take a look at this excellent article: http://www.codeproject.com/staticctrl/clabel.asp[^] Hope that helps! Sincerely, Alexander Wiseman Est melior esse quam videri It is better to be than to seem
-
hi, i have a dialog box with a static control. the problem is that when i try to use setbkcolor for the static control in oninitdialog of the dialog box, it does not produce any results. i have tried to use GetDC() for the static control to get the DC. and then tried to set the background color of the static control. can any one give me a solution? regards, kevin
SetBkColor()
should be used when handling aWM_PAINT
message or within a control'sDrawItem()
override. Use it to set the background color of the DC for the duration of the painting action. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com -
Look into using the WM_CTLCOLOR Message http://support.microsoft.com/default.aspx?scid=kb;en-us;32685
-
SetBkColor()
should be used when handling aWM_PAINT
message or within a control'sDrawItem()
override. Use it to set the background color of the DC for the duration of the painting action. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com -
using WM_CTLCOLOR causes problems in other parts of my code. is there any other solution?
It should not affect other parts of your code. Here is a sample of my code.
HBRUSH CMyView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CFormView::OnCtlColor(pDC, pWnd, nCtlColor); INT nIDCtl = pWnd->GetDlgCtrlID(); switch(nIDCtl) { case IDC_STATIC_CTRL1: { // Change background color to white so that the // text is easier to read. pDC->SetBkColor(RGB(255, 255, 255)); CBrush br; br.CreateSolidBrush(RGB(255, 255, 255)); hbr = (HBRUSH)br; br.Detach(); } break; case IDC_STATIC_CTRL2: .... .... case IDC_STATIC_CTRL3: .... .... case IDC_STATIC_CTRL4: .... .... } return hbr; }