why my programs end during onClose event?

This is a discussion on why my programs end during onClose event? within the Windows Programming forums, part of the Platform Specific Boards category; Hi everyone, there is something that I'm not very clear about. Why do my program close when I click the ...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    58

    why my programs end during onClose event?

    Hi everyone,
    there is something that I'm not very clear about. Why do my program close when I click the cross button on the top right hand corner where I had comment the on PostMessage for the following code below? And also, why when I Post WM_DESTORY, my dialog did not close?

    Code:
    void CMYDlg::OnClose() 
    {	
      int returnValue=IDNO;
      retValue = ::MessageBox(NULL, _T("You are about to close the application, are you sure you want to continue?"), 
    							_T("Testing"), MB_YESNO|MB_ICONQUESTION);
      if(returnValue == IDYES)
      {
    	 ::PostMessage(0,WM_DESTROY,NULL,NULL);
      }
      CDialog::OnClose();
    }

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    CDialog::OnCLose() will call the code to destroy your Dlg.

    Try something like....


    Code:
    void CMYDlg::OnClose() 
    {	
      int returnValue=IDNO;
      retValue = ::MessageBox(NULL, _T("You are about to close the application, are you sure you want to continue?"), 
    							_T("Testing"), MB_YESNO|MB_ICONQUESTION);
      if(returnValue == IDYES)
      {
    	 CDialog::OnClose();  
      }
      
    }
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,538
    1) Suggest you don't post messages directly in a MFC app - suggest you use proper functions such as EndDialog or call the base function's member.
    2) There's no use in using ::MessageBox since you can just use MessageBox which is relative to your window. You are just passing NULL, which is usually just done where there's no window, so in this case use CWnd's MessageBox and don't worry about the HWND.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  2. Problem using java programs within C code
    By lemania in forum Linux Programming
    Replies: 1
    Last Post: 05-08-2005, 02:02 AM
  3. delegate & event
    By Micko in forum C# Programming
    Replies: 5
    Last Post: 03-08-2004, 03:05 AM
  4. Replies: 2
    Last Post: 09-22-2003, 01:47 PM
  5. POSIX/DOS programs?
    By nickname_changed in forum C++ Programming
    Replies: 1
    Last Post: 02-28-2003, 04:42 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21