自绘制按钮(通过重载DrawItem函数实现)
2010-09-26 19:11
597 查看
void CMyButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: Add your code to draw the specified item
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);
CBrush brushT(RGB(0,0,0)); //背景色
CBrush brushF(RGB(255, 255, 255)); //边框颜色
CDC dc;
COLORREF crOldColor = ::SetTextColor(lpDrawItemStruct->hDC, RGB(255,255,255)); //设置字体颜色
dc.Attach(lpDrawItemStruct->hDC);
dc.FillRect(&lpDrawItemStruct->rcItem, &brushT); //填充按钮背景色
::SetBkColor(lpDrawItemStruct->hDC, RGB(0, 0, 0)); //设置字体背景色
::DrawText(lpDrawItemStruct->hDC, strText, strText.GetLength(), &lpDrawItemStruct->rcItem, DT_SINGLELINE|DT_VCENTER|DT_CENTER); //重绘文字
dc.FrameRect(&lpDrawItemStruct->rcItem, &brushF); //绘按钮边框
::SetBkMode(lpDrawItemStruct->hDC, TRANSPARENT); //设置透明模式
::SetTextColor(lpDrawItemStruct->hDC, crOldColor); //选回字体原来的颜色
dc.Detach();
}
{
// TODO: Add your code to draw the specified item
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);
CBrush brushT(RGB(0,0,0)); //背景色
CBrush brushF(RGB(255, 255, 255)); //边框颜色
CDC dc;
COLORREF crOldColor = ::SetTextColor(lpDrawItemStruct->hDC, RGB(255,255,255)); //设置字体颜色
dc.Attach(lpDrawItemStruct->hDC);
dc.FillRect(&lpDrawItemStruct->rcItem, &brushT); //填充按钮背景色
::SetBkColor(lpDrawItemStruct->hDC, RGB(0, 0, 0)); //设置字体背景色
::DrawText(lpDrawItemStruct->hDC, strText, strText.GetLength(), &lpDrawItemStruct->rcItem, DT_SINGLELINE|DT_VCENTER|DT_CENTER); //重绘文字
dc.FrameRect(&lpDrawItemStruct->rcItem, &brushF); //绘按钮边框
::SetBkMode(lpDrawItemStruct->hDC, TRANSPARENT); //设置透明模式
::SetTextColor(lpDrawItemStruct->hDC, crOldColor); //选回字体原来的颜色
dc.Detach();
}
相关文章推荐
- 自绘实现半透明水晶按钮(继承CButton,设置BS_OWNERDRAW风格,覆盖DrawItem函数绘制按钮,把父窗口的背景复制到按钮上,实现视觉上的透明,最后通过AlphaBlend实现半透明)
- 自己通过坐标转化,实现的一个按钮。绘图绘制的
- 通过javascript实现点击一个按钮触发发音的动作
- 简单笔画轨迹的绘制,并通过保存轨迹点,实现Path的保存和恢复。
- 用ztree实现node在两个div之间移动(通过两个按钮响应事件)
- 通过按钮实现程序自身的重启
- android实现按钮拖动效果及路径的绘制等2D绘图功能---待完善
- C#怎么通过一个按钮Button,实现点击这个按钮可以打开一个文件或者文件夹?
- android端和pc端使用usb进行socket通信,其中android是服务器端,pc是客户端。如何实现安卓端输入的数据通过按钮发送到pc端?
- javascript实现通过表格绘制颜色填充矩形的方法
- 通过按钮控件实现MDI新建子窗口(MFC自动生成的视图、文档、子框架共用)
- 如何实现在当前jsp页面中通过点击按钮来跳转到上一个次访问的页面
- 在页面中,我们经常看到,一个button按钮,如果属标点击,就会触发一个窗口的显示,如果二次点击并可以隐藏,那么如何通过JAVA配合html来实现这一功能呢?
- Android通过Path实现复杂效果(搜索按钮+时钟的实现 +svg实现)
- 一种通过鼠标操作实现多边形的绘制的实现方法
- 通过SpringMVC+Annotation实现方法、按钮级别的细粒度权限控制
- 自绘制按钮的实现
- Android通过Path实现复杂效果(搜索按钮+时钟的实现 )
- 通过按钮点击触发事件实现动态扣血
- 动态的把数据显示在table中,点击某一行的删除按钮实现该行的删除(通过ajax实现页面的无刷新加载)