Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a dialog with a button and then when I press a button an other dialog opens...then I must close this dialog, I use the function "CloseWindow" but it's minimized and it doesn't disappear..how can I do?
My code when I press button in the first dialog:
<pre>  
        void CDlgEstimateTime::OnBnClickedBtnFormati()
{
        CDlgMy dialog;

		dialog.DoModal();
}



<pre>
 in dlgDialog:

	    AfxMessageBox(IDS_STRING330, MB_ICONERROR);
		ShowWindow(SW_MINIMIZE);
		ShowWindow(SW_HIDE);		
		return;


but CDlgMy isn't hidden.

in CDlgMy:

BOOL CDlgFormati::OnInitDialog()
{
	CDialog::OnInitDialog();
    FillList();
    return TRUE;
}
in FillList there is ShowWindow(SW_HIDE);


What I have tried:

I tried to use the function CloseWindow
Posted
Updated 19-Sep-22 2:20am
v3
Comments
Richard MacCutchan 19-Sep-22 5:34am    
My code does exactly what yours does, and the dialog is hidden. The only difference is that my code is plain Win32 rather than MFC. However that should not make any significant difference. Where exactly in your dialog code are those calls to ShowWindow?
Member 14594285 19-Sep-22 6:13am    
in CDlgMy:

BOOL CDlgFormati::OnInitDialog()
{
CDialog::OnInitDialog();
FillList();
return TRUE;
}
in FillList there is ShowWindow(SW_HIDE);
Richard MacCutchan 19-Sep-22 6:31am    
Please use the Improve question link above, and add complete details in your question.
Member 14594285 19-Sep-22 8:20am    
done
Richard MacCutchan 19-Sep-22 8:56am    
It is unlikely that the system will let you hide the dialog in the OnInitDialog method. Once that method returns the dialog is displayed and the focus set on the first control in the tab order. This also begs the real question: what is the purpose of a dialog that you immediately want to hide?

That is what CloseWindow is supposed to do, as stated in CloseWindow function (winuser.h) - Win32 apps | Microsoft Docs[^]. You need to use DestroyWindow function (winuser.h) - Win32 apps | Microsoft Docs[^] to remove it completely.
 
Share this answer
 
Comments
CPallini 16-Sep-22 6:49am    
5.
Richard MacCutchan 16-Sep-22 6:56am    
Thanks.
You can hide the calling dialog in VB I do it like so;

me.hide

(name of dialog).showdialog

me.show
 
Share this answer
 
Comments
Richard MacCutchan 16-Sep-22 6:56am    
Except that C++/MFC are not part of .NET
Michael_Davies 16-Sep-22 7:05am    
Do they have a hide/show methods for dialog?
Richard MacCutchan 16-Sep-22 7:20am    
There is the ShowWindow method which offers that feature, but Dialogs are not really supposed to be used in that way.
Michael_Davies 16-Sep-22 7:22am    
Check this out; https://topic.alibabacloud.com/a/several-methods-of-mfc-hide-main-window-running_8_8_10256747.html
Richard MacCutchan 16-Sep-22 7:30am    
As I said, this is not the way you should use dialogs.

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