Archive for the ‘WTL’ Category

how to create a modeless (non-modal) dialog in WTL (ATL , C++)

May 25, 2009

modeless dialog:
thanks to http://www.sowbug.org/mt/2004/01/modeless-dialogs.html#more

1) in MainDlg.h , a class global for the dialog (otherwise it will be created and destroyed in
the same subroutine and throw an exception)
CBigFocusDlg dlgBigFocus;

2) Create the modeless dialog in response to a button click in the main dialog

// **************************************
LRESULT CMainDlg::OnBnClickedShow_Big_Focus_Dlg(WORD /*wNotifyCode*/, WORD

/*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
// if it already exists, then bring it to top and return
if ( dlgBigFocus ) {
::BringWindowToTop(dlgBigFocus.m_hWnd);
return 0;
}

// MODELESS DIALOG
// http://www.sowbug.org/mt/2004/01/modeless-dialogs.html#more

dlgBigFocus.Create(NULL );
dlgBigFocus.CenterWindow(this->m_hWnd);
dlgBigFocus.ShowWindow(SW_SHOWNORMAL);

return 0;
}

// ******************************************************************************
// how to close the dialog:

LRESULT CBigFocusDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
// center the dialog on the screen
CenterWindow();

return TRUE;
}

LRESULT CBigFocusDlg::OnCloseCmd(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
this->DestroyWindow();
return 0;
}

// **************************************
LRESULT CBigFocusDlg::OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
this->DestroyWindow();
return 0;
}

Advertisements