WM

    技术2022-05-11  14

    //下面代码显示了如何使用WM_ENDSESSION WM_DESTROY WM_QUIT消息,基本上来自于//<<win95-a-developers-guide>>的第一章

     

    LRESULT WINAPI XXX_WndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam) switch(uMsg){  HANDLE_MSG(hwnd,WM_CLOSE,  xxx_OnClose);  HANDLE_MSG(hwnd,WM_DESTROY,  xxx_OnDestroy);  HANDLE_MSG(hwnd,WM_QUERYENDSESSION, xxx_OnQueryEndSession);  HANDLE_MSG(hwnd,WM_ENDSESSION,  xxx_OnEndSession); } return( DefWindowProc(hwnd,uMsg,wParam,lParam));} BOOL xxx_OnQueryEndSession(HWND hwnd) //For demonstration purpose ,pretend that there is unsaved data. BOOL fIsDataUnsaved = TRUE; BOOL fOkToEndSession = TRUE; if (fIsDataUnsaved) {  //Present message box.  int n = MessageBox(hwnd,__TEXT("Do you want to save changes?"),   __TEXT("xxx --Example technique for proper shutdown"),   MB_YESNOCANCEL|MB_ICONWARNING);  if(n == IDYES)  {   //you would present a file save dialog box here.  }  if (n == IDCANCEL)   fOkToEndSession = FALSE; } return(fOkToEndSession);} // void  xxx_OnEndSession(HWND hwnd, BOOL fEnding) if (fEnding) {  //if the session is really ending ,explicitly destroy the window.  DestroyWindow(hwnd);  //DestroyWindow will send WM_DESTROY and WM_NCDESTROY message. }} // void  xxx_OnDestroy(HWND hwnd) //the system will automaticllyu destory the edit child window. //the main window is being destroyed;signal the message loop to terminate //so that the thread and process terminate. PostQuitMessage(0);} // void  xxx_OnClose(HWND hwnd) // we handle WM_CLOSE the same way we would handle a logoff or shutdown. BOOL fOkToClose = xxx_OnQueryEndSession(hwnd); xxx_OnEndSession(hwnd,fOkToClose);} //

     


    最新回复(0)