CButton* button = (CButton*)thedlg->GetDlgItem(IDC_CONN);
CDC* bcdc = button->GetDC();
bcdc->SetTextColor(RGB(255,0,0));
button->UpdateWindow();
我用以上语句尝试没有任何效果,请高人给一个比较简单的实现方法。。谢谢!
CDC* bcdc = button->GetDC();
bcdc->SetTextColor(RGB(255,0,0));
button->UpdateWindow();
我用以上语句尝试没有任何效果,请高人给一个比较简单的实现方法。。谢谢!
// NOTE: CMyButton is a class derived from CButton. The CMyButton
// object was created as follows:
//
// CMyButton myButton;
// myButton.Create(_T("My button"),
// WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_OWNERDRAW,
// CRect(10,10,100,30), pParentWnd, 1);
//// This example implements the DrawItem method for a CButton-derived
// class that draws the button's text using the color red.
void CMyButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
UINT uStyle = DFCS_BUTTONPUSH; // This code only works with buttons.
ASSERT(lpDrawItemStruct->CtlType == ODT_BUTTON); // If drawing selected, add the pushed style to DrawFrameControl.
if (lpDrawItemStruct->itemState & ODS_SELECTED)
uStyle |= DFCS_PUSHED; // Draw the button frame.
::DrawFrameControl(lpDrawItemStruct->hDC, &lpDrawItemStruct->rcItem,
DFC_BUTTON, uStyle); // Get the button's text.
CString strText;
GetWindowText(strText); // Draw the button text using the text color red.
COLORREF crOldColor = ::SetTextColor(lpDrawItemStruct->hDC, RGB(255,0,0));
::DrawText(lpDrawItemStruct->hDC, strText, strText.GetLength(),
&lpDrawItemStruct->rcItem, DT_SINGLELINE|DT_VCENTER|DT_CENTER);
::SetTextColor(lpDrawItemStruct->hDC, crOldColor);
}
DrawItem要如何调用和传参呢?
{
SetTextColor((HDC)wParam,RGB(255,0,0));
return (long)CreateSolidBrush(RGB(255,255,255));
}
注意此时的按钮必需是自绘风格如果真的想不这样做
SetSysColor();也可以做到,但是这个是所有窗体都会变
你说:就没有简单点的方法吗?我就为一个按钮上的字改个颜色还得费这么大工夫啊
使用好默认的按钮不 是一件容易的事,要是我就不会用默认的按钮,自己实现的很简单,但是系统的不简单,找到接口很麻烦
m_bitmap = ::LoadBitmap(AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDB_MYBUT_BITMAP));
m_Button.SetBitmap(IDB_MYBUT_BITMAP);