【轉載】windows mobile 上隱藏和關閉X以及OK的處理

來源:互聯網
上載者:User
【轉自】http://blog.csdn.net/czbever1、隱藏X: 在WM_CREATE裡 SetWindowLong(hWnd,GWL_STYLE,WS_NONAVDONEBUTTON );3、如果想將X按鈕改為退出程式而不是最小化,可以在初始化window時用: SHDoneButton(hWnd,SHDB_SHOWCANCEL); 然後在OnCommand中的IDCANCEL中向視窗發送WM_CLOSE訊息就可以關閉程式了這樣子程式一開始就是ok按鈕。4、對話方塊中將螢幕右上方ok隱藏:在win32中需要在WM_INITDIALOG訊息加入以下:SHDoneButton(hWnd,SHDB_HIDE); SetWindowLong(hWnd,GWL_STYLE,WS_NONAVDONEBUTTON );在MFC中,需要按以下方法處理:BOOL CtestmfcDlg::OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult){ if(message == WM_INITDIALOG) {                         // 建立一個“完成”按鈕並調整其大小。                SHINITDLGINFO shidi;                shidi.dwMask = SHIDIM_FLAGS;                shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_SIZEDLGFULLSCREEN | SHIDIF_EMPTYMENU;                shidi.hDlg = m_hWnd;    ::SHInitDialog(&shidi);    ::SHDoneButton(m_hWnd,SHDB_HIDE);     ::SetWindowLong(m_hWnd,GWL_STYLE,WS_NONAVDONEBUTTON );                          return (INT_PTR)TRUE; } return CDialog::OnWndMsg(message,wParam,lParam,pResult);}或者在直接在OnInitDialog裡替換掉CDialog::OnInitDialog.BOOL CtestmfcDlg::OnInitDialog(){    SHINITDLGINFO shidi;                shidi.dwMask = SHIDIM_FLAGS;                shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_SIZEDLGFULLSCREEN | SHIDIF_EMPTYMENU;                shidi.hDlg = m_hWnd;    ::SHInitDialog(&shidi);    ::SHDoneButton(m_hWnd,SHDB_HIDE);     ::SetWindowLong(m_hWnd,GWL_STYLE,WS_NONAVDONEBUTTON ); // 設定此對話方塊的表徵圖。當應用程式主視窗不是對話方塊時,架構將自動 //  執行此操作 SetIcon(m_hIcon, TRUE);   // 設定大表徵圖 SetIcon(m_hIcon, FALSE);  // 設定小表徵圖 // TODO: 在此添加額外的初始化代碼  return TRUE;  // 除非將焦點設定到控制項,否則返回TRUE}The button at the right of the Task Bar (the bar at the top of your Pocket PC) is called the "Smart Minimize Button".5、另外一種把X處理為退出程式的方法為子類化TaskBar:But how do we manage to have the "Smart Minimize Button" close the application for us?We have to hook it. Here's how it works: First, subclass the task bar window. The new window procedure must be looking for WM_LBUTTONUP messages in the rectangle of the button. When you intercept the message, post a WM_CLOSE message to your main frame. You will have to be careful when subclassing the task bar window procedure: you have to make sure that you will un-subclass it when your application loses the focus (deactivated) or when it is closed (essentially the same thing).The Recipe for MFCAll the work you need to do is restricted to the CMainFrame class. First, let's look at the definitions you need to add to the header file:extern HWND g_hWndMain, g_hWndTask;extern WNDPROC g_fnProcTask;static LRESULT CALLBACK TaskWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);The static variables will store the task bar and main frame's window handles. The WNDPROC will store the task bar's original window proc. Now, go to the implementation file (CPP) and add these declarations://// Static variables for task bar subclassing//static HWND g_hWndMain = NULL;static HWND g_hWndTask = NULL;static WNDPROC g_fnProcTask = NULL;Now, add the following protected methods to CMainFrame:// CMainFrame::HookTaskBar//// Hook into the task bar//BOOL CMainFrame::HookTaskBar(){ // // Already hooked? // if(g_fnProcTask)  return FALSE; g_hWndTask = ::FindWindow(_T("HHTaskBar"), NULL); if(g_hWndTask) {  g_hWndMain = GetSafeHwnd();  g_fnProcTask = (WNDPROC)::GetWindowLong(g_hWndTask, GWL_WNDPROC);  ::SetWindowLong(g_hWndTask, GWL_WNDPROC, (LONG)TaskWndProc); }  return g_hWndTask != NULL;}// CMainFrame::FreeTaskBar//// Free the task bar//BOOL CMainFrame::FreeTaskBar(){ // // Already freed? // if(!g_fnProcTask)  return FALSE;  ::SetWindowLong(g_hWndTask, GWL_WNDPROC, (LONG)g_fnProcTask); g_fnProcTask = NULL; return TRUE;}Add an OnActivate handler to the class (WM_ACTIVATE message):// CMainFrame::OnActivate//// The frame is being activated / deactivated//void CMainFrame::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized) { CFrameWnd::OnActivate(nState, pWndOther, bMinimized);  if(nState == WA_INACTIVE)  FreeTaskBar(); else  HookTaskBar();}Finally, here is the new task bar window proc.// TaskWndProc////  Handles the WM_LBUTTONUP message//LRESULT TaskWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam){ if(msg == WM_LBUTTONUP) {  RECT rc;  POINT pt;  rc.left  = 240 - 26;  rc.top  = 0;  rc.bottom = 26;  rc.right = 240;  pt.x  = LOWORD(lParam);  pt.y  = HIWORD(lParam);  if(::PtInRect(&rc, pt))  {   ::PostMessage(g_hWndMain, WM_CLOSE, 0, 0);   return ::CallWindowProc(    g_fnProcTask,     hWnd,     WM_MOUSEMOVE,     0,     MAKELPARAM(200, 0));  } } return ::CallWindowProc(g_fnProcTask, hWnd, msg, wParam, lParam);}Why the WM_MOUSEMOVE? It simulates the user dragging the stylus out of the button, and thereby restoring it to the normal state.4、另外在win32中還有另外一種去掉 (OK) 和 [x] 的辦法: 在對話方塊的風格上加 WS_NONAVDONEBUTTON 屬性 #define WS_NONAVDONEBUTTON WS_MINIMIZEBOX 注意這個 WS_MINIMIZEBOX 和 PC 上的意義不一樣5、隱藏IME按鈕: 在 SHCreateMenuBar 時使用 SHCMBF_HIDESIPBUTTON 標誌,最好還要調用 SipShowIM( SIPF_OFF );因為可能程式的調用者開啟著IME(調用者開啟著IME有時候會導致被調用者也開啟IME)
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.