首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

对话框背景,该如何解决

2012-03-23 
对话框背景对话框中有button,listbox等控件。运行时,刚开始对话框的控件在bitmap之上,但当你移动对话框时,

对话框背景
对话框中有button,listbox等控件。运行时,刚开始对话框的控件在bitmap之上,      
但当你移动对话框时,那些控件时隐时现,请问这是为什么?      
正确的实现对话框的背景图的方法有是..?      

我是怎么写的:

BOOL   CMy8Dlg::OnEraseBkgnd(CDC*   pDC)  
{
        //   TODO:   Add   your   message   handler   code   here   and/or   call   default
        CClientDC   dc(this);
        CRect   rect;
        GetClientRect(&rect);//得到窗体的大小
        CDC   dcMem;
        dcMem.CreateCompatibleDC(&dc);
        CBitmap   bmpBackground;
        bmpBackground.LoadBitmap(IDB_BITMAP1);//加载背景图片
        BITMAP   bitMap;
        bmpBackground.GetBitmap(&bitMap);
        CBitmap   *pbmpOld=dcMem.SelectObject(&bmpBackground);
        dc.StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,0,0,
                    bitMap.bmWidth,   bitMap.bmHeight,SRCCOPY);//该函数给对话框贴上位图

        return   true;
        return   CDialog::OnEraseBkgnd(pDC);
}

[解决办法]
你把代码改成这样试试
BOOL CMy8Dlg::OnEraseBkgnd(CDC* pDC)
{
CRect rect;
GetClientRect(&rect);//得到窗体的大小
CDC dcMem;
dcMem.CreateCompatibleDC(&pDC);
CBitmap bmpBackground;
bmpBackground.LoadBitmap(IDB_BITMAP1);//加载背景图片
BITMAP bitMap;
bmpBackground.GetBitmap(&bitMap);
CBitmap *pbmpOld=dcMem.SelectObject(&bmpBackground);
pDC-〉StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,0,0,
bitMap.bmWidth, bitMap.bmHeight,SRCCOPY);//该函数给对话框贴上位图

return true;
}

另外,建议你在对话框初始化时将位图导入,
绘图代码写在OnPaint()函数中,
OnEraseBkgnd(CDC* pDC)之返回true

热点排行