Home > Software engineering >  MFC, the use of dialog popup dialog cannot control the picture of the original dialog control drawin
MFC, the use of dialog popup dialog cannot control the picture of the original dialog control drawin

Time:09-22

My class in the pop-up dialog box to add the following code, but can't control drawing, ask why
If (nResponse==IDOK)//to judge whether the return value is the OK button (the ID for the IDOK, chicken peck rice has been deleted it)
{
//TODO: Place code here to handle the when the dialog is

//dismissed with OK
}
Else if (nResponse==IDCANCEL)//whether the return value for the Cancel button (the ID is IDCANCEL, chicken peck rice will change its Caption to "exit")
{
//TODO: Place code here to handle the when the dialog is

//dismissed with Cancel
}
The else
{
The CWnd * pPictureWnd=GetDlgItem (IDC_PICTRUE1);
The CDC * pDC=GetDlgItem (IDC_PICTRUE1) - & gt; GetDC ();
CRect rc;
GetDlgItem (IDC_PICTRUE1) - & gt; GetClientRect (rc);
PDC - & gt; MoveTo (10, 10);
PDC - & gt; The LineTo (100, 10);
PDC - & gt; MoveTo (10, 10);
PDC - & gt; The LineTo (10, 100);
PPictureWnd - & gt; The ReleaseDC (pDC);
}

CodePudding user response:

The original dialog box dialog box opens in the son, window is covered by child dialogs, child dialogs ok after the original dialog window need to redraw the
IDC_PICTRUE1 DC is invalid, can add RedrawWindow (), so that DC (effective) of the client area effectively, again:
RedrawWindow ();//to redraw the original dialog make IDC_PICTRUE1 DC effective
The CWnd * pPictureWnd=GetDlgItem (IDC_PICTRUE1);
The CDC * pDC=pPictureWnd> GetDC ();
CRect rc;
PPictureWnd - & gt; GetClientRect (rc);

CodePudding user response:

I just learn vs programming just for a few days, there are many don't understand the question,
Can you tell me where I add code button response function in the pop-up dialog right? Judge what is the code in the if?
DLG CMyDialog1 *;
DLG=new CMyDialog1 (this);
INT_PTR nResponse=DLG - & gt; DoModal ();
If (nResponse==IDOK)//to judge whether the return value is the OK button (the ID for the IDOK, chicken peck rice has been deleted it)
{
//TODO: Place code here to handle the when the dialog is

//dismissed with OK
}
Else if (nResponse==IDCANCEL)//whether the return value for the Cancel button (the ID is IDCANCEL, chicken peck rice will change its Caption to "exit")
{
//TODO: Place code here to handle the when the dialog is

//dismissed with Cancel
}

CodePudding user response:

"The pop-up dialog box to add code?"
The
2 buttons on the dialog box of OK and Cancel

If (nResponse==IDOK) means that the user press the OK button

CodePudding user response:

But in child dialog button response function I also added a code, the code and the if (nResponse==IDOK) can exist at the same time?

CodePudding user response:

In the dialog box button I also added a of the code from the response function
You can but don't damage the return value is
Void CxxxxDlg: : OnOK ()
{
//TODO: Add extra validation here
You add code;
CDialog: : OnOK ();
}

CodePudding user response:

Put your drawing code in the OnPaint function to do `

CodePudding user response:

refer to the second floor sdvafd response:
I just learn vs programming just for a few days, there are many don't understand the question,
Can you tell me where I add code button response function in the pop-up dialog right? Judge what is the code in the if?
DLG CMyDialog1 *;
DLG=new CMyDialog1 (this);
INT_PTR nResponse=DLG - & gt; DoModal ();
If (nResponse==IDOK)//to judge whether the return value is the OK button (the ID for the IDOK, chicken peck rice has been deleted it)
{
//TODO: Place code here to handle the when the dialog is

//dismissed with OK
}
Else if (nResponse==IDCANCEL)//whether the return value for the Cancel button (the ID is IDCANCEL, chicken peck rice will change its Caption to "exit")
{
//TODO: Place code here to handle the when the dialog is

//dismissed with Cancel
}


Directly using the
CMyDialog1 DLG.
DLG. DoModal ();

CodePudding user response:

The CWnd * pPictureWnd=GetDlgItem (IDC_PICTRUE1);
The CDC * pDC=GetDlgItem (IDC_PICTRUE1) - & gt; GetDC ();
ASSERT_VALID (pPictureWnd);
CRect rect;
GetClientRect (& amp; The rect);

PDC - & gt; SetMapMode (MM_ANISOTROPIC);
PDC - & gt; SetViewportOrg (the rect. Right/2, the rect. Bottom/2);//after the migration of the origin of the original coordinate
PDC - & gt; SetViewportExt (the rect. Right, the rect. Bottom);

PDC - & gt; SetWindowOrg (0, 0);//window coordinates upper left
PDC - & gt; SetWindowExt (the rect. Bottom, (1) * the rect. Right);

PDC - & gt; MoveTo ((1) * the rect. Right/2, the rect. The bottom/2);
PDC - & gt; LineTo (the rect. Right/2, the rect. Bottom/2);
PDC - & gt; MoveTo (0, (1) * the rect. The bottom/2);
PDC - & gt; LineTo (0, the rect. Bottom/2);
How to output a centered coordinate system

CodePudding user response:

The code above where I went wrong, lead to can't output normal coordinate system

CodePudding user response:

I know what is wrong, thank you,
The correct code:
CRect rect;
M_picDraw. GetClientRect (& amp; The rect);
The CDC * pDC=m_picDraw. GetDC ();