Override the hotkey message on windows mobile platform

今天写了一个smartphone上的小程序,发现一个很奇怪的问题,就是当我用DoModal谈出一个对话框时,即使我的焦点在对话框的一个Edit control里面,只要我一按back,对话框就会被cancel掉,而不是删除edit中的一个字符。
 
找啊找啊找,终于找到了这个函数:
SHSendBackToFocusWindow
 
From MSDN:

This function sends the BACK key to the control with focus.

After an application overrides the BACK key by sending the SHCMBM_OVERRIDEKEY message to its menu bar, the BACK key message is received as a WM_HOTKEY message. Pass the WM_HOTKEY message and its wParam and lParam values to the application to forward the BACK key to child windows.

void SHSendBackToFocusWindow(
  UINT uMsg,
  WPARAM wp,
  LPARAM lp
);

Parameters

uMsg

The WM_HOTKEY message.

wParam

The wParam of the WM_HOTKEY message.

lParam

The lParam of the WM_HOTKEY message. HIWORD contains the virtual key code of the overridden key; LOWORD contains information about the modifier keys or MOD_KEYUP if the key was released.

Return Values

 
—————————
也就是说,如果我期望这个Back被送到edit control里面去,并且不cancel当前对话框,应该要做这些事情:
1。在对话框初始化的时候对他的menu bar发一个SHCMBM_OVERRIDEKEY 消息,带的参数应该是wparam = VK_TBACK, lparam = MAKELPARAM(SHMBOF_NOTIFY|SHMBOF_NODEFAULT, SHMBOF_NOTIFY|SHMBOF_NODEFAULT);
2。增加消息映射WM_HOTKEY,处理如果wparam=VK_TBACK的时候,调用SHSendBackToFocusWindow()
 
呵呵,这个东西可真难找
Advertisements
This entry was posted in Windows mobile programming. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s