Another Simple Way to Convert Modeless Dialogs to Modal

–>

This is another simple way of converting a modeless dialog into a modal dialog.

While overriding the dialog’s Create() call, get the pointer to the main frame window and disable it using EnableWindow() call.

BOOL CModelessDlg::Create( UINT nID, CWnd* pParentWnd )
{
	

// TODO: Add your specialized code here and/or call the base class

	pParentWnd->EnableWindow(FALSE);

//You can get pParentWnd by calling

	AfxGetMainWnd() also.
	

return

 CDialog::Create(nID, pParentWnd);
}


Before destroying by “DestroyWindow()”, call EnableWindow() to set it as TRUE.

void

 CModelessDlg::OnOK()
{
	

// TODO: Add extra validation here

	...........
	..........
	.........

	AfxGetMainWnd()->EnableWindow();
	DestroyWindow();
}

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read