如题。查过资料了,好像要自己重载DrawItem,没试成功。希望能给个解决方法。
在CSDN有一个是重载了Button的DrawItem,但把它改成Radio Button时,观感有问题,呵呵。// ============ 底下是参考的原文,是修改成Button的,没能成功地改成Radio Button你可以试下这个:DrawItem()
因为它是CButton::DrawItem ,
你的RADIO也是继承CButton类的,
你重载下DrawItem()。
下面是MSDN上的关于DrawItem的例子。
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);
}
在CSDN有一个是重载了Button的DrawItem,但把它改成Radio Button时,观感有问题,呵呵。// ============ 底下是参考的原文,是修改成Button的,没能成功地改成Radio Button你可以试下这个:DrawItem()
因为它是CButton::DrawItem ,
你的RADIO也是继承CButton类的,
你重载下DrawItem()。
下面是MSDN上的关于DrawItem的例子。
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);
}
解决方案 »
- 关于InvalidateRect()的问题?????
- atlbase.h的这种错误怎么解决?
- (ffmpeg)高手请帮忙,谢谢!!!!!!!!!!!11
- 请教:有关TRACE宏的问题?谢谢
- 窗口退出时发送什么消息?
- 类型CDocument* 如何在OCX中的接口函数中声明?
- 使用pop3收邮件遇到GB2312?B?的编码怎么解码?
- random(100)和temp34是函数么
- 头大的一个问题:(
- 我SetWindowsHookEx成功了(WH_GETMESSAGE),可他就是不走到我的回调函数里去
- 用CreateProcess执行一个dos程式序,若使用管道操作会出现无法输出信息在dos窗口的问题
- no matching symbolic information found.解决方法.急!在线等!!!!!!
重载CMyButton中的CtrlColor
pDC->setTextColor();大概是这样,你试一下。
if(pWnd->GetDlgCtrlID()==IDC_RADIO)
pDC->SetTextColor(RGB(255,0,0))//就可以设置为红色了
同样的设置颜色的代码,在32位下工作正常,64位下就不能改颜色。注:把32位下编译好的程序在64位下运行,RaidoButton的字体颜色也没有改动。
LOGFONT lf;
CRect rect;
CRect winRect;
CFont fontTemp, * pFontOld; dc.GetCurrentFont()->GetLogFont(&lf);
//lstrcpy(lf.lfFaceName, _T("华文隶书"));
lf.lfWidth = 0;
lf.lfWeight = FW_HEAVY;
lf.lfHeight = 0x0F;
fontTemp.CreateFontIndirect(&lf);
pFontOld = dc.SelectObject(&fontTemp);
/*((CButton*)GetDlgItem(IDC_RADIO_TEST))->SetWindowText(_T("Test Bold."));*/
CButton * btn = (CButton*)GetDlgItem(IDC_RADIO_TEST);
btn->GetWindowRect(&rect);
this->GetWindowRect(&winRect);
//dc.DrawText(_T("test bold test."), &rect, DT_BOTTOM);
dc.TextOut(rect.left - winRect.left, rect.top - winRect.top, _T("test bold test."));
//dc.TextOut(100, 0, _T("test bold test."));
dc.SelectObject(pFontOld);
// =================
我用上面的方法改了下,发现用dc的输出是,我可以在Radio Button的位置将字改成粗体,但是那样的话我要把原先的Radio Button的文本位置挑很小,这样的话那些加粗的字才能显示出来。但是这样子的话,就相当与在Radio Button的右边放一个CStatic的控件了,与原先的Radio Button的行为有区别的(比如点字的时候,就可以选中Radio Button)。
pDC->SetTextColor(RGB(255,0,0))//就可以设置为红色了// 现在这个代码不好使了
///////////////////////////////////////
在Dialog中添加WM_CTRLCOLOR响应,添加代码: if(pWnd-> GetDlgCtrlID()==IDC_RADIO)
pDC-> SetTextColor(RGB(255,0,0))//就可以设置为红色了
//////////////////////////////////////////就是改Radio的颜色不行。。不知道怎么回事。