在OnPaint中设置两个按钮的位置时,出现闪烁当在OnPaint最后添加CDialog::OnPaint()就没有按钮闪烁的问题?
在OnPaint中设置两个按钮的位置时,出现闪烁的问题,当在OnPaint最后添加CDialog::OnPaint()
后两个按钮就不在出现闪烁的问题,请问这是什么原因呢?
BUTTON 按钮是继承 pngbutton类,支持按钮背景贴图的功能。
下面是OnPaint 中的代码,请大家赐教原因,谢谢!
void CDlgClassroom::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
//CDialog::OnPaint();
CPaintDC dc(this);
CRect rect;
GetClientRect(&rect);//对话框当前位置
//设置按钮的位置
_button_speaker.SetWindowPos(NULL,380,rect.bottom-25,_button_speaker.m_nSliceWidth,_button_speaker.m_nHeight,1);
_button_lecture.SetWindowPos(NULL,500,rect.bottom-25,_button_lecture.m_nSliceWidth,_button_lecture.m_nHeight,1);
//画图的方法 StretchBlt 平铺图片
CDC MemDC;
CBitmap cbitmap;
CBitmap* pOldBmp = NULL;
HBITMAP hBitmap;
//画底部工具栏背景图
CDC * pDC = GetDC();
Bitmap backgroundtop(L".\\classroom\\class_toolbar_bottom.png");//加载PNG图片
backgroundtop.GetHBITMAP(Color(0,0,0),&hBitmap); // Bitmap To HBITMAP
CBitmap* cBitmap = CBitmap::FromHandle(hBitmap); // HBITMAP To CBitmap *
MemDC.CreateCompatibleDC(pDC); // 显示图片
pOldBmp = MemDC.SelectObject(cBitmap);
dc.StretchBlt(0,rect.bottom-30,rect.Width(),30 /*rect.Height()*/, &MemDC, 0, 0,backgroundtop.GetWidth() , backgroundtop.GetHeight(), SRCCOPY);
MemDC.SelectObject(pOldBmp); //releaseDC
MemDC.DeleteDC();
cBitmap->DeleteObject();
CDialog::OnPaint();
}
}