Ignore:
Timestamp:
Feb 9, 2016, 12:57:59 PM (10 years ago)
Author:
rousseau
Message:

Changed application termination [apitest]

Termination is now redirected to WM_CLOSE.
WM_CLOSE does a DestroyWindow(), which in turn generates a WM_DESTROY
message, which is where the main message-loop is ended by doing a call
to PostQuitMessage().

At exit however, the 'wParam' field of the 'msg' structure does not
contain the exit-code as provided with PostQuitMessage().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/swt/testapp/apitest/src/ApiTestWin.cpp

    r22113 r22115  
    9595                /* Message from the button, we post a message to close the window */
    9696                case ID_EXIT:
    97                     PostQuitMessage(0);
    98                     break;
    99 
    100                 /* Exit Message from the File Menu, forward it to ID_EXIT */
     97                    PostMessage(hwnd, WM_CLOSE, NULL, NULL);
     98                    break;
     99
     100                /* Message from the button, we post a message to close the window */
    101101                case ID_FILE_EXIT:
    102                     PostMessage(hwnd, WM_COMMAND, (UINT) ID_EXIT, NULL);
     102                    PostMessage(hwnd, WM_CLOSE, NULL, NULL);
    103103                    break;
    104104
     
    132132
    133133        /*
    134         // Request to quit the application.
     134        // This message is generated by a call to PostQuitMessage() or the
     135        // posting of a WM_QUIT message. It causes GetMessage() to return zero
     136        // and thus the message-loop to end. So this message is never
     137        // dispatched and this case thus never reached. After the message-loop
     138        // ends, the message-structure contains this message with an exit-code
     139        // (from PostQuitMessage()) in wParam.
    135140        */
    136141        case WM_QUIT:
     
    140145
    141146        /*
    142         // Request to close the application.
    143         // On Win32 WM_CLOSE does a DestroyWindow() but does not post a WM_QUIT
    144         // message and thus does not terminate the message-loop.
     147        // This message is sent when the close-button is clicked.
     148        // On Win32, DefWindowProc() does a DestroyWindow(), but does not post
     149        // a WM_QUIT message and thus does not terminate the message-loop.
    145150        */
    146151        case WM_CLOSE:
    147152            printf("WM_CLOSE received\n");
    148153            lres = DefWindowProc(hwnd, msg, wparam, lparam);
    149             PostQuitMessage(0);
    150             break;
    151 
    152         /*
    153         // Window is being destroyed, time to cleanup resources allocated.
     154            break;
     155
     156        /*
     157        // This message is generated by a call to DestroyWindow().
     158        // At the time this message is received, the windows and its children
     159        // are not destroyed yet.
    154160        */
    155161        case WM_DESTROY:
    156162            printf("WM_DESTROY received\n");
    157163            lres = DefWindowProc(hwnd, msg, wparam, lparam);
     164            PostQuitMessage(99);
    158165            break;
    159166
     
    266273    hwnd = CreateWindow(
    267274        MainWndClass,                   // Our Window Class
    268         "ApiTestWin :: Main Window [generated:201602071054]",   // Caption Text
     275        "ApiTestWin :: Main Window [generated:201602071950]",   // Caption Text
    269276        WS_OVERLAPPEDWINDOW,            // Window Stype
    270277        100,                            // The x-pos from ulc
     
    292299    }
    293300
     301    /* Last Message Info */
     302    printf("\n");
     303    printf("Last Message:\n");
     304    printf("msg.hwnd=%08X\n", msg.hwnd);
     305    printf("msg.message=%08X (%d)\n", msg.message, msg.message);
     306    printf("msg.wParam=%08X (%d)\n", msg.wParam, msg.wParam);
     307    printf("msg.lParam=%08X (%d)\n", msg.lParam, msg.lParam);
     308
    294309    /* App is terminating */
     310    printf("\n");
    295311    printf("ApiTestWin is terminating...\n");
    296312
     
    307323    printf("\n");
    308324    printf("%s\n","###############################################################################");
    309     printf("%s\n","# This is the Windows variant of ApiTest                 version.201602071054 #");
     325    printf("%s\n","# This is the Windows variant of ApiTest                 version.201602071950 #");
    310326    printf("%s\n","###############################################################################");
    311327    printf("\n");
Note: See TracChangeset for help on using the changeset viewer.