[Reprinted] Hide and disable X and OK processing on windows mobile

Source: Internet
Author: User
[Conversion] SetWindowLong (hWnd, GWL_STYLE, WS_NONAVDONEBUTTON) in WM_CREATE; 3. If you want to change the X button to exit the program rather than minimize, you can use: SHDoneButton (hWnd, SHDB_SHOWCANCEL); then, send the WM_CLOSE message to the window in IDCANCEL of OnCommand to close the program. Then, the subroutine is the OK button at the beginning. 4. In the dialog box, hide the "OK" button in the upper right corner of the screen: add the following to the WM_INITDIALOG message in win32: SHDoneButton (hWnd, SHDB_HIDE); SetWindowLong (hWnd, GWL_STYLE, ws_nonavdoneb, you must follow these steps: BOOL ctew.fcdlg: OnWndMsg (UINT message, WPARAM wParam, LPARAM lParam, LRESULT * pResult) {if (message = WM_INITDIALOG) {// create a "finish" button and adjust its size. 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, success); return (INT_PTR) TRUE ;} return CDialog: OnWndMsg (message, wParam, lParam, pResult);} or directly replace CDialog: OnInit in OnInitDialog. Dialog. 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, success); // set the icon of this dialog box. When the main window of the application is not a dialog box, the framework will automatically // execute this operation SetIcon (m_hIcon, TRUE); // set the big icon SetIcon (m_hIcon, FALSE ); // set the small icon // TODO: add the extra initialization code return TRUE here; // unless you set the focus to the control, otherwise return 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. Another way to process X as an exit program is to subclass 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 (essential 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 v Ariables 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: // CMain Frame: 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 = callback) {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. In addition, there is another way to remove (OK) and [x] in win32: add the WS_NONAVDONEBUTTON attribute # define WS_NONAVDONEBUTTON WS_MINIMIZEBOX to the style of the dialog box. Note that the WS_MINIMIZEBOX has different meanings from the PC. 5. Hide the input method button: Use the fuse flag in shcreatemen, it is better to call SipShowIM (SIPF_OFF); because the caller of the program may open the input method (the caller opens the input method sometimes causes the caller to also open the input method)
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.