mfc中的OnPaint函数问题,有段代码不理解其含义
我只想知道,它刷新了哪几幅图?是在运行一次OnPaint()之后才开始动态刷新还是从一开始就动态刷新?voidCtask1Dlg::OnPaint(){if(IsIcon...
我只想知道,它刷新了哪几幅图?
是在运行一次OnPaint()之后才开始动态刷新还是从一开始就动态刷新?
void Ctask1Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // 用于绘制的设备上下文
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// 使图标在工作区矩形中居中
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;
// 绘制图标
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CPaintDC dc(this);
if(pBmpData!=NULL)
{
CRect rect;
CWnd *pWnd=GetDlgItem(IDC_ShowPicture);
pWnd->GetClientRect(&rect);
CDC *pDC=pWnd->GetDC();
pWnd->GetClientRect(rect);
CDC MemDC;
CBitmap MemBitmap;
HBITMAP HBP=CreateDIBitmap(dc,(BITMAPINFOHEADER*)pBmpInfo,CBM_INIT,pBmpData,pBmpInfo,DIB_RGB_COLORS);
MemDC.CreateCompatibleDC(NULL); //创建兼容DC
MemDC.SelectObject(HBP);
pDC->SetStretchBltMode(HALFTONE);
pDC->StretchBlt(0,0,rect.Width(),rect.Height(),&MemDC,0,0,pBmpInfo->bmiHeader.biWidth,BmpHeight,SRCCOPY);
MemDC.DeleteDC();
MemBitmap.DeleteObject();
if (NULL!=bmpdisplay)
{
pWnd=GetDlgItem(IDC_PICTURE2);
pWnd->GetClientRect(&rect);
pDC=pWnd->GetDC();
pWnd->GetClientRect(rect);
HBP=CreateDIBitmap(dc,(BITMAPINFOHEADER*)pBmpInfo,CBM_INIT,bmpdisplay,pBmpInfo,DIB_RGB_COLORS);
MemDC.CreateCompatibleDC(NULL); //创建兼容DC
MemDC.SelectObject(HBP);
pDC->SetStretchBltMode(HALFTONE);
pDC->StretchBlt(0,0,rect.Width(),rect.Height(),&MemDC,0,0,pBmpInfo->bmiHeader.biWidth,BmpHeight,SRCCOPY);//输出到屏幕,坐标是按对话框大小位置来填
MemDC.DeleteDC();
MemBitmap.DeleteObject();
}
}
CDialogEx::OnPaint();
}
} 展开
是在运行一次OnPaint()之后才开始动态刷新还是从一开始就动态刷新?
void Ctask1Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // 用于绘制的设备上下文
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// 使图标在工作区矩形中居中
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;
// 绘制图标
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CPaintDC dc(this);
if(pBmpData!=NULL)
{
CRect rect;
CWnd *pWnd=GetDlgItem(IDC_ShowPicture);
pWnd->GetClientRect(&rect);
CDC *pDC=pWnd->GetDC();
pWnd->GetClientRect(rect);
CDC MemDC;
CBitmap MemBitmap;
HBITMAP HBP=CreateDIBitmap(dc,(BITMAPINFOHEADER*)pBmpInfo,CBM_INIT,pBmpData,pBmpInfo,DIB_RGB_COLORS);
MemDC.CreateCompatibleDC(NULL); //创建兼容DC
MemDC.SelectObject(HBP);
pDC->SetStretchBltMode(HALFTONE);
pDC->StretchBlt(0,0,rect.Width(),rect.Height(),&MemDC,0,0,pBmpInfo->bmiHeader.biWidth,BmpHeight,SRCCOPY);
MemDC.DeleteDC();
MemBitmap.DeleteObject();
if (NULL!=bmpdisplay)
{
pWnd=GetDlgItem(IDC_PICTURE2);
pWnd->GetClientRect(&rect);
pDC=pWnd->GetDC();
pWnd->GetClientRect(rect);
HBP=CreateDIBitmap(dc,(BITMAPINFOHEADER*)pBmpInfo,CBM_INIT,bmpdisplay,pBmpInfo,DIB_RGB_COLORS);
MemDC.CreateCompatibleDC(NULL); //创建兼容DC
MemDC.SelectObject(HBP);
pDC->SetStretchBltMode(HALFTONE);
pDC->StretchBlt(0,0,rect.Width(),rect.Height(),&MemDC,0,0,pBmpInfo->bmiHeader.biWidth,BmpHeight,SRCCOPY);//输出到屏幕,坐标是按对话框大小位置来填
MemDC.DeleteDC();
MemBitmap.DeleteObject();
}
}
CDialogEx::OnPaint();
}
} 展开
2个回答
展开全部
这个在窗口创建的时候会调用一次,产生无效区域的时候又会调用刷新,比如改变窗口大小,窗口被遮挡,内容更新等,具体请参考WM_PAINT
http://baike.baidu.com/link?url=n_swq3w3g5ygoQc1Y4v8hehLslWfnyhy71TWVAkxhjqQz1lIJxjhcLe9ZbzpyBDzAkG1Gik84kU861aTHsQ_Va
http://baike.baidu.com/link?url=n_swq3w3g5ygoQc1Y4v8hehLslWfnyhy71TWVAkxhjqQz1lIJxjhcLe9ZbzpyBDzAkG1Gik84kU861aTHsQ_Va
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询