不会,谢谢大家了!
解决方案 »
- 请教电子白板处理滚动条OnVScroll事件?
- 关于WINDOWS程序设计一书中鼠标那章的一点怀疑,发现了书上说的是错的!!!
- SOS,关于BCG标签之间切换的问题。
- 动态改变静态文本框内容上的一点疑惑
- 捕获所有的异常
- 如何获得Program Files目录的路径
- 请问哪位做了记事本的,能把原代码给我参考一下吗?(我刚学MFC)
- 一个莱鸟问题-》怎样把一个BMP文件添加到VC的资源中《-问题解决就结贴
- 为何,枚举注册表中的项时,为何有时项名读出不完整呀!(高人请进)
- 请问,如何在另一个应用程序的Edit框中自动输入文字
- 怎么在我的窗口中显示jpg?散分,散分。。。。。。
- 那我的scrollbar想根据document的变化改变,怎么办??
不知道OnCtrlColor行不行,不行就DrawItem了
不要误人子弟,叫人笑掉大牙!
-----------------------
WM_DRAWITEM 消息
并且设置按钮具有OWNERDRAW 风格
void CToolDialog::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: Add your message handler code here and/or call default
if(nIDCtl==IDC_BUTTON_TEST)
{
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;
CButton *pButton=(CButton*)this->GetDlgItem(IDC_BUTTON_TEST);
if(pButton)
pButton->GetWindowText(strText);
// Draw the button text using the text blue red.
COLORREF crOldColor = ::SetTextColor(lpDrawItemStruct->hDC, RGB(0,0,255));
::DrawText(lpDrawItemStruct->hDC, strText, strText.GetLength(),
&lpDrawItemStruct->rcItem, DT_SINGLELINE|DT_VCENTER|DT_CENTER);
::SetTextColor(lpDrawItemStruct->hDC, crOldColor);
}
CDialog::OnDrawItem(nIDCtl, lpDrawItemStruct);
}
http://www.vckbase.com/ 上面可以去下一个,需要把 BCMenu.h/cpp 和 BtnST.h/cpp 加到你的工程中去
BOOL Attach(const UINT nID, CWnd* pParent, const COLORREF BGColor = RGB(192, 123, 192), // 按纽的背景色const COLORREF FGColor = RGB(1, 1, 1), // 文本颜色);protected:virtual void DrawItem(LPDRAWITEMSTRUCT lpDIS); //重定义虚拟函数DrawItemvoid DrawFrame(CDC *DC, CRect R); //绘制按纽框void DrawFilledRect(CDC *DC, CRect R, COLORREF color); //填充按纽框void DrawLine(CDC *DC, CRect EndPoints, COLORREF color); void DrawLine(CDC *DC, long left, long top, long right, long bottom, COLORREF color);void DrawButtonText(CDC *DC, CRect R, const char *Buf, COLORREF TextColor);//绘制按纽上的文本
COLORREF GetFGColor() { return m_fg; } COLORREF GetBGColor() { return m_bg; }private:COLORREF m_fg, m_bg;};#endif
第二步:定义各函数//CcolorButton.cpp……// CColorButtonIMPLEMENT_DYNAMIC(CColorButton, CButton)CColorButton::CColorButton() { } CColorButton::~CColorButton(){}
//定义Attach()函数BOOL CColorButton::Attach(const UINT nID, CWnd* pParent, const COLORREF BGColor, const COLORREF FGColor){if (!SubclassDlgItem(nID, pParent))return FALSE;m_fg = FGColor;m_bg = BGColor; return TRUE;}
//重载DrawItem()void CColorButton::DrawItem(LPDRAWITEMSTRUCT lpDIS){CDC* pDC = CDC::FromHandle(lpDIS->hDC);UINT state = lpDIS->itemState; CRect focusRect, btnRect;focusRect.CopyRect(&lpDIS->rcItem); //按纽的选中虚线框btnRect.CopyRect(&lpDIS->rcItem);
// 设置表示按纽被选中的虚线框focusRect.left += 4;focusRect.right -= 4;focusRect.top += 4;focusRect.bottom -= 4;
// 按纽标题const int bufSize = 512;TCHAR buffer[bufSize];GetWindowText(buffer, bufSize);
// 绘制并标志按纽 DrawFilledRect(pDC, btnRect, GetBGColor()); DrawFrame(pDC, btnRect);DrawButtonText(pDC, btnRect, buffer, GetFGColor());
// 如果按纽处于选中状态则在其上绘制选中虚线框if (state & ODS_FOCUS) {DrawFocusRect(lpDIS->hDC, (LPRECT)&focusRect);}}void CColorButton::DrawFrame(CDC *DC, CRect R){ //绘制按纽,用户通过定制该函数可实现不同形状的按纽。DrawLine(DC, R.left, R.top, R.right, R.top, RGB(255, 255, 255)); DrawLine(DC, R.left, R.top, R.left, R.bottom, RGB(255, 255, 255)); //以下绘制按纽的外围框线以使按纽有立体感DrawLine(DC, R.left + 1, R.bottom - 1, R.right, R.bottom - 1, RGB(1, 1, 1));//绘制按纽左框线和上框线DrawLine(DC, R.right - 1, R.top + 1, R.right - 1, R.bottom, RGB(1, 1, 1));//绘制按纽右框线和下框线 }//用色彩填充按纽框void CColorButton::DrawFilledRect(CDC *DC, CRect R, COLORREF color){ CBrush B;B.CreateSolidBrush(color);DC->FillRect(R, &B);}// DrawLine用于绘制按纽,其为多态函数void CColorButton::DrawLine(CDC *DC, CRect EndPoints, COLORREF color){ ……}void CColorButton::DrawLine(CDC *DC, long left, long top, long right, long bottom, COLORREF color){ ……}//绘制按纽文本void CColorButton::DrawButtonText(CDC *DC, CRect R, const char *Buf, COLORREF TextColor){COLORREF prevColor = DC->SetTextColor(TextColor);DC->SetBkMode(TRANSPARENT);DC->DrawText(Buf, strlen(Buf), R, DT_CENTER|DT_VCENTER|DT_SINGLELINE);DC->SetTextColor(prevColor);}
第三步:引用定制类定制任意对话框CColorDlg,在其上画一按键控件。ID为IDOK。//CColorDlg.hclass CColorDlg : public CDialog{…..// Implementationprotected:CColorButton m_btnOK;}
//CColorDlg.cpp…….BOOL CColorBtnSampleDlg::OnInitDialog(){CDialog::OnInitDialog();…….VERIFY(m_btnOK.Attach(IDOK, this, RED, BLUE, YELLOW));…….}……
要用上面的方法.
自己画.
我不明白怎么把一个IDOK一样的画上去的button跟一个自己定义的button类结合起来。