MFC中,使用对话框中弹出的对话框无法控制原对话框的picture control绘图

sdvafd 2018-09-03 02:49:02
我在弹出的对话框的类中添加了如下代码,但是不能控制绘图,请教为什么
if (nResponse == IDOK) // 判断返回值是否为OK按钮(其ID为IDOK,鸡啄米已经将它删除)
{
// TODO: Place code here to handle when the dialog is

// dismissed with OK
}
else if (nResponse == IDCANCEL) // 判断返回值是否为Cancel按钮(其ID为IDCANCEL,鸡啄米将它的Caption改为了“退出”)
{
// TODO: Place code here to handle when the dialog is

// dismissed with Cancel
}
else
{
CWnd* pPictureWnd = GetDlgItem(IDC_PICTRUE1);
CDC *pDC = GetDlgItem(IDC_PICTRUE1)->GetDC();
CRect rc;
GetDlgItem(IDC_PICTRUE1)->GetClientRect(rc);
pDC->MoveTo( 10, 10);
pDC->LineTo( 100, 10);
pDC->MoveTo( 10, 10);
pDC->LineTo( 10, 100);
pPictureWnd->ReleaseDC(pDC);
}
...全文
189 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
schlafenhamster 2018-09-03
  • 打赏
  • 举报
回复
原 对话框 在 子对话框 打开后 ,窗口 被 子 对话框 覆盖 , 子 对话框 ok 后 原 对话框窗口需要 重绘,这时
IDC_PICTRUE1 的 DC 是 无效的,可以 加 一句 RedrawWindow(),使 dc 有效 (客户区有效),再:
RedrawWindow();// 重绘 原 对话框使IDC_PICTRUE1 的 DC 有效
CWnd* pPictureWnd = GetDlgItem(IDC_PICTRUE1);
CDC *pDC = pPictureWnd>GetDC();
CRect rc;
pPictureWnd->GetClientRect(rc);
sdvafd 2018-09-03
  • 打赏
  • 举报
回复
我已知道哪错了,谢谢大家。
正确代码:
CRect rect;
m_picDraw.GetClientRect(&rect);
CDC *pDC=m_picDraw.GetDC();
sdvafd 2018-09-03
  • 打赏
  • 举报
回复
上述代码哪里出错了,导致不能输出正常坐标系
sdvafd 2018-09-03
  • 打赏
  • 举报
回复
CWnd* pPictureWnd= GetDlgItem(IDC_PICTRUE1);
CDC *pDC = GetDlgItem(IDC_PICTRUE1)->GetDC();
ASSERT_VALID(pPictureWnd);
CRect rect;
GetClientRect(&rect);

pDC->SetMapMode(MM_ANISOTROPIC);
pDC->SetViewportOrg(rect.right/2,rect.bottom/2); //偏移后的原点的原坐标
pDC->SetViewportExt(rect.right,rect.bottom);

pDC->SetWindowOrg(0,0); //窗口坐标位置 左上
pDC->SetWindowExt(rect.bottom,(-1)*rect.right);

pDC->MoveTo((-1)*rect.right/2,rect.bottom/2);
pDC->LineTo(rect.right/2,rect.bottom/2);
pDC->MoveTo(0,(-1)*rect.bottom/2);
pDC->LineTo(0,rect.bottom/2);
怎样才能输出一个居中的坐标系
JamesWu9527 2018-09-03
  • 打赏
  • 举报
回复
引用 2 楼 sdvafd 的回复:
我刚学vs编程才几天,有许多不懂的问题。
请问我在button响应函数中添加代码弹出对话框对吗?请问代码中if在判断什么?
CMyDialog1 * dlg;
dlg = new CMyDialog1(this);
INT_PTR nResponse = dlg->DoModal();
if (nResponse == IDOK) // 判断返回值是否为OK按钮(其ID为IDOK,鸡啄米已经将它删除)
{
// TODO: Place code here to handle when the dialog is

// dismissed with OK
}
else if (nResponse == IDCANCEL) // 判断返回值是否为Cancel按钮(其ID为IDCANCEL,鸡啄米将它的Caption改为了“退出”)
{
// TODO: Place code here to handle when the dialog is

// dismissed with Cancel
}


直接使用
CMyDialog1 dlg;
dlg.DoModal();
Eleven 2018-09-03
  • 打赏
  • 举报
回复
把你绘图的代码放到OnPaint函数中去做`
schlafenhamster 2018-09-03
  • 打赏
  • 举报
回复
在子对话框的按钮响应函数中我也加了代码
可以 但 不要 破坏 原 返回 值 即
void CxxxxDlg::OnOK()
{
// TODO: Add extra validation here
你加的代码;
CDialog::OnOK();
}
sdvafd 2018-09-03
  • 打赏
  • 举报
回复
但是在子对话框的按钮响应函数中我也加了代码,这些代码与if (nResponse == IDOK)可以同时存在吗?
schlafenhamster 2018-09-03
  • 打赏
  • 举报
回复
"添加代码弹出对话框对吗?"

对话框上 有 2个 按钮 OK 和 Cancel

if (nResponse == IDOK) 就是说 用户 按了 OK按钮
sdvafd 2018-09-03
  • 打赏
  • 举报
回复
我刚学vs编程才几天,有许多不懂的问题。
请问我在button响应函数中添加代码弹出对话框对吗?请问代码中if在判断什么?
CMyDialog1 * dlg;
dlg = new CMyDialog1(this);
INT_PTR nResponse = dlg->DoModal();
if (nResponse == IDOK) // 判断返回值是否为OK按钮(其ID为IDOK,鸡啄米已经将它删除)
{
// TODO: Place code here to handle when the dialog is

// dismissed with OK
}
else if (nResponse == IDCANCEL) // 判断返回值是否为Cancel按钮(其ID为IDCANCEL,鸡啄米将它的Caption改为了“退出”)
{
// TODO: Place code here to handle when the dialog is

// dismissed with Cancel
}

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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