CDialog::DoModal() Behaviour 
Author Message
 CDialog::DoModal() Behaviour

I have a listbox in a CDialog derived class that contains a large amount
of data.

I would like to open the dialog
as a modal dialog, but initialize all the elements of the listbox
before the WM_INITDIALOG message.
(i.e. I don't want to keep reinitializing the list box every time I do a
DoModal)

Sajeev

CMyClass::OnButtonClick()
{
  // I want the list box to be in heap memory rather than the stack
where DoModal will place it.
  m_MyDialogWithListbox.DoModal();

Quote:
}



Sun, 02 Jun 2002 03:00:00 GMT  
 CDialog::DoModal() Behaviour
Maybe I misunderstand... But why cant you create the modal dialog as a
member, then initializing it in the constructor.

// in CMyClass header
 CSomeDialog m_MyDialogWithListbox:

// in CMyClass constructor
CMyClass ::CMyClass ()
 :m_DlgSetup()                        // call the contructor
{

Quote:
}

// In CSomeDialog constructor
CSomeDialog::CSomeDialog()
:CDialog()
{
    // Initialize()

Quote:
}

Leave you OnButtonClick as it is...

/ Rob


Quote:
> I have a listbox in a CDialog derived class that contains a large amount
> of data.

> I would like to open the dialog
> as a modal dialog, but initialize all the elements of the listbox
> before the WM_INITDIALOG message.
> (i.e. I don't want to keep reinitializing the list box every time I do a
> DoModal)

> Sajeev

> CMyClass::OnButtonClick()
> {
>   // I want the list box to be in heap memory rather than the stack
> where DoModal will place it.
>   m_MyDialogWithListbox.DoModal();
> }



Sun, 02 Jun 2002 03:00:00 GMT  
 CDialog::DoModal() Behaviour
Hi !

Quote:

> ...
> I have a listbox in a CDialog derived class that contains a large amount
> of data.

> I would like to open the dialog
> as a modal dialog, but initialize all the elements of the listbox
> before the WM_INITDIALOG message.
> (i.e. I don't want to keep reinitializing the list box every time I do a
> DoModal)
> ...

        No way. The actual Windows dialog object doesn't yet exist until you
call DoModal(). And it doesn't exist any more (already destroyed) after
DoModal() returns. It means that you can't preserve list box items
between DoModal() calls because the list box is created anew (together
with the dialog window) every time you call DoModal(). WM_INITDIALOG is
a place to initialize these items.

Best regards,
Andrey.



Sun, 02 Jun 2002 03:00:00 GMT  
 CDialog::DoModal() Behaviour
Thanks Andrey,

I realized this, but I was thinking something like a Modeless Dialog
Create() to initialize the listbox and then display this Dialog as a
Modal dialog.

I tried using CDialog::Create() which will create the dialog hWnd object
and all controls and then call a function to perform a Modal Loop using
CDialog::RunModalLoop() but that did not seem to work. If anyone knows
how to use the RunModalLoop could you send a simple example of how to
use it properly.

Sajeev



Sun, 02 Jun 2002 03:00:00 GMT  
 CDialog::DoModal() Behaviour
I would use Create as mentioned.

There are ways to emulate the DoModal and have been covered elsewhere. I
recall the technique is to disable the parent window.

- Tim


Quote:
> Thanks Andrey,

> I realized this, but I was thinking something like a Modeless Dialog
> Create() to initialize the listbox and then display this Dialog as a
> Modal dialog.

> I tried using CDialog::Create() which will create the dialog hWnd object
> and all controls and then call a function to perform a Modal Loop using
> CDialog::RunModalLoop() but that did not seem to work. If anyone knows
> how to use the RunModalLoop could you send a simple example of how to
> use it properly.

> Sajeev



Mon, 03 Jun 2002 03:00:00 GMT  
 CDialog::DoModal() Behaviour
OK, here's a trick. Create a modeless dialog. When you want to do the
equivalent of "DoModal", make it visible, and disable its parent. When
you "close" it, just enable the parent and hide the dialog. Note that
you still have to inidialize it in OnInitDialog. You don't need to
fiddle around with RunModalLoop or anything else; playing at that
level is seriously hazardous as you must deeply understand MFC to make
sure that what you are doing is sane.
                                joe

On Wed, 15 Dec 1999 10:55:37 -0800, Sajeev Madusuthanan

Quote:

>Thanks Andrey,

>I realized this, but I was thinking something like a Modeless Dialog
>Create() to initialize the listbox and then display this Dialog as a
>Modal dialog.

>I tried using CDialog::Create() which will create the dialog hWnd object
>and all controls and then call a function to perform a Modal Loop using
>CDialog::RunModalLoop() but that did not seem to work. If anyone knows
>how to use the RunModalLoop could you send a simple example of how to
>use it properly.

>Sajeev

Joseph M. Newcomer [MVP]

Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm
Author of "Win32 Programming" (with Brent Rector, Addison-Wesley, 1997)
Author of "Developing Windows NT Device Drivers" (with Ed Dekker, AWL, 1999)


Mon, 03 Jun 2002 03:00:00 GMT  
 CDialog::DoModal() Behaviour
Hi !

        I would suggest you take a look at CDialog::DoModal() method source
code in MFC sources. Essentially DoModal() is just a pair of Create()
and RunModalLoop() calls. Probably you just have to take into account a
number of additional details (see DoModal() source) and it will start
working.

Quote:

> Thanks Andrey,

> I realized this, but I was thinking something like a Modeless Dialog
> Create() to initialize the listbox and then display this Dialog as a
> Modal dialog.

> I tried using CDialog::Create() which will create the dialog hWnd object
> and all controls and then call a function to perform a Modal Loop using
> CDialog::RunModalLoop() but that did not seem to work. If anyone knows
> how to use the RunModalLoop could you send a simple example of how to
> use it properly.

> Sajeev



Mon, 03 Jun 2002 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. CDialog::DoModal(), CDialog::EndDialog() Design Flaw

2. Q: How to move a CDialog before calling DoModal()

3. Q: CDialog::DoModal () fails

4. CDialog::DoModal

5. Using DoModal from CDialog when called from a DLL

6. CDialog.DoModal problem

7. Help. CDialog::DoModal Fail in _beginthreadex

8. Invalid Page Fault from CDialog.DoModal()

9. Calling CDialog::DoModal crashes

10. CDialog::DoModal()

11. CDialog::DoModal() keyboard messages?????

12. HELP! CDialog/DoModal problems in regular DLL

 

 
Powered by phpBB® Forum Software