MessageBox 訊息對話方塊

來源:互聯網
上載者:User
 1.參數的使用  
  MB_SYSTEMMODAL   所有視窗的Modal模式,含   WS_EX_TOPMOST   風格(該風格可通過MB_TOPMOST單獨設定)      
  MB_SERVICE_NOTIFICATION   顯示在當前案頭,即使沒有使用者登入(一般用於service   服務)  
   
  對話方塊中messagebox問題    
  http://community.csdn.net/Expert/topic/3318/3318010.xml?temp=.359234  
   
  2.MessageBoxIndirect   (一般用於自訂表徵圖)  
      MSGBOXPARAMS   msgBox;  
      msgBox.cbSize   =   sizeof(MSGBOXPARAMS);  
      msgBox.dwStyle   =   MB_USERICON   |   nButtons;  
      msgBox.hInstance   =   AfxGetApp()->m_hInstance;  
      msgBox.hwndOwner   =   NULL;  
      msgBox.lpszCaption   =   lpszTitle;  
      msgBox.lpszIcon   =   MAKEINTRESOURCE(nResourceID);//資源中的ICON  
      msgBox.lpszText   =   lpszText;  
      MessageBoxIndirect(&msgBox);  
       
  如何在MessageBox中使用MB_USERICON屬性?    
  http://community.csdn.net/Expert/topic/4193/4193253.xml?temp=.2414667  
   
  3.WH_CBT   鉤子   (一般用於設定視窗位置和修改按鈕文本)  
  a)設定視窗的位置(http://support.microsoft.com/default.aspx?scid=kb;en-us;180936)  
  HHOOK   hHook;  
  LRESULT   CALLBACK   CBTProc(int   nCode,WPARAM   wParam,LPARAM   lParam)  
  {  
  if(nCode   ==   HCBT_ACTIVATE)  
  {  
  RECT   rect;  
  GetWindowRect(hWnd,   &rect);  
  MoveWindow((HWND)hWnd,   0,   0,   rect.right-rect.left,   rect.bottom-rect.top,   TRUE);  
  }  
  return   CallNextHookEx(hHook,   nCode,   wParam,   lParam);  
  }  
   
  使用方法  
  hHook   =   SetWindowsHookEx(WH_CBT,   CBTProc,   GetModuleHandle(NULL),   0);  
  MessageBox(NULL,   "hello   world!",   "info",   MB_OK);  
  問題列表:  
  如何指定MessageBox框的彈出位置   急    
  http://community.csdn.net/Expert/topic/3695/3695161.xml?temp=.1622888  
  如何設定MessageBox彈出的位置?    
  http://community.csdn.net/Expert/topic/3196/3196290.xml?temp=.1177027  
  MessageBox彈出框的顯示位置    
  http://community.csdn.net/Expert/topic/4035/4035756.xml?temp=.9125635  
  請問如何改變AfxMessageBox對話方塊的初始位置?    
  http://community.csdn.net/Expert/topic/3519/3519806.xml?temp=.5104181  
   
  b)修改按鈕文本(一般用於國際化)  
  HHOOK   hHook;  
  LRESULT   __stdcall   CBTHookProc(   long   nCode,WPARAM   wParam,LPARAM   lParam)  
  {  
      if   (nCode==HCBT_ACTIVATE)  
      {  
      SetDlgItemText((HWND)wParam,IDYES,"&Yes");  
      SetDlgItemText((HWND)wParam,IDNO   ,"&No");  
      SetDlgItemText((HWND)wParam,IDOK,"&OK");  
      SetDlgItemText((HWND)wParam,IDCANCEL,"&Cancel");  
      UnhookWindowsHookEx(hHook);  
      }  
      return   0;  
  }  
  使用方法:  
  hHook=SetWindowsHookEx(WH_CBT,(HOOKPROC)CBTHookProc,AfxGetInstanceHandle(),NULL);  
  問題列表:  
  messagebox的確定安鈕怎麼老是中文,如何顯示英文    
  http://community.csdn.net/Expert/topic/4094/4094181.xml?temp=.3754541  
   
  P.S.   過一段時間消失的MessageBox(源自MSDN)  
  void   CALLBACK   MessageBoxTimer(HWND   hwnd,   UINT   uiMsg,   UINT   idEvent,   DWORD   dwTime)  
  {  
        PostQuitMessage(0);  
  }  
  UINT   TimedMessageBox(HWND   hwndParent,   LPCTSTR   ptszMessage,   LPCTSTR   ptszTitle,   UINT   flags,   DWORD   dwTimeout)  
  {  
        MSG   msg;  
        UINT   idTimer   =   SetTimer(NULL,   0,   dwTimeout,   (TIMERPROC)MessageBoxTimer);  
        UINT   uiResult   =   MessageBox(hwndParent,   ptszMessage,   ptszTitle,   flags);  
        KillTimer(NULL,   idTimer);  
        if   (PeekMessage(&msg,   NULL,   WM_QUIT,   WM_QUIT,   PM_REMOVE))   {  
                uiResult   =   0;//預設值  
        }  
        return   uiResult;  
  }  
  使用方法同MessageBox,只是多了個DWORD參數   dwTimeout

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.