Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. MFC GUI

MFC GUI

Scheduled Pinned Locked Moved C / C++ / MFC
c++performancehelptutorial
9 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bhanu_8509
    wrote on last edited by
    #1

    Dear All, I want to create GUI in MFC like the one we see in Apple iTunes or in a Sony ericsson PC suite. In the mentioned GUI's the dialog is loaded when the user clicks on a button at the right panel. When I develop an application like this, my program throw assertion error due to loading and unloading dialogs. This is due to the memory while calling DoModal() recursively while clicking the buttons. Please guide me to develop an application where we can load 'n' number of dialogs at 'n' number of times. Many thanks in advance.

    N M 2 Replies Last reply
    0
    • B bhanu_8509

      Dear All, I want to create GUI in MFC like the one we see in Apple iTunes or in a Sony ericsson PC suite. In the mentioned GUI's the dialog is loaded when the user clicks on a button at the right panel. When I develop an application like this, my program throw assertion error due to loading and unloading dialogs. This is due to the memory while calling DoModal() recursively while clicking the buttons. Please guide me to develop an application where we can load 'n' number of dialogs at 'n' number of times. Many thanks in advance.

      N Offline
      N Offline
      Nishad S
      wrote on last edited by
      #2

      It is strange that a dialog uses this much memory... :( What operation is done to use this much memory? Are you freeing them proper?

      - ns ami -

      B 1 Reply Last reply
      0
      • N Nishad S

        It is strange that a dialog uses this much memory... :( What operation is done to use this much memory? Are you freeing them proper?

        - ns ami -

        B Offline
        B Offline
        bhanu_8509
        wrote on last edited by
        #3

        I have four buttons in my dialog, totally four dialogs for four buttons, when I click a button1 it will load the appropriate dialog1 (dlg1->DoModal()). If I click button2 then it will load the dialog2 (dlg2->Modal). Code snippet is : //in button1 Dialog1 dlg1 = new Dialog1(); OnCancel();//to close the current dialog dlg1->DoModal(); //in button2 Dialog2 dlg2 = new Dialog2(); OnCancel();//to close the current dialog dlg2->DoModal(); //in button3 Dialog3 dlg3 = new Dialog3(); OnCancel();//to close the current dialog dlg3->DoModal(); //in button4 Dialog4 dlg4 = new Dialog4(); OnCancel();//to close the current dialog dlg4->DoModal();

        N I 2 Replies Last reply
        0
        • B bhanu_8509

          I have four buttons in my dialog, totally four dialogs for four buttons, when I click a button1 it will load the appropriate dialog1 (dlg1->DoModal()). If I click button2 then it will load the dialog2 (dlg2->Modal). Code snippet is : //in button1 Dialog1 dlg1 = new Dialog1(); OnCancel();//to close the current dialog dlg1->DoModal(); //in button2 Dialog2 dlg2 = new Dialog2(); OnCancel();//to close the current dialog dlg2->DoModal(); //in button3 Dialog3 dlg3 = new Dialog3(); OnCancel();//to close the current dialog dlg3->DoModal(); //in button4 Dialog4 dlg4 = new Dialog4(); OnCancel();//to close the current dialog dlg4->DoModal();

          N Offline
          N Offline
          Nishad S
          wrote on last edited by
          #4

          bhanu_8509 wrote:

          new Dialog1();

          If you are creating dialog using new, then in each button click, a new instance of dialog will be created. It might be the reason of memory leak. I think you need to create them once, and reuse it again and again.

          - ns ami -

          B 1 Reply Last reply
          0
          • N Nishad S

            bhanu_8509 wrote:

            new Dialog1();

            If you are creating dialog using new, then in each button click, a new instance of dialog will be created. It might be the reason of memory leak. I think you need to create them once, and reuse it again and again.

            - ns ami -

            B Offline
            B Offline
            bhanu_8509
            wrote on last edited by
            #5

            please tell me how to do this. i cannot create a global object to each and every dialog. frankly I dont know how to create global objects which can be accessed in other dialogs. thanks.

            N 1 Reply Last reply
            0
            • B bhanu_8509

              Dear All, I want to create GUI in MFC like the one we see in Apple iTunes or in a Sony ericsson PC suite. In the mentioned GUI's the dialog is loaded when the user clicks on a button at the right panel. When I develop an application like this, my program throw assertion error due to loading and unloading dialogs. This is due to the memory while calling DoModal() recursively while clicking the buttons. Please guide me to develop an application where we can load 'n' number of dialogs at 'n' number of times. Many thanks in advance.

              M Offline
              M Offline
              Maximilien
              wrote on last edited by
              #6

              I'm not certain I understand correctly what you want to achieve. I don't have iTunes in front of me; and I don't see what you mean by "clicks on a button at the right panel". Me think it's quite moronic to call DoModal() recursively. If you want to create and display N dialogs M number of times, you'd better use modeless dialogs and be conscious about managing the memory (when you create and destroy the dialogs).

              B 1 Reply Last reply
              0
              • B bhanu_8509

                I have four buttons in my dialog, totally four dialogs for four buttons, when I click a button1 it will load the appropriate dialog1 (dlg1->DoModal()). If I click button2 then it will load the dialog2 (dlg2->Modal). Code snippet is : //in button1 Dialog1 dlg1 = new Dialog1(); OnCancel();//to close the current dialog dlg1->DoModal(); //in button2 Dialog2 dlg2 = new Dialog2(); OnCancel();//to close the current dialog dlg2->DoModal(); //in button3 Dialog3 dlg3 = new Dialog3(); OnCancel();//to close the current dialog dlg3->DoModal(); //in button4 Dialog4 dlg4 = new Dialog4(); OnCancel();//to close the current dialog dlg4->DoModal();

                I Offline
                I Offline
                Iain Clarke Warrior Programmer
                wrote on last edited by
                #7

                Why not...

                void CMyFirstDialog::OnButtonOne ()
                {
                EndDialog (ID_BUTTON1); // CMyFirstDialog::DoModal () now returns ID_BUTTON1.
                }

                ....

                ...
                CDialog *pDlg = new CMyFirstDialog ();
                int nReturn = 0;
                while (pDlg)
                {
                nReturn = pDlg->DoModal ();

                  delete pDlg; // tidy up
                  pDlg = NULL;
                
                  switch (nReturn)
                  {
                  case ID\_BUTTON1:
                     pDlg = new CFirstDlg;
                     break;
                 
                  case ID\_BUTTON2:
                     pDlg = new CSecondDlg;
                     break;
                

                ....
                }
                }
                ASSERT(!pDlg);

                OK, that was very quick and hacky - with no real error checking, but I hope it gives you an idea. The main difference is you wait till one dialog is finished and tidied up, *then* move on to the next one. Other wise, they just stack one on top of the other... Iain. switch (

                Codeproject MVP for C++, I can't believe it's for my lounge posts...

                modified on Tuesday, January 27, 2009 9:54 AM

                1 Reply Last reply
                0
                • M Maximilien

                  I'm not certain I understand correctly what you want to achieve. I don't have iTunes in front of me; and I don't see what you mean by "clicks on a button at the right panel". Me think it's quite moronic to call DoModal() recursively. If you want to create and display N dialogs M number of times, you'd better use modeless dialogs and be conscious about managing the memory (when you create and destroy the dialogs).

                  B Offline
                  B Offline
                  bhanu_8509
                  wrote on last edited by
                  #8

                  No I dont want to use modeless dialogs. I will try with Ian suggestion and get back to you all. Thanks.

                  1 Reply Last reply
                  0
                  • B bhanu_8509

                    please tell me how to do this. i cannot create a global object to each and every dialog. frankly I dont know how to create global objects which can be accessed in other dialogs. thanks.

                    N Offline
                    N Offline
                    Nishad S
                    wrote on last edited by
                    #9

                    For such an application a main dialog/window should be there to track these button selections... So that these kind of recursive DoModal can be avoided. A sample... not perfect but only to get the idea.

                    void CMainDlg::ShowDlgs() // my own function
                    {
                    for( ;; )
                    {
                    int nNextDlg = 1;
                    switch( nNextDlg )
                    {
                    case 1:
                    {
                    Dialog1 dlg;
                    nNextDlg = dlg.DoModal();
                    }
                    case 2:
                    {
                    Dialog2 dlg;
                    nNextDlg = dlg.DoModal();
                    }
                    // and so on...
                    // ...
                    case ID_EXIT: // = 100 or something else... (ID for exit the application/loop)
                    return;
                    }
                    }
                    }

                    Better is to make the use of user/registered message communication between parent (main dialog/window) and child dialogs (Dialog1, Dialog2, etc.), but I don't know exactly what you are trying to do.

                    - ns ami -

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups