Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Closing All Open Dialogs

0 views
Skip to first unread message

SaranG(Saravanan)

unread,
Jul 22, 2008, 7:10:46 AM7/22/08
to sarav...@mothercode.com, maniv...@mothercode.com
Hi all,
I am developing Dialog based application.This application
contains so many no. of dialogs. So i need to close all open dialogs
when i click the button in one dialog like named "Close All". I tried
with OnCancel and OnOK both this will close only one dialog of which i
called from. So any one can help me.

Thanks in advance,
SaranG.


werner m...

unread,
Jul 22, 2008, 8:35:00 AM7/22/08
to
"SaranG(Saravanan)" wrote:

Hi SaranG,
nomally I use for multiple dialoges the classes CPropertySheet /
CPropertyPage. I don't know if you do so. But I will explain you the way to
close the pages on the following sample.

CPropertySheet = parent
|
+-> CPropertyPage -> CPropertySheet = parent
| : |
+-> CPropertyPage .. +-> CPropertyPage ..
| : | :
+-> CPropertyPage .. +-> CPropertyPage ..
| : | :

/*==================================================
OnOK ( CPropertyPage )
==================================================*/
void CppXXXX::OnOK()
{
CPropertyPage::OnOK();
// On button OK send a close message to the parent
// ( CPropertySheet ) and let him close the childs
CWnd* pParentWnd = GetParent();
pParentWnd->SendMessage( WM_CLOSE, 0, (LPARAM)0 );
}

/*==================================================
OnOK ( CPropertySheet )
==================================================*/
void CpshXXXX::OnClose()
{
WORD i;
if( pDaten->m_pPropPages[i]->m_hWnd != NULL )
{ // send a close message to the child ( CPropertyPage )
for( i = 0; i < 3; i++ )
{ CWnd* pChildWnd = FromHandle( pDaten->m_pPropPages[i]->m_hWnd );
pChildWnd->SendMessage( WM_CLOSE, 0, (LPARAM)0 ); }
}
CPropertySheet::OnClose();
}

Continue this way until all your dialogues are closed. Also implement the
close for the cancel button.

Maybe it will help you.
Regards
werner m...

werner m...

unread,
Jul 22, 2008, 9:14:00 AM7/22/08
to
"SaranG(Saravanan)" wrote:

Sorry, in my previously sent reply was something missing !

/*===================================================
OnClose ( CPropertySheet )
=====================================================*/


void CpshXXXX::OnClose()
{
WORD i;

if( strcmp(m_pClassParent->m_lpszClassName, "CppXXXXUeR" ) == 0 )
{ // CPropertyPage parent
CppXXXXUeR* pDaten = (CppXXXXUeR*) m_pParent;


if( pDaten->m_pPropPages[i]->m_hWnd != NULL )
{ // send a close message to the child ( CPropertyPage )
for( i = 0; i < 3; i++ )
{ CWnd* pChildWnd = FromHandle( pDaten->m_pPropPages[i]->m_hWnd );
pChildWnd->SendMessage( WM_CLOSE, 0, (LPARAM)0 ); }
}
}

else
{ if( strcmp(m_pClassParent->m_lpszClassName, "CppXXXXStR" ) == 0 )
{ // Another CPropertyPage parent
CppXXXXStR* pDaten = (CppXXXXStR*) m_pParent;


for( i = 0; i < 3; i++ )

{ if( pDaten->m_pPropPages[i] != NULL )
{ if( pDaten->m_pPropPages[i]->m_hWnd != NULL )


{ // send a close message to the child ( CPropertyPage )

CWnd* pChildWnd = FromHandle(
pDaten->m_pPropPages[i]->m_hWnd );
pChildWnd->SendMessage( WM_CLOSE, 0, (LPARAM)0 ); }
}
}
}
}
CPropertySheet::OnClose();
}

Regards
werner m...

Tom Serface

unread,
Jul 22, 2008, 10:11:02 AM7/22/08
to
Aside from keeping track of open dialogs on your own and just sending
WM_CLOSE message to each (using PostMessage) you could use something like:

http://msdn.microsoft.com/en-us/library/ms633494(VS.85).aspx

To call a function for all open windows and just send the message to the
dialog types (or whatever types you want to close).

Tom

"SaranG(Saravanan)" <infos...@gmail.com> wrote in message
news:340ee8dd-73fe-4a2c...@25g2000hsx.googlegroups.com...

Joseph M. Newcomer

unread,
Jul 22, 2008, 10:32:06 AM7/22/08
to
Are they modal or modeless?

For modal it is trivial. You click the "Close All" button on the most recent modal dialog
and then you explicitly call EndDialog with a code that is not expected (e.g., IDABORT),
and the caller interprets that to be a request to close itself with the same code, etc.

For modeless, I tend to do something like SendMessageToDescendants from the mainframe with
a user-defined message such as UWM_CLOSE_ALL_DIALOGS and every modeless dialog that
receives it closes itself.
joe

On Tue, 22 Jul 2008 04:10:46 -0700 (PDT), "SaranG(Saravanan)" <infos...@gmail.com>
wrote:

Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

SaranG(Saravanan)

unread,
Jul 23, 2008, 3:32:21 AM7/23/08
to
On Jul 22, 7:32 am, Joseph M. Newcomer <newco...@flounder.com> wrote:
> Are they modal or modeless?
>
> For modal it is trivial. You click the "Close All" button on the most recent modal dialog
> and then you explicitly call EndDialog with a code that is not expected (e.g., IDABORT),
> and the caller interprets that to be a request to close itself with the same code, etc.
>
> For modeless, I tend to do something like SendMessageToDescendants from the mainframe with
> a user-defined message such as UWM_CLOSE_ALL_DIALOGS and every modeless dialog that
> receives it closes itself.
> joe
>
> On Tue, 22 Jul 2008 04:10:46 -0700 (PDT), "SaranG(Saravanan)" <infosar...@gmail.com>

> wrote:
>
> >Hi all,
> > I am developing Dialog based application.This application
> >contains so many no. of dialogs. So i need to close all open dialogs
> >when i click the button in one dialog like named "Close All". I tried
> >with OnCancel and OnOK both this will close only one dialog of which i
> >called from. So any one can help me.
>
> >Thanks in advance,
> >SaranG.
>
> Joseph M. Newcomer [MVP]
> email: newco...@flounder.com

Hi,
Thanks for all who enlighten me up. And i made that closing of
all open dialog with some flag variables usage.
And tried with the WM_CLOSE message.
Once again,
Thanks
SaranG.

0 new messages