c++在picture控件区域用了双缓冲之后,点击按钮无法弹出子对话框,而且主对话框也没有反应

樱花雨2377 2016-06-24 09:04:05
我的c++在picture控件区域用了双缓冲之后,点击按钮无法弹出子对话框,而且主对话框也没有反应


这是刚运行之后出现的界面,没有写子对话框的按钮都可以实现


这是点击了“圆形”按钮,也就是级联了一个子对话框的按钮之后的界面,主对话框没有反应,不能移动也不能关闭


但后来发现在资源管理器关闭主对话框,或者点击键盘上的Alt之后子对话框就可以弹出来了

这是我的代码



// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.

void CMyShapeDlg::OnPaint()
{
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
{
// CDialog::OnPaint();

CRect rect;
CDC *pDC=GetDlgItem(IDC_PICTURE)->GetDC();
GetDlgItem(IDC_PICTURE)->GetClientRect(&rect);
CPen pen(PS_SOLID,1,RGB(255,0,0));

//使用双缓冲技术
CDC dcMem; //内存DC
CBitmap bmpMem; //位图
dcMem.CreateCompatibleDC(pDC); //创建兼容DC

dcMem.SelectObject(pen);
bmpMem.CreateCompatibleBitmap(pDC,rect.right-rect.left,rect.bottom-rect.top); //创建和picture区域一样大小的(空)位图
//把位图选到设备上下文的环境中
CBitmap *pOld=dcMem.SelectObject(&bmpMem);
dcMem.FillSolidRect(rect,pDC->GetBkColor());

//内置圆
CRect rect1=new CRect(0,0,80,80);
dcMem.Ellipse(rect1);

//内置矩形
CRect rect2=new CRect(110,50,210,100);
dcMem.Rectangle(rect2);

//内置三角形
CPoint point[3]={CPoint(250,200),CPoint(300,150),CPoint(350,200)};
dcMem.Polygon(point,3);


//内置椭圆
CRect rect3=new CRect(410,0,510,60);
dcMem.Ellipse(rect3);

//内置梯形
dcMem.MoveTo(25,150);
dcMem.LineTo(75,150);
dcMem.MoveTo(25,150);
dcMem.LineTo(0,200);
dcMem.MoveTo(75,150);
dcMem.LineTo(100,200);
dcMem.MoveTo(0,200);
dcMem.LineTo(100,200);

//点击按钮画圆
for(int i=0;i<m_Circle_Count;i++)
{
dcMem.Ellipse((cx[i]-40),(cy[i]-40),(cx[i]+40),(cy[i]+40));
}

//将内存拷贝懂啊设备dc中
pDC->BitBlt(0,0,rect.right-rect.left,rect.bottom-rect.top,&dcMem, 0, 0, SRCCOPY);
pDC->SelectObject(pOld);
bmpMem.DeleteObject();
dcMem.DeleteDC();


}
}

// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CMyShapeDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}

void CMyShapeDlg::OnCircle()
{
// TODO: Add your control notification handler code here
CDlgAddCircle dlg;
dlg.DoModal();
UpdateData(false);
}




...全文
206 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
flying_music 2016-06-24
  • 打赏
  • 举报
回复
楼主你这是MFC的问题,去那个版块问问吧,这里是C++语言比较多

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧