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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Terminate MFC App in CView::OnInitialUpdate()

Terminate MFC App in CView::OnInitialUpdate()

Scheduled Pinned Locked Moved C / C++ / MFC
c++algorithmshelpquestion
5 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.
  • C Offline
    C Offline
    CodeBrain
    wrote on last edited by
    #1

    If am searching for a way to exit a MFC MDI application if I discover an error in CMyView::OnInitialUpdate(). If I use SendMessage(WM_CLOSE) to the main window, I get some crashes in MFC classes. Using exit(0) seems to be not very good, because of memeory leaks. So what's the best way to end a MFC application during CMyView::OnInitialUpdate()? Thanks in advance.

    J S R 3 Replies Last reply
    0
    • C CodeBrain

      If am searching for a way to exit a MFC MDI application if I discover an error in CMyView::OnInitialUpdate(). If I use SendMessage(WM_CLOSE) to the main window, I get some crashes in MFC classes. Using exit(0) seems to be not very good, because of memeory leaks. So what's the best way to end a MFC application during CMyView::OnInitialUpdate()? Thanks in advance.

      J Offline
      J Offline
      Jagadeesh VN
      wrote on last edited by
      #2

      First iterate through all the open documents, and close them one by one. Then instead of using SendMessage to send WM_CLOSE, use PostMessage. It should work. Acutually the program crashes, When OnActivateFrame( ... ) is invoked with WA_INACTIVE parameter and the 'this' pointer( which has an invalid value ). So use PostMessage. "A robust program is resistant to errors -- it either works correctly, or it does not work at all; whereas a fault tolerant program must actually recover from errors."

      1 Reply Last reply
      0
      • C CodeBrain

        If am searching for a way to exit a MFC MDI application if I discover an error in CMyView::OnInitialUpdate(). If I use SendMessage(WM_CLOSE) to the main window, I get some crashes in MFC classes. Using exit(0) seems to be not very good, because of memeory leaks. So what's the best way to end a MFC application during CMyView::OnInitialUpdate()? Thanks in advance.

        S Offline
        S Offline
        Steve S
        wrote on last edited by
        #3

        Use PostMessage instead of SendMessage. SendMessage is a synchronous do it now kind of thing, which will rip the floor from underneath you, while PostMessage will defer it until OnInitialUpdate returns. Steve S

        1 Reply Last reply
        0
        • C CodeBrain

          If am searching for a way to exit a MFC MDI application if I discover an error in CMyView::OnInitialUpdate(). If I use SendMessage(WM_CLOSE) to the main window, I get some crashes in MFC classes. Using exit(0) seems to be not very good, because of memeory leaks. So what's the best way to end a MFC application during CMyView::OnInitialUpdate()? Thanks in advance.

          R Offline
          R Offline
          Roger Allen
          wrote on last edited by
          #4

          Why not use PostQuitMessage() ? Roger Allen Sonork 100.10016 Were you different as a kid? Did you ever say "Ooohhh, shiny red" even once? - Paul Watson 11-February-2003

          J 1 Reply Last reply
          0
          • R Roger Allen

            Why not use PostQuitMessage() ? Roger Allen Sonork 100.10016 Were you different as a kid? Did you ever say "Ooohhh, shiny red" even once? - Paul Watson 11-February-2003

            J Offline
            J Offline
            Jagadeesh VN
            wrote on last edited by
            #5

            PostQuitMessage is another option. But it uses WM_QUIT instead of WM_CLOSE. I thought, since the guy was using WM_CLOSE, lets us point out, where he has went wrong. Actualy the problem was with using SendMessage, and not with WM_CLOSE. "A robust program is resistant to errors -- it either works correctly, or it does not work at all; whereas a fault tolerant program must actually recover from errors."

            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