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. hi all [modified]

hi all [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
help
14 Posts 5 Posters 2 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.
  • A ashish dogra

    plz tell me dlg.Create(IDD_DIALOG1); dlg.ShowWindow(1); when i rty this to create modeless dialog box after one try it will create error as assertion failureplz Ashish Dogra MCA Noida -- modified at 1:33 Thursday 29th June, 2006

    H Offline
    H Offline
    Hamid Taebi
    wrote on last edited by
    #2

    yes because you create your dialog and you dont need to create again_**


    **_

    whitesky


    A 1 Reply Last reply
    0
    • H Hamid Taebi

      yes because you create your dialog and you dont need to create again_**


      **_

      whitesky


      A Offline
      A Offline
      ashish dogra
      wrote on last edited by
      #3

      sir i will try to create it again after cancelling it but sir as with domaodal() we can try again after cancelling it it will not give any error Ashish Dogra MCA Noida

      1 Reply Last reply
      0
      • A ashish dogra

        plz tell me dlg.Create(IDD_DIALOG1); dlg.ShowWindow(1); when i rty this to create modeless dialog box after one try it will create error as assertion failureplz Ashish Dogra MCA Noida -- modified at 1:33 Thursday 29th June, 2006

        S Offline
        S Offline
        Sarath C
        wrote on last edited by
        #4

        For a modeless dailog, you should define your own constructore, never let the default constructor to call the base class with template ID. Here is an article from MSDN[^] SaRath.
        "It is your attitude, not your aptitude, that determines your altitude - Zig Ziglar." My Blog | Understanding State Pattern in C++

        A 1 Reply Last reply
        0
        • S Sarath C

          For a modeless dailog, you should define your own constructore, never let the default constructor to call the base class with template ID. Here is an article from MSDN[^] SaRath.
          "It is your attitude, not your aptitude, that determines your altitude - Zig Ziglar." My Blog | Understanding State Pattern in C++

          A Offline
          A Offline
          ashish dogra
          wrote on last edited by
          #5

          even i use this i will still not solve the problem CMy dlg; dlg.Create(IDD_DIALOG1); dlg.ShowWindow(1); please tell me some example Ashish Dogra MCA Noida

          H 1 Reply Last reply
          0
          • A ashish dogra

            even i use this i will still not solve the problem CMy dlg; dlg.Create(IDD_DIALOG1); dlg.ShowWindow(1); please tell me some example Ashish Dogra MCA Noida

            H Offline
            H Offline
            Hamid Taebi
            wrote on last edited by
            #6

            ashish dogra wrote:

            CMy dlg; dlg.Create(IDD_DIALOG1); dlg.ShowWindow(1);

            Whats problem with this code_**


            **_

            whitesky


            A 1 Reply Last reply
            0
            • A ashish dogra

              plz tell me dlg.Create(IDD_DIALOG1); dlg.ShowWindow(1); when i rty this to create modeless dialog box after one try it will create error as assertion failureplz Ashish Dogra MCA Noida -- modified at 1:33 Thursday 29th June, 2006

              O Offline
              O Offline
              ovidiucucu
              wrote on last edited by
              #7

              After exiting DoModal, the attached window of CDialog object is destroyed and detached, so there is no problem to call DoModal again. For a modeless dialog (made with CDialog::Create), unless the CDialog object goes out-of scope or DestroyWindow was called, the window is not destroyed, not even the user pushes OK/Cancel/close button. So you have to test if the dialog was created before call CDialog::Create. If yes, then simply show it:

              void CFoo::ShowModelessDialog(CDialog& dlg, UINT nResID)
              {
                 if(!::IsWindow(dlg.m_hWnd)) // thest attached window handle
                 {
                     // create only if not yet created
                    dlg.Create(nResID, this);
                 }
                 dlg.ShowWindow(SW_SHOW);
              }
              // ...
              // ... somewhere ...
                 ShowDialog(m_dlg, IDD_DIALOG1);
              // ... and no problem to show again
                 ShowDialog(m_dlg, IDD_DIALOG1);
              

              NOTE: You can test m_hWnd against NULL instead of calling ::IsWindow, as well. Ovidiu Cucu Microsoft MVP - Visual C++

              N 1 Reply Last reply
              0
              • H Hamid Taebi

                ashish dogra wrote:

                CMy dlg; dlg.Create(IDD_DIALOG1); dlg.ShowWindow(1);

                Whats problem with this code_**


                **_

                whitesky


                A Offline
                A Offline
                ashish dogra
                wrote on last edited by
                #8

                sir the problem is that when i run application the modeless dialog box open a screen after clicking on ok button of fiest dialog box but when i cancel the modeless dialog and again click on ok button of first dialog box then it will give an assertion error and does not create modeless dialog box again plz sovle this one Ashish Dogra MCA Noida

                H 1 Reply Last reply
                0
                • A ashish dogra

                  sir the problem is that when i run application the modeless dialog box open a screen after clicking on ok button of fiest dialog box but when i cancel the modeless dialog and again click on ok button of first dialog box then it will give an assertion error and does not create modeless dialog box again plz sovle this one Ashish Dogra MCA Noida

                  H Offline
                  H Offline
                  Hamid Taebi
                  wrote on last edited by
                  #9

                  Can you show how to use and you show your code that has error_**


                  **_

                  whitesky


                  A 1 Reply Last reply
                  0
                  • O ovidiucucu

                    After exiting DoModal, the attached window of CDialog object is destroyed and detached, so there is no problem to call DoModal again. For a modeless dialog (made with CDialog::Create), unless the CDialog object goes out-of scope or DestroyWindow was called, the window is not destroyed, not even the user pushes OK/Cancel/close button. So you have to test if the dialog was created before call CDialog::Create. If yes, then simply show it:

                    void CFoo::ShowModelessDialog(CDialog& dlg, UINT nResID)
                    {
                       if(!::IsWindow(dlg.m_hWnd)) // thest attached window handle
                       {
                           // create only if not yet created
                          dlg.Create(nResID, this);
                       }
                       dlg.ShowWindow(SW_SHOW);
                    }
                    // ...
                    // ... somewhere ...
                       ShowDialog(m_dlg, IDD_DIALOG1);
                    // ... and no problem to show again
                       ShowDialog(m_dlg, IDD_DIALOG1);
                    

                    NOTE: You can test m_hWnd against NULL instead of calling ::IsWindow, as well. Ovidiu Cucu Microsoft MVP - Visual C++

                    N Offline
                    N Offline
                    Nawal K Gupta
                    wrote on last edited by
                    #10

                    In you use this code void OnSomeFunction() { CMy dlg; dlg.Create(IDD_DIALOG1); dlg.ShowWindow(1); } this is not safe, because the dlg object is created in Stack and it will get destroyed as soon as the function is out of scope. Create ModeLess Dialogs in Heap or Make Sure that the Object is not out of scope by making is static or Global/Top Clsss Variale Like. One Way of Doing It is: void OnSomeFunction() { static CMy * Dlg =NULL; if (!m_Dlg) { Dlg= new CMy(); Dlg->Create(IDD_DIALOG1); } dlg.ShowWindow(1); }

                    O 1 Reply Last reply
                    0
                    • H Hamid Taebi

                      Can you show how to use and you show your code that has error_**


                      **_

                      whitesky


                      A Offline
                      A Offline
                      ashish dogra
                      wrote on last edited by
                      #11

                      void CGd1Dlg::OnOK() { CMy dlg; dlg.Create(IDD_DIALOG1); dlg.ShowWindow(1); } Ashish Dogra MCA Noida

                      H 1 Reply Last reply
                      0
                      • A ashish dogra

                        void CGd1Dlg::OnOK() { CMy dlg; dlg.Create(IDD_DIALOG1); dlg.ShowWindow(1); } Ashish Dogra MCA Noida

                        H Offline
                        H Offline
                        Hamid Taebi
                        wrote on last edited by
                        #12

                        can you show in CMy::CtetDlg(CWnd* pParent /*=NULL*/) : CDialog(CtetDlg::IDD, pParent) and one suggestion use this function instead your functions and answer to me it work or doesnt work CMy::CtetDlg(CWnd* pParent /*=NULL*/) : CDialog(CtetDlg::IDD, pParent) BOOL o= Create(IDD,pParent); ----------- void CGd1Dlg::OnOK() { CMy *dlg; dlg=new CMy(this); /*use from breakpoint and debug for see error if you get a error*/ dlg->ShowWindow(1); }_**


                        **_

                        whitesky


                        A 1 Reply Last reply
                        0
                        • H Hamid Taebi

                          can you show in CMy::CtetDlg(CWnd* pParent /*=NULL*/) : CDialog(CtetDlg::IDD, pParent) and one suggestion use this function instead your functions and answer to me it work or doesnt work CMy::CtetDlg(CWnd* pParent /*=NULL*/) : CDialog(CtetDlg::IDD, pParent) BOOL o= Create(IDD,pParent); ----------- void CGd1Dlg::OnOK() { CMy *dlg; dlg=new CMy(this); /*use from breakpoint and debug for see error if you get a error*/ dlg->ShowWindow(1); }_**


                          **_

                          whitesky


                          A Offline
                          A Offline
                          ashish dogra
                          wrote on last edited by
                          #13

                          thanks sir it works thanks a lot ......................HAVE A NICE DAY Ashish Dogra MCA Noida

                          1 Reply Last reply
                          0
                          • N Nawal K Gupta

                            In you use this code void OnSomeFunction() { CMy dlg; dlg.Create(IDD_DIALOG1); dlg.ShowWindow(1); } this is not safe, because the dlg object is created in Stack and it will get destroyed as soon as the function is out of scope. Create ModeLess Dialogs in Heap or Make Sure that the Object is not out of scope by making is static or Global/Top Clsss Variale Like. One Way of Doing It is: void OnSomeFunction() { static CMy * Dlg =NULL; if (!m_Dlg) { Dlg= new CMy(); Dlg->Create(IDD_DIALOG1); } dlg.ShowWindow(1); }

                            O Offline
                            O Offline
                            ovidiucucu
                            wrote on last edited by
                            #14

                            Hey, hey, dear Indian Idol! To be clear. I didn't suggest to declare a CDialog object locally in a function. Did you see that in may example? If you pay a little bit more attention, can observe that I prefixed with m_ which suggest that m_dlg is a member of class CFoo. And your static CMy *Dlg locally declared in OnSomeFunction() smells a C. And by the way... where you think it's possible to delete *Dlg in order to get rid of memory leaks? Ovidiu Cucu Microsoft MVP - Visual C++

                            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