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();
}



Comments

  • Pointer to Parent Window

    Posted by Legacy on 11/23/2001 12:00am

    Originally posted by: Pata

    I have a dialog in an own thread ( modeless ) that was floating around like hell until I passed a pointer to the main window in the constructor of the dialog.

    CSMSMyThread::CSMSMyThread(CWnd* pParent /*=NULL*/)
    : CDialog(CSMSMyThread::IDD, AfxGetApp()->GetMainWnd())
    {
    //{{AFX_DATA_INIT(CSMSMyThread)
    //}}AFX_DATA_INIT
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

    }

    Now it's acting like a modal dialog.

    /Pata

    Reply
  • solution for tab controls and the like

    Posted by Legacy on 02/25/2000 12:00am

    Originally posted by: Rick Kissh

    I was having trouble getting everything inside the parent frame to ignore events when it was a tab control that was the parent of the modal dialog. The following was my solution:

    // DISABLING
    // add this to your dialog constructor where pParent is the
    // parent CWnd
    GetSafeOwner( pParent, NULL )->EnableWindow( FALSE );


    // REENABLING
    // override DestroyWindow
    BOOL CCategoriesDlg::DestroyWindow()
    {
    GetSafeOwner( GetParent(), NULL )->EnableWindow( TRUE );
    return CDialog::DestroyWindow();
    }


    Reply
  • Do it with CPropertysheet

    Posted by Legacy on 12/08/1999 12:00am

    Originally posted by: Johannes Stromberg

    How do I do the same thing with CPropertySheet?

    /Johannes

    Reply
  • Didn't quite work on NT 4.0

    Posted by Legacy on 11/11/1998 12:00am

    Originally posted by: Darryl Adams

    I tried this on NT 4.0, Visual C++ 6.0, during a command message handler, and it did not quite work. I guess disabling the parent disabled the child as well. However, calling:

    GetParent()->EnableWindow(false);
    EnableWindow(true);

    This did work, and allowed me to toggle modal/modeless at the press of a button. Switching back to modeless was done with:

    GetParent()->EnableWindow(true);

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: May 6, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT While you likely have very good reasons for remaining on WinXP after end of support -- an estimated 20-30% of worldwide devices still are -- the bottom line is your security risk is now significant. In the absence of security patches, attackers will certainly turn their attention to this new opportunity. Join Lumension Vice President Paul Zimski in this one-hour webcast to discuss risk and, more importantly, 5 pragmatic risk mitigation techniques …

  • When it comes to desktops – physical or virtual – it's all about the applications. Cloud-hosted virtual desktops are growing fast because you get local data center-class security and 24x7 access with the complete personalization and flexibility of your own desktop. Organizations make five common mistakes when it comes to planning and implementing their application management strategy. This eBook tells you what they are and how to avoid them, and offers real-life case studies on customers who didn't let …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds