The annoying ghost key on Smartphone

Source: Internet
Author: User
The Development on PPC is not a short time! Start SP! At the beginning, I encountered a headache. the backend key in textbox does not work, and it is dizzy! After a while, I found some information and solved the problem. I saved it here for archiving.

-------- BelowTextFrom csdn blog.

    1. If the current window is not a dialogbox or there is no editbox, the previous window should be displayed when the back key is pressed. However, the current window should not be destroyed, but be overwritten by the previous window.
    2. If the current window is a MessageBox or a modal dialog without editbox, close the dialog box when you press the back key. For MessageBox, the return value of the dialog box may be IDNO, idcancel or idok. For the modal dialog box, the dialog box will receive a message of wm_command whose ID value is idcancel.
    3. If the current window contains editbox, when you press the back key, delete the last character in editbox.

/*
* I have a problem here. This articleArticleNote that the modal dialog box and the non-modal dialog box have different processing conditions. If the non-modal dialog box is used, you can continue to read it and follow the article, but if you
* If the window is domodal (), you do not need to change the behavior of the back key. You only need to respond to idcancel and then shsendbacktofocuswindow (wm_hotkey, 2, makelparam (mod_keyup, vk_tback ));
* In this way, the test is successful on Dopod 575!
/*

In the third case, the system does not automatically handle the issue. We need to do some work on our own.

First, we need to send a shcmbm_overridekey message to menubar to notify menubar that we want to change the behavior of the backkey.

The wparam parameter of the shcmbm_overridekey message is the key value to change the behavior, as shown in the following table:

Key Meaning
Vk_tback Back button
Vk_tsoft1 Left softkeybar button
Vk_tsoft2 Right softkeybar button
Vk_tvolumeup Up volume button
Vk_tvolumedown Down volume button
Vk_trecord Record button

The lparam parameter of the shcmbm_overridekey message is the behavior we want to change. The low byte of lparam is the mask and the high byte is the value.

For example, if we want to remove the default behavior of the backend key and want to send the wm_hotkey message to the current window when the backend key is pressed, we can do this:

 
Sendmessage (shfindmenubar (hwnd), shcmbm_overridekey, vk_tback, makelparam (shmbof_nodefault | shmbof_notify, shmbof_nodefault | shmbof_notify ));

Shmbof_nodefault is the default act of removing the backkey, and shmbof_notify is the message to send the key press to the window.

The first parameter of the makelparam macro is low, and the second parameter is high.

If we only want to remove the default behavior of the backkey, and do not need to send the wm_hotkey message to the window, we can do this:

Sendmessage (shfindmenubar (hwnd), shcmbm_overridekey, vk_tback,
Makelparam (shmbof_nodefault | shmbof_policy,
Shmbof_nodefault ));

To restore the default behavior of the backend key, you can do this:

Sendmessage (shfindmenubar (hwnd), shcmbm_overridekey, vk_tback,
Makelparam (shmbof_nodefault | shmbof_policy,
0 ));

In the wm_hotkey message received by the window, wparam indicates the key to be pressed, as shown in the following table:

Key Value
Vk_tsoft1 0
Vk_tsoft2 1
Vk_tback 2
Vk_tvolumeup 3
Vk_tvolumedown 4
Vk_trecord 5

 

Lparam also contains the key value, but it is different. In lparam, high indicates the key value to be pressed, and low indicates other values to be pressed. For smartphone, mod_keyup indicates that the key has been released.

When we receive the wm_hotkey message, we need to delete the characters.CodeTo do this, you only need to call a function provided by the system:

Void shsendbacktofocuswindow (uint umsg, wparam WP, lparam LP );

Therefore, the code for processing the wm_hotkey message can be written as follows:

 
Case wm_hotkey: If (hiword (lparam) = vk_tback) shsendbacktofocuswindow (wmsg, wparam, lparam); in this way, the last character is deleted.
 
Finally, if menubar is destroyed, the behavior of changing the backend key will be automatically terminated, and no code for restoration is required.
 
The original URL of the article can be viewed as follows:
 
Http://msdn.microsoft.com/library/default.asp? Url =/library/en-US/win_ce/html/pwc_thebackbuttonandotherinterestingbuttons.asp
 
You can also execute this function by letting the backend key execute the default action:
 
Void shnavigateback (void );
 
If you have installed the wm5 for smartphone SDK, you can refer to the following example:
 
C: \ Program Files \ Windows CE tools \ wce500 \ Windows Mobile 5.0 smartphone SDK \ samples \ CPP \ Win32 \ back \Back. sln 
 
RecentlyProgramPut it on the dopod585 and run it. The system won't be able to intercept the message of the backkey. no way, you have to intercept the global message, and then determine whether to backend the key before processing.
 

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.