Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a dialog that opens an other dialog, I must close only the second dialog
if I use this code:

ASSERT(AfxGetMainWnd() != NULL);
AfxGetMainWnd()->SendMessage(WM_CLOSE);


I close the first and the second dialog, how must I do?

What I have tried:

<pre>
	ASSERT(AfxGetMainWnd() != NULL);
	AfxGetMainWnd()->SendMessage(WM_CLOSE);
Posted
Updated 1-Sep-21 4:52am

1 solution

AfxGetMainWnd[^] does what the name suggests - it fetches the main window CWnd for the application.
So sending a WM_CLOSE message to that will always close the application, and both windows.

What you need to do is send WM_CLOSE to the second dialog - which means locating the CWnd instance for that. If you are using CDialog as the base class, it derives from CWnd, so you can get it directly from your constructed instance before you display it.
 
Share this answer
 
Comments
Member 14594285 1-Sep-21 11:06am    
Ok thanks, now it works
OriginalGriff 1-Sep-21 11:35am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900