WM_ENDSESSION WM_DESTROY WM_QUIT

//下面代码显示了如何使用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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值