我在彈出的對話框的類中添加了如下代碼,但是不能控制繪圖,請教為什么
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);
}
uj5u.com熱心網友回復:
原 對話框 在 子對話框 打開后 ,視窗 被 子 對話框 覆寫 , 子 對話框 ok 后 原 對話框視窗需要 重繪,這時IDC_PICTRUE1 的 DC 是 無效的,可以 加 一句 RedrawWindow(),使 dc 有效 (客戶區有效),再:
RedrawWindow();// 重繪 原 對話框使IDC_PICTRUE1 的 DC 有效
CWnd* pPictureWnd = GetDlgItem(IDC_PICTRUE1);
CDC *pDC = pPictureWnd>GetDC();
CRect rc;
pPictureWnd->GetClientRect(rc);
uj5u.com熱心網友回復:
我剛學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
}
uj5u.com熱心網友回復:
"添加代碼彈出對話框對嗎?"對
對話框上 有 2個 按鈕 OK 和 Cancel
if (nResponse == IDOK) 就是說 用戶 按了 OK按鈕
uj5u.com熱心網友回復:
但是在子對話框的按鈕回應函式中我也加了代碼,這些代碼與if (nResponse == IDOK)可以同時存在嗎?uj5u.com熱心網友回復:
在子對話框的按鈕回應函式中我也加了代碼可以 但 不要 破壞 原 回傳 值 即
void CxxxxDlg::OnOK()
{
// TODO: Add extra validation here
你加的代碼;
CDialog::OnOK();
}
uj5u.com熱心網友回復:
把你繪圖的代碼放到OnPaint函式中去做`uj5u.com熱心網友回復:
直接使用
CMyDialog1 dlg;
dlg.DoModal();
uj5u.com熱心網友回復:
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);
怎樣才能輸出一個居中的坐標系
uj5u.com熱心網友回復:
上述代碼哪里出錯了,導致不能輸出正常坐標系uj5u.com熱心網友回復:
我已知道哪錯了,謝謝大家。正確代碼:
CRect rect;
m_picDraw.GetClientRect(&rect);
CDC *pDC=m_picDraw.GetDC();
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/62469.html
標籤:基礎類
