我用双缓冲画图,但一闪而过,
void CMy0823_1Dlg::OnPaint()
{
CPaintDC dc(this);
RECT ClientRect;
::GetClientRect(m_hWnd,&ClientRect);
UINT ClientWidth=ClientRect.right-ClientRect.left;
UINT ClientHeight=ClientRect.bottom-ClientRect.top; HDC hScrDC= dc.m_hDC ; //创建屏幕DC
HDC hMemDC=CreateCompatibleDC(hScrDC); //创建内存DC
HBITMAP bitmap=::CreateCompatibleBitmap(hScrDC,ClientWidth,ClientHeight);//创建兼容位图内存块,存放图片数据
HBITMAP OldBitmap=(HBITMAP)::SelectObject(hMemDC,bitmap); //内存hMemDC与位图内存块相关联 //先画整个客户区的背景
::FillRect(hMemDC,&ClientRect,(HBRUSH)GetStockObject(WHITE_BRUSH)); //填充颜色矩形
HBRUSH brush=::CreateSolidBrush(RGB(255,123,216));
RECT rect={0,0,1000,1000};
::FillRect(hMemDC,&rect,brush);
::DeleteObject(brush); //画空矩形2
::SelectObject(hMemDC,(HBRUSH)GetStockObject(NULL_BRUSH));
::Rectangle(hMemDC,10,10,1000,1000);
/* for(int j=0;j<1;j++)
{
MemDC.MoveTo(gline[j-1]/1,grow[j-1]/100);
MemDC.LineTo(gline[j]/100,grow[j]/100);
}*/
MemDC.MoveTo(100,100);
MemDC.LineTo(200,200);//编译可以通过,可是点击感叹号就说dubug ASSERTion FAILD什么的
// MyDraw();//自己定义的画图函数,用他图花了,一闪而过,就没有了 BitBlt(hScrDC,0,0,ClientWidth,ClientHeight,hMemDC,0,0,SRCCOPY); ::SelectObject(hMemDC,OldBitmap); //bitmap指向的内存块再也没有和hMemDC挂钩,之后你可以使用bitmap所指向的图片数据了
::DeleteObject(bitmap); //释放位图所占Memory
::DeleteDC(hMemDC) ; //删除内存DC
// ::ReleaseDC(m_hWnd,hScrDC) ; //释放屏幕DC if (IsIconic())
{
CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (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
{ void CMy0823_1Dlg::OnPaint() ; }
}//刚接触c++,不是很了解,求高人指点
void CMy0823_1Dlg::OnPaint()
{
CPaintDC dc(this);
RECT ClientRect;
::GetClientRect(m_hWnd,&ClientRect);
UINT ClientWidth=ClientRect.right-ClientRect.left;
UINT ClientHeight=ClientRect.bottom-ClientRect.top; HDC hScrDC= dc.m_hDC ; //创建屏幕DC
HDC hMemDC=CreateCompatibleDC(hScrDC); //创建内存DC
HBITMAP bitmap=::CreateCompatibleBitmap(hScrDC,ClientWidth,ClientHeight);//创建兼容位图内存块,存放图片数据
HBITMAP OldBitmap=(HBITMAP)::SelectObject(hMemDC,bitmap); //内存hMemDC与位图内存块相关联 //先画整个客户区的背景
::FillRect(hMemDC,&ClientRect,(HBRUSH)GetStockObject(WHITE_BRUSH)); //填充颜色矩形
HBRUSH brush=::CreateSolidBrush(RGB(255,123,216));
RECT rect={0,0,1000,1000};
::FillRect(hMemDC,&rect,brush);
::DeleteObject(brush); //画空矩形2
::SelectObject(hMemDC,(HBRUSH)GetStockObject(NULL_BRUSH));
::Rectangle(hMemDC,10,10,1000,1000);
/* for(int j=0;j<1;j++)
{
MemDC.MoveTo(gline[j-1]/1,grow[j-1]/100);
MemDC.LineTo(gline[j]/100,grow[j]/100);
}*/
MemDC.MoveTo(100,100);
MemDC.LineTo(200,200);//编译可以通过,可是点击感叹号就说dubug ASSERTion FAILD什么的
// MyDraw();//自己定义的画图函数,用他图花了,一闪而过,就没有了 BitBlt(hScrDC,0,0,ClientWidth,ClientHeight,hMemDC,0,0,SRCCOPY); ::SelectObject(hMemDC,OldBitmap); //bitmap指向的内存块再也没有和hMemDC挂钩,之后你可以使用bitmap所指向的图片数据了
::DeleteObject(bitmap); //释放位图所占Memory
::DeleteDC(hMemDC) ; //删除内存DC
// ::ReleaseDC(m_hWnd,hScrDC) ; //释放屏幕DC if (IsIconic())
{
CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (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
{ void CMy0823_1Dlg::OnPaint() ; }
}//刚接触c++,不是很了解,求高人指点
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货