CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jun 2001
    Posts
    126

    Modelless Dialog trouble

    I am trying to create and use some modelless dialogs in my dialog based project. I can't seem to get it to work although I am following MSDN exactly (as far as I know). This is what I am doing to try to get a modelless dialog to appear:

    CTestDlg testdlg;
    testdlg.Create(IDD_TESTDLG, NULL);
    testdlg.ShowWindow(SW_SHOW);

    But it doesnt show up. It looks as if it pops up and immediately closes before I can really see it.
    Please help.



  2. #2
    Join Date
    Jun 2000
    Posts
    184

    Re: Modelless Dialog trouble

    you must use a pointer

    CTestDlg *testdlg;

    testdlg=new(CTestDlg);
    testdlg->Create(IDD_TESTDLG, NULL);
    testdlg->ShowWindow(SW_SHOW);



    because when you exit from the function that call Create() and ShowWindow() the object testdlg is destroied.
    If you don't want use a pointer you must declare CTestDlg testdlg; as public variable


  3. #3
    Join Date
    Nov 2000
    Location
    Colorado Springs,USA
    Posts
    491

    Re: Modelless Dialog trouble

    hi,
    u cannot create Dialog like that. U should be use pointer.

    CTestDlg *testdlg; //put it into class

    {
    testdlg=new CTestDlg;
    testdlg->Create(IDD_TESTDLG, NULL);
    testdlg->ShowWindow(SW_SHOW);
    }

    Regards,
    soundar




  4. #4
    Join Date
    Jun 2001
    Posts
    126

    Re: Modelless Dialog trouble

    Ahha. That makes sense. I should have known. Thanks alot.


  5. #5
    Join Date
    Jun 2001
    Posts
    126

    Re: Modelless Dialog trouble

    Thank you. That was very helpful.


  6. #6
    Join Date
    Aug 2001
    Posts
    19

    Re: Modelless Dialog trouble

    Hi;

    There's nothing wrong with doing that, but *I think* you'll have a memory leak since you are using the 'new' command. It probably won't cause any major problems, but, nonetheless. You should probably declare a variable m_MyModlessDlg as part of the calling class, that way you can properly destroy the Modeless Dialog.

    Scott.

  7. #7
    Join Date
    Jun 2001
    Posts
    126

    Re: Modelless Dialog trouble

    Now that you mention it, you are probably right about the memory leak thing. I will go about it your way. Thanks for the help. I appreciate it.


  8. #8
    Join Date
    Aug 2001
    Location
    Minnesota, USA
    Posts
    801

    Re: Modelless Dialog trouble

    Or (and some disagree), you could override OnNcDestroy() and call:


    delete this;




    Just a thought so the dialog will manage it's own deletion.

    Chris


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured