Search code examples
winapimdi

Win32 : MDI & Exit Code 18 (0x12)


I'm a beginner and trying to learn win32 API by following some tutorial. I create a MDI window.

However, my window application is exiting with code 18 (0x12).

Native' has exited with code 18 (0x12).

I have no idea why it is not exiting with code '0'.

I replace PostQuitMessage ( WM_QUIT ) with PostQuitMessage ( 0 ) and the problem is solved.

Next Question is:

  1. What is the different between PostQuitMessage(WM_QUIT) and PostQuitMessage(0)?

  2. How to have only one same submenu child window is opened.

Can Open same submenu twice


Solution

  • Your WinMain() function is returning the wParam value of the last message received by GetMessage(), which is WM_QUIT. Its wParam value is specified in the call to PostQuitMessage(). You are passing WM_QUIT as that value, instead of 0:

    case WM_DESTROY:
        PostQuitMessage(WM_QUIT);
        return 0;
    

    WM_QUIT has a numeric value of 18 (0x12):

    #define WM_QUIT                         0x0012
    

    That is why your program is exiting with code 18.