komeisa
asked on
Cannot get Static Picture Control (Rectangle Mode) to change color
Hey Everybody;
I am currently trying to get Static Picture Control in Rectangle Mode to Change colors from the default black, grey, or white. Here is my code to do so,
HBRUSH Cdev_discDlg::OnCtlColor(C DC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
switch (nCtlColor) {
case CTLCOLOR_STATIC:
if (pWnd->GetDlgCtrlID() == IDC_myRectangle)
{
pDC->SetBkMode(OPAQUE);
pDC->SetBkColor(RGB(150, 150, 150));
return m_pBkBrush;
}
else
{
pDC->SetTextColor(RGB(54, 51, 127));
pDC->SetBkColor(RGB(209, 208, 226));
}
// Drop through to return the background brush.
case CTRLCOLOR_DLG:
return m_pBkBrush;
default:
return m_pBkBrush;
}
}
Now the function works correctly for all other controls. I can get it to change the dialogue and other static controls but not the rectangle. Any help would be greatly appreciated
I am currently trying to get Static Picture Control in Rectangle Mode to Change colors from the default black, grey, or white. Here is my code to do so,
HBRUSH Cdev_discDlg::OnCtlColor(C
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
switch (nCtlColor) {
case CTLCOLOR_STATIC:
if (pWnd->GetDlgCtrlID() == IDC_myRectangle)
{
pDC->SetBkMode(OPAQUE);
pDC->SetBkColor(RGB(150, 150, 150));
return m_pBkBrush;
}
else
{
pDC->SetTextColor(RGB(54, 51, 127));
pDC->SetBkColor(RGB(209, 208, 226));
}
// Drop through to return the background brush.
case CTRLCOLOR_DLG:
return m_pBkBrush;
default:
return m_pBkBrush;
}
}
Now the function works correctly for all other controls. I can get it to change the dialogue and other static controls but not the rectangle. Any help would be greatly appreciated
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi,
My guess is that SS_xxxRECT style won't work with CtlColor. The following link may explain why.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwui/html/msdn_statictl.asp
SS_BLACKRECT
The SS_BLACKRECT static control displays a frame around the control and fills the control with a solid color that is the same color as the Window Frame (COLOR_WINDOWFRAME). The default Windows color is black. The user can change the color by changing the window frame color in the Control Panel, or an application can call SetSysColors.
Obviously, a static with SS_BLACKRECT seems not relying on the brush passed from CtlColor, instead, it fills the rect with COLOR_WINDOWFRAME. I would also suggest the solution as given by Priyesh.
Any info which shows how this can be done as per given in the question would be appreciated.
AnashPO
My guess is that SS_xxxRECT style won't work with CtlColor. The following link may explain why.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwui/html/msdn_statictl.asp
SS_BLACKRECT
The SS_BLACKRECT static control displays a frame around the control and fills the control with a solid color that is the same color as the Window Frame (COLOR_WINDOWFRAME). The default Windows color is black. The user can change the color by changing the window frame color in the Control Panel, or an application can call SetSysColors.
Obviously, a static with SS_BLACKRECT seems not relying on the brush passed from CtlColor, instead, it fills the rect with COLOR_WINDOWFRAME. I would also suggest the solution as given by Priyesh.
Any info which shows how this can be done as per given in the question would be appreciated.
AnashPO
Handle WM_ERASEBKGND and paint the background
BOOL CMyStatic::OnEraseBkgnd(CD C* pDC)
{
CRect rcBounds;
GetClientRect(&rcBounds);
pDC->FillSolidRect(rcBound s, RGB(255, 0, 0)); // FILL WITH RED
return TRUE;
}
BOOL CMyStatic::OnEraseBkgnd(CD
{
CRect rcBounds;
GetClientRect(&rcBounds);
pDC->FillSolidRect(rcBound
return TRUE;
}
void CMyDialog::OnSomeButton()
{
CRect rect;
CWnd* pWnd = GetDlgItem(IDC_CONTROL_ID)
pWnd->GetWindowRect(&rect)
ScreenToClient(&rect);
rect.left += 10;
rect.right += 10;
pWnd->MoveWindow(&rect);
}