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. Help in closing main application from child window

Help in closing main application from child window

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++performancetutorial
20 Posts 3 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 Blake Miller

    parent->PostMessage(WM_CLOSE); Marriage slows down your coding, a baby slows it down even more!

    P Offline
    P Offline
    pavanbabut
    wrote on last edited by
    #10

    I have noticed another thing. It is giving the same error when i try to destroy the childwindow within its OnClose() function and not calling any function of main application in it. Do you have any idea on this situation. The error occurs only when i click any of the buttons i have on the child window which calls a function in the main window and then try to destroy the child window using its OnClose() function. thanks, -Pavan

    S 1 Reply Last reply
    0
    • P pavanbabut

      I have noticed another thing. It is giving the same error when i try to destroy the childwindow within its OnClose() function and not calling any function of main application in it. Do you have any idea on this situation. The error occurs only when i click any of the buttons i have on the child window which calls a function in the main window and then try to destroy the child window using its OnClose() function. thanks, -Pavan

      S Offline
      S Offline
      StarMeteor
      wrote on last edited by
      #11

      Instead of using PostMessage function, I use SendMessage with the message as "WM_SYSCOMMAND" here is the example: ::SendMessage(pParent->m_hWnd,WM_SYSCOMMAND,SC_CLOSE,0); I guess the assertion error may be related to your child window? You should better have a look what you have done on Destroying child window, especially pointers stuff ..... :(( Hope this help

      P 1 Reply Last reply
      0
      • S StarMeteor

        Instead of using PostMessage function, I use SendMessage with the message as "WM_SYSCOMMAND" here is the example: ::SendMessage(pParent->m_hWnd,WM_SYSCOMMAND,SC_CLOSE,0); I guess the assertion error may be related to your child window? You should better have a look what you have done on Destroying child window, especially pointers stuff ..... :(( Hope this help

        P Offline
        P Offline
        pavanbabut
        wrote on last edited by
        #12

        Yep tht's right, the error is from childwindow only and arising only when I am destroying it even in its own OnClose function and again this happens only if I use any of the buttons on my childwindow which have calls to parent functions in them. The only pointer object i am having in my hcild window is a pointer to its parent window and all the functions and some public variables of the main application are called using tht pointer. I am not able to understand why I am getting this error only when I try to destroy the child window :confused: either directly or indirectly. -Pavan -- modified at 22:56 Thursday 5th January, 2006

        S 1 Reply Last reply
        0
        • P pavanbabut

          Yep tht's right, the error is from childwindow only and arising only when I am destroying it even in its own OnClose function and again this happens only if I use any of the buttons on my childwindow which have calls to parent functions in them. The only pointer object i am having in my hcild window is a pointer to its parent window and all the functions and some public variables of the main application are called using tht pointer. I am not able to understand why I am getting this error only when I try to destroy the child window :confused: either directly or indirectly. -Pavan -- modified at 22:56 Thursday 5th January, 2006

          S Offline
          S Offline
          StarMeteor
          wrote on last edited by
          #13

          How you create the child window? :^) In addition, have you trace in debug window line by line to see at which line the problem occur? ;)

          P 1 Reply Last reply
          0
          • S StarMeteor

            How you create the child window? :^) In addition, have you trace in debug window line by line to see at which line the problem occur? ;)

            P Offline
            P Offline
            pavanbabut
            wrote on last edited by
            #14

            The child creation is by defining a pointer object tot he child dialog class. Yep, i did traced it line by line and the result is it is having a null memory reference at the time when it is trying to destroy the child window or even if i comment the child window destroy statement and try to destroy the main window directly (which is of ocurse not the right way to terminate an application). So, what I doubt is the child destroy function is trying to free or access a null reference, but dont know where it happens. thanks, -Pavan. -- modified at 0:01 Friday 6th January, 2006

            S 1 Reply Last reply
            0
            • P pavanbabut

              The child creation is by defining a pointer object tot he child dialog class. Yep, i did traced it line by line and the result is it is having a null memory reference at the time when it is trying to destroy the child window or even if i comment the child window destroy statement and try to destroy the main window directly (which is of ocurse not the right way to terminate an application). So, what I doubt is the child destroy function is trying to free or access a null reference, but dont know where it happens. thanks, -Pavan. -- modified at 0:01 Friday 6th January, 2006

              S Offline
              S Offline
              StarMeteor
              wrote on last edited by
              #15

              I assume what you have done is as follow: // in Main dialog (CMainDlg), // Contain a member variable pointer of CChildDlg, so call dChildDlg // At OnInitDialog() of CMainDlg { /* Something */ dChildDlg = new CChildDlg; dChildDlg->Create(/*some param.*/); /* Something */ }; If the case is similar, maybe you check if you call : delete dChildDlg somewhere before you call: dChildDlg->DestroyWindow() Hope this help a bit~ -- modified at 4:35 Friday 6th January, 2006

              P 1 Reply Last reply
              0
              • S StarMeteor

                I assume what you have done is as follow: // in Main dialog (CMainDlg), // Contain a member variable pointer of CChildDlg, so call dChildDlg // At OnInitDialog() of CMainDlg { /* Something */ dChildDlg = new CChildDlg; dChildDlg->Create(/*some param.*/); /* Something */ }; If the case is similar, maybe you check if you call : delete dChildDlg somewhere before you call: dChildDlg->DestroyWindow() Hope this help a bit~ -- modified at 4:35 Friday 6th January, 2006

                P Offline
                P Offline
                pavanbabut
                wrote on last edited by
                #16

                My whole childwindow creation in main window initdialog goes like this- RECT rect; achild = new CChildWindow(this); achild->Create(IDD_CHILD_WINDOW,this); achild->GetClientRect(&rect); achild->MoveWindow(0,650,(rect.right-rect.left),(rect.bottom-rect.top)); achild->ShowWindow(SW_SHOW); then some of the functions in childwindow calls the functions in main window like this- void CChildWindow::OnFunction1() { // TODO: Add your control notification handler code here parent->OnKeyFunction1(); } so, where am i referencing a null memory while destroying my child window???:confused: -Pavan

                S 1 Reply Last reply
                0
                • P pavanbabut

                  My whole childwindow creation in main window initdialog goes like this- RECT rect; achild = new CChildWindow(this); achild->Create(IDD_CHILD_WINDOW,this); achild->GetClientRect(&rect); achild->MoveWindow(0,650,(rect.right-rect.left),(rect.bottom-rect.top)); achild->ShowWindow(SW_SHOW); then some of the functions in childwindow calls the functions in main window like this- void CChildWindow::OnFunction1() { // TODO: Add your control notification handler code here parent->OnKeyFunction1(); } so, where am i referencing a null memory while destroying my child window???:confused: -Pavan

                  S Offline
                  S Offline
                  StarMeteor
                  wrote on last edited by
                  #17

                  there is a problem assume your OnKeyFunction1 at parent (CMainWindow::OnKeyFunction1()) is for closing the application, in it you will KILL the child (i.e. delete the pointer of child window or equivlant) and so the function don't know how to return to the child part (CChildWindow::OnKeyFunction1)!! so, what you have to do is change the structure: 1. Use callback function to use parent window function instead of directly calling, callback allow window to handle when to call the function 2. Use Send message as the "tunnel" for commuincation for some command function 3. try to build the function in child only if it only consider to be used in child hope this help!

                  P 1 Reply Last reply
                  0
                  • S StarMeteor

                    there is a problem assume your OnKeyFunction1 at parent (CMainWindow::OnKeyFunction1()) is for closing the application, in it you will KILL the child (i.e. delete the pointer of child window or equivlant) and so the function don't know how to return to the child part (CChildWindow::OnKeyFunction1)!! so, what you have to do is change the structure: 1. Use callback function to use parent window function instead of directly calling, callback allow window to handle when to call the function 2. Use Send message as the "tunnel" for commuincation for some command function 3. try to build the function in child only if it only consider to be used in child hope this help!

                    P Offline
                    P Offline
                    pavanbabut
                    wrote on last edited by
                    #18

                    Hi, Thanks for ur replies. Today I recognised one thing which is causing me the same error. Actually my program is having 2 threads running parallel (but will be in suspended state when they r not used and resumed when needed) to the main application. My application is terminating well without any errors if I am not starting any of the threads. But when I have started them even once and then try to terminate the application or even if I click on the main application window it is giving me the same error, Access Violation and at the time of debugging the error it is sometimes pointing to // delegate to object's WindowProc lResult = pWnd->WindowProc(nMsg, wParam, lParam); in WINAFX.h. Any idea??:confused: -Pavan -- modified at 16:47 Monday 9th January, 2006

                    S 1 Reply Last reply
                    0
                    • P pavanbabut

                      Hi, Thanks for ur replies. Today I recognised one thing which is causing me the same error. Actually my program is having 2 threads running parallel (but will be in suspended state when they r not used and resumed when needed) to the main application. My application is terminating well without any errors if I am not starting any of the threads. But when I have started them even once and then try to terminate the application or even if I click on the main application window it is giving me the same error, Access Violation and at the time of debugging the error it is sometimes pointing to // delegate to object's WindowProc lResult = pWnd->WindowProc(nMsg, wParam, lParam); in WINAFX.h. Any idea??:confused: -Pavan -- modified at 16:47 Monday 9th January, 2006

                      S Offline
                      S Offline
                      StarMeteor
                      wrote on last edited by
                      #19

                      hmm.... those thread are worker thread or UI thread? :doh:

                      P 1 Reply Last reply
                      0
                      • S StarMeteor

                        hmm.... those thread are worker thread or UI thread? :doh:

                        P Offline
                        P Offline
                        pavanbabut
                        wrote on last edited by
                        #20

                        Those threads are worker threads, i hope. But there is a statement in those, which calls another child window on the main application using the window handle and updates the image of tht window (since this application is a real time image grabbing application). -Pavan.

                        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