void CMFCApplication2View::OnDraw(CDC* pDC)
{
// TODO: 在此处为本机数据添加绘制代码
CMFCApplication2Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CInputDlg dlg;
int iRet = dlg.DoModal();
if (iRet == IDOK) {
CMFCApplication2Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CRect rect;
GetClientRect(&rect);
pDC->SetMapMode(MM_ANISOTROPIC);
pDC->SetWindowExt(rect.Width(), rect.Height());
pDC->SetViewportExt(rect.Width(), -rect.Height());
pDC->SetViewportOrg(rect.Width() / 2, rect.Height() / 2);
rect.OffsetRect(-rect.Width() / 2, -rect.Height() / 2);
pDC->Rectangle(rect);//清空屏幕
CRectangle Rect;//定义长方形类对象
CString strText;
GetDlgItemText(IDC_EDIT1,strText);
dlg.length.GetWindowText(strText);
Rect.length = _wtof(strText);
CString strText01;
dlg.width.GetWindowText(strText01);
GetDlgItemText(IDC_EDIT2, strText01);
Rect.width = _wtof(strText01);
在 dlg.length.GetWindowText(strText);这里出现不懂的错误。
【以下回答由 GPT 生成】
根据代码片段看,dlg.length.GetWindowText(strText);
这行代码有两个潜在的问题。
首先,CInputDlg
类中的 length
是一个控件变量,不是一个成员变量。所以不能直接使用 dlg.length
来获取控件的文本内容。正确的方式是使用 GetDlgItemText
函数来获取控件的文本内容,就像后面两行代码那样。
其次,GetDlgItemText
函数需要指定控件的 ID,而不是 IDC_EDIT1
或 IDC_EDIT2
这样的宏常量。如果在 CInputDlg
的资源文件中定义了相应的控件 ID,可以根据实际情况来修改代码。
下面是修改后的代码片段:
void CMFCApplication2View::OnDraw(CDC* pDC)
{
// ...
CInputDlg dlg;
int iRet = dlg.DoModal();
if (iRet == IDOK) {
// ...
CRect rect;
GetClientRect(&rect);
pDC->SetMapMode(MM_ANISOTROPIC);
pDC->SetWindowExt(rect.Width(), rect.Height());
pDC->SetViewportExt(rect.Width(), -rect.Height());
pDC->SetViewportOrg(rect.Width() / 2, rect.Height() / 2);
rect.OffsetRect(-rect.Width() / 2, -rect.Height() / 2);
pDC->Rectangle(rect); // 清空屏幕
// ...
CRectangle Rect; // 定义长方形类对象
CString strText;
dlg.GetDlgItemText(IDC_EDIT1, strText);
Rect.length = _wtof(strText);
CString strText01;
dlg.GetDlgItemText(IDC_EDIT2, strText01);
Rect.width = _wtof(strText01);
// ...
}
}
请注意,这里假设 CInputDlg
类存在一个名为 GetDlgItemText
的成员函数,可以从对话框中的控件获取文本内容。如果没有,你需要根据实际情况来修改代码。