开发者

how to set Button BackColor?

How do I change the ba开发者_如何学JAVAckground color of a button control created using CreateWindow?


The Windows API does not offer many options to customize the appearance of standard controls anymore.

  • WM_CTLCOLORBTN can be handled by the parent window of a button to control some aspects of a buttons appearance, but uxtheme buttons only use the background brush to paint the area behind the button. The appearance of the face is determined by the current theme.

  • WM_DRAWITEM can also be handled by the parent window, by setting the BS_OWNERDRAW style on the button. This allows the parent window to completely replace the normal buttons painting logic.


To manage the color of the controls on your dialog box, add a handler to the WM_CTLCOLOR message in your dialog class.
You will then have to add few lines like that :

HBRUSH CYourDialogClass::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
    HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

    if (pWnd->GetDlgCtrlID() == IDC_OF_YOUR_BUTTON)
    {
        pDC->SetBkColor (RGB(0, 0, 255)); // BLUE color for background
        pDC->SetTextColor (RGB(255, 0, 0)); // RED color for text
    }

    return hbr;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜