void COwnBmpButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: Add your code to draw the specified item
CDC ButtonDC;
CBitmap BitMapTrans;
BITMAP bmp;
CDC mem;
CRect rc;
ButtonDC.Attach(lpDrawItemStruct->hDC);
mem.CreateCompatibleDC(&ButtonDC);
GetClientRect(&rc);
//rc = lpDrawItemStruct->rcItem;
UINT state = lpDrawItemStruct->itemState;
if(!m_State)
{
BitMapTrans.LoadBitmap(IDB_DOWN);
BitMapTrans.GetBitmap(&bmp);
CBitmap *old = mem.SelectObject(&BitMapTrans);
ButtonDC.StretchBlt(rc.left,rc.top,rc.right,rc.bottom,&mem,0,0,bmp.bmWidth,bmp.bmHeight,SRCCOPY);
mem.SelectObject(old);
BitMapTrans.DeleteObject();
ButtonDC.SetBkMode(TRANSPARENT);
ButtonDC.SetTextColor(RGB(0,110,100));
ButtonDC.DrawText(m_strFocus,&rc,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
}
else
{
BitMapTrans.LoadBitmap(IDB_UP);
CBitmap *old2 = mem.SelectObject(&BitMapTrans);
BitMapTrans.GetBitmap(&bmp);
CBitmap *old = mem.SelectObject(&BitMapTrans);
ButtonDC.StretchBlt(rc.left,rc.top,rc.right,rc.bottom,&mem,0,0,bmp.bmWidth,bmp.bmHeight,SRCCOPY);
ButtonDC.SetBkMode(TRANSPARENT);
ButtonDC.SetTextColor(RGB(0,110,100));
ButtonDC.DrawText(m_strLostFocus,&rc,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
mem.SelectObject(old2);
BitMapTrans.DeleteObject();
}
}以上代码是自绘按钮中显示位图,现在在窗体中添加多个这种按钮,每个按钮显示不同的位图,结果当鼠标移动到按钮上时偶尔会出现闪烁白色区域,是不是刷新的问题,如果用双缓存该怎么改呢,请大侠指点!!在线等,答者有分
{
// TODO: Add your code to draw the specified item
CDC ButtonDC;
CBitmap BitMapTrans;
BITMAP bmp;
CDC mem;
CRect rc;
ButtonDC.Attach(lpDrawItemStruct->hDC);
mem.CreateCompatibleDC(&ButtonDC);
GetClientRect(&rc);
//rc = lpDrawItemStruct->rcItem;
UINT state = lpDrawItemStruct->itemState;
if(!m_State)
{
BitMapTrans.LoadBitmap(IDB_DOWN);
BitMapTrans.GetBitmap(&bmp);
CBitmap *old = mem.SelectObject(&BitMapTrans);
ButtonDC.StretchBlt(rc.left,rc.top,rc.right,rc.bottom,&mem,0,0,bmp.bmWidth,bmp.bmHeight,SRCCOPY);
mem.SelectObject(old);
BitMapTrans.DeleteObject();
ButtonDC.SetBkMode(TRANSPARENT);
ButtonDC.SetTextColor(RGB(0,110,100));
ButtonDC.DrawText(m_strFocus,&rc,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
}
else
{
BitMapTrans.LoadBitmap(IDB_UP);
CBitmap *old2 = mem.SelectObject(&BitMapTrans);
BitMapTrans.GetBitmap(&bmp);
CBitmap *old = mem.SelectObject(&BitMapTrans);
ButtonDC.StretchBlt(rc.left,rc.top,rc.right,rc.bottom,&mem,0,0,bmp.bmWidth,bmp.bmHeight,SRCCOPY);
ButtonDC.SetBkMode(TRANSPARENT);
ButtonDC.SetTextColor(RGB(0,110,100));
ButtonDC.DrawText(m_strLostFocus,&rc,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
mem.SelectObject(old2);
BitMapTrans.DeleteObject();
}
}以上代码是自绘按钮中显示位图,现在在窗体中添加多个这种按钮,每个按钮显示不同的位图,结果当鼠标移动到按钮上时偶尔会出现闪烁白色区域,是不是刷新的问题,如果用双缓存该怎么改呢,请大侠指点!!在线等,答者有分
解决方案 »
- 32位系统下生成的exe文件,无法在64位里连接SQL数据库
- 文件的异常处理?
- 线程同步的概念问题
- 请问我想在基于对话框的程序里 画一些简单的曲线图 除了直接 用循环来LINETO或者逐点绘制 之外还有啥方便的好方法么?
- C++怎么描述等待串口数据
- 我想拦截全局的CreateFileA函数,怎么办?就是所有应用程序调用CreateFileA都会执行我的代码?
- 如何改变控件自动产生的滚动条为XP型或用位图改变!
- 小声的问句既生unsigned long何生DWORD
- 对话框中,怎样取得多个CButton中我所单击的CButton的资源号?
- marconi 请进来拿分
- TWAIN barcode 条形码 识别
- 现在在监控软件是怎么分屏的?
按钮本身重载"OnEraseBackgroud" 直接return TRUE
// click state, 按下去的状态
if( lpDrawItemStruct -> itemState & ODS_SELECTED {
}
else if ( m_hover)// hover state, 移上去的状态
{
}
else// enable state, 正常的状态
{
}
你加载Bitmap时 只需加载一次 放在OnInitDlg 中