目标OS:WinCE
IDE:VS 2005
--------------------------------------------------------------------------------------------
CDC m_dcMem;
CBitmap m_bmpMem;//可放到对话框头文件类定义中
为对话框添加WM_PAINT消息
void CETimeDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
// Do not call CDialog::OnPaint() for painting messages
m_dcMem.CreateCompatibleDC(&dc);//创建兼容DC
CString filpath=L"";
filpath+="//NAND//sk//GPS界面主菜单-1.BMP/0"; //图片路径
m_bmpMem.m_hObject=SHLoadDIBitmap(filpath); //图片加载至m_bmpMem
//或者图片作为资源 m_bmpMem.LoadBitmapW(IDB_BITMAP1);
m_dcMem.SelectObject(&m_bmpMem);//位图选入兼容DC
dc.BitBlt(0,0,800,480,&m_dcMem,0,0,SRCCOPY);//兼容DC的位图贴到当前DC
}
问题:1。不添加PAINT消息,将主要代码放到cpp文件的OnInitDialog()函数中,无法实现
2。定义CWnd *m_pView;CDC *m_pDC;
m_pView=GetDlgItem(IDD_ETIME_DIALOG);//IDD_ETIME_DIALOG为程序主对话框ID,获取对话框指针
m_pDC=m_pView->GetDC();//获取对话框的DC指针
//其他代码用m_pDC代替&dc
无论在PAINT函数中还是OnInitDialog()中都无法实现
--------------------------------------------------------------------------------------------------------
按照别人的方法做的双缓冲,感觉与只用一个DC没区别。。。。
void CETimeDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
// Do not call CDialog::OnPaint() for painting messages
CDC dcMem;
CBitmap bmpMem,*oldbmpMem;
dcMem.CreateCompatibleDC(&dc);
bmpMem.CreateCompatibleBitmap(&dc,800,480);
oldbmpMem=dcMem.SelectObject(&bmpMem);
CDC dcMem2;
CBitmap bmpMem2,*oldbmpMem2;
CString filpath=L"";
filpath+="//NAND//sk//GPS界面主菜单-1.BMP/0";
bmpMem2.m_hObject=SHLoadDIBitmap(filpath);
dcMem2.CreateCompatibleDC(&dcMem);
oldbmpMem2=dcMem2.SelectObject(&bmpMem2);
TransparentImage(dcMem.m_hDC,0,0,800,480,dcMem2.m_hDC,0,0,800,480,RGB(255,0,255));
//难道是从兼容DC2复制图片到兼容DC1比较快,不闪屏?
// dcMem2.SelectObject(oldbmpMem2);
// bmpMem2.DeleteObject();
// dcMem2.DeleteDC();
dc.BitBlt(0,0,800,480,&dcMem,0,0,SRCCOPY);
dcMem2.SelectObject(oldbmpMem2);
bmpMem2.DeleteObject();
dcMem2.DeleteDC();
dcMem.SelectObject(oldbmpMem);
bmpMem.DeleteObject();
dcMem.DeleteDC();
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ezhong的博客签名-------------------------------------
以上内容来自ezhong的博客园,作者:ezhong
ezhong的博客园: http://www.cnblogs.com/ezhong
感谢您的阅读。感谢您的分享。