Hide and disable X and OK processing on Windows Mobile

Source: Internet
Author: User

1. Hide X:

In wm_create
Setwindowlong (hwnd, gwl_style, ws_nonavdonebutton );

3. If you want to change the X button to exit the program instead of minimizing it, you can use it when initializing the window:
Shdonebutton (hwnd, shdb_showcancel );
Then, send the wm_close message to the window in idcancel in oncommand to close the program.

In this way, the subroutine is the OK button at the beginning.

4. In the dialog box, hide OK in the upper right corner of the screen:

 

In Win32, add the following to the wm_initdialog message:
Shdonebutton (hwnd, shdb_hide );
Setwindowlong (hwnd, gwl_style, ws_nonavdonebutton );

In MFC, follow these steps:

Bool ctew.fcdlg: onwndmsg (uint message, wparam, 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, ws_nonavdonebutton );


Return (int_ptr) true;
}
Return cdialog: onwndmsg (message, wparam, lparam, presult );
}

 

Or replace cdialog: oninitdialog directly in 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 );

 

// Set the icon in this dialog box. When the application main window is not a dialog box, the framework will automatically
// Perform this operation
Seticon (m_hicon, true); // you can specify a large icon.
Seticon (m_hicon, false); // you can specify a small icon.

// Todo: add additional initialization code here
 
Return true; // return true unless focus is set to the control.
}

 

 

 

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 method 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 MFC
All 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, uint MSG, wparam, 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, uint MSG, wparam, 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. In addition, there is another way to remove (OK) and [X] in Win32:
 
Add the ws_nonavdonebutton attribute to the style of the dialog box.
 
# Define ws_nonavdonebutton ws_minimizebox
 
Note that the ws_minimizebox and PC have different meanings.

5. Hide the input method button:
 
Use the shcmbf_hidesipbutton flag in shcreatemenubar. It is best to call sipshowim (sipf_off );
Because the caller of the program may open the input method (when the caller opens the input method, the caller may 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.