转自: http://kevinyisuihan.blog.163.com/blog/static/404793222008812942364/

When working on a project that involved creating a custom dialer for Windows Mobile devices, one of the more important tasks is enabling the detection of the Send (green, off-hook) and Hang-up (red, on-hook) button presses at all times. The difficulty with this feat is that the Windows Mobile OS has specific needs for these buttons so you have to be careful with how you go about using them.

For example the Send button is used for launching the phone application (cprog.exe by default), and also perform phone related tasks like making and answering calls or calling a contact. The Hang-up button is used to minimize dialogs and hang up active calls.

On some devices the Hang-up button can have other behaviors such as acting as a power button or enabling keyboard lock. It’s important to know these facts, because depending on what you intend to do with the Send or Hang-up buttons, you may cause existing features of the OS to not function.

There are several methods to detect the Send and Hang-up buttons, but only a few methods will let you safely co-exist with the existing features of the Windows Mobile OS. I’ll first talk about obtaining the key presses through use of keyboard hook (SetWindowsHook) and why you shouldn’t use it. This is the first method I used for the project but quickly learned about the various limitations. If you do an Internet search for “Windows Mobile SetWindowsHook” you will obtain several pages explaining how to use SetWindowsHook on the device to detect each key press. Using this method to detect the Send or Hang-up keys you may discover several set backs.

You are not just intercepting the Send or Hang-up keys but every key press so you’ll have to be extra careful about handling them.
If an existing application already has the keyboard hook, you may not be able to use it. On a device like the Palm Treo 700/750 you may find that the Key-guard feature no longer works. This is because the Palm Key-guard also relies on the keyboard hook and can no longer use it if another application has control of it.
You may find that certain features that rely on Send/Hang-up no long work. For example you can no longer dial a number from Contacts with the Send button.

There are ways around these limitations of course, but it would require a lot of manual handling from your application.

Another method of key detection is the use of hotkey registration. Microsoft provides us with the “RegisterHotKey” function which essentially allows you to register any button with your application window as a hotkey using the virtual key codes (VK_TTALK for Send, VK_TEND for Hang-up). What this does is, when the registered key is pressed; it will send you a WM_HOTKEY message, even if your window is not in the foreground, allowing you to handle it.

However there are a couple limitations when dealing with the Send and Hang-up keys. You may find that attempting to register either buttons as a hot key will fail. The reason is that the TaskBar (PPC) or Tray (Smartphone) already has Send button registered as a hotkey and the phone application has the Hang-up button.

You can forcibly “steal” the hot key using either the “UnregisterHotKey” function or the hidden “UnregisterFunc1” function; however taking the hot key away from their respective owners would render some features useless as with the cases when using “SetWindowsHook”.

After some experimentation I have found that there is a unique way in which you may register the Send and Hang-up buttons (and possibly other buttons) as hot keys. I’ve discovered that it is possible to register a button using 0x2001 as a modifier (some others will work as well such 0x2002, etc). What this does is it will generate a WM_HOTKEY message for you when pressing the Send button without interfering with the existing hot key registration held by the TaskBar or Tray or phone application. The limitation here, however, is that you will only get “one shot”; that is, only one WM_HOTKEY is generated and successive key presses will have no notifications. The solution is simply to register the key again. The code would look as follows (note that error and results checking are left out for simplicity)

// setup the window to receive the hot key message

ON_MESSAGE(WM_HOTKEY, &MyappDlg::OnHotkey)

...

// define some of the values to use for registering hot keys

#define ONE_SHOT_MOD 0x2001

#define VK_TTALK_ID 0x07

#define VK_TEND_ID 0x08

...

// register the Send and Hang-up buttons with the unique modifier

::RegisterHotKey(m_hWnd, VK_TTALK_ID, ONE_SHOT_MOD, VK_TTALK);

::RegisterHotKey(m_hWnd, VK_TEND_ID, ONE_SHOT_MOD, VK_TEND);

...

// wait for and handle the hot key messages

afx_msg LRESULT MyappDlg::OnHotkey( WPARAM wParam, LPARAM lParam )

{

switch (lParam >> 16)

{

case VK_TTALK:

// reregister VK_TTALK to get the next key press

::RegisterHotKey(m_hWnd, VK_TTALK_ID, ONE_SHOT_MOD, VK_TTALK);

// handle the keypress...

break;

case VK_TEND:

// reregister VK_TEND to get the next key press

::RegisterHotKey(m_hWnd, VK_TEND_ID, ONE_SHOT_MOD, VK_TEND);

// handle the keypress...

break;

...

So there you have it. Each time the Send and Hang-up buttons are pressed you get a notification and you don’t have to worry about interfering with the normal operations of each button.

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/ice520301/archive/2009/12/31/5112448.aspx

Override VK_TTALK VK_TEND相关推荐

  1. 浅显易懂 Makefile 入门 (02)— 普通变量和自动变量定义、使用($@、$^、$< 作用)、变量覆盖 override、变量的来源 origin

    1. 变量的定义 Makefile 文件中定义变量的基本语法如下: 变量的名称=值列表 变量的名称可以由大小写字母.阿拉伯数字和下划线构成.等号左右的空白符没有明确的要求,因为在执行 make 的时候 ...

  2. C#中类的继承 override virtual new的作用以及代码分析

    继承中override virtual new的作用 virtual 父类中需要注明允许重写的方法: override 子类中必须显示声明该方法是重写的父类中的方法: new 子类中忽略父类的已存在的 ...

  3. C++11中override的使用

    override是C++11中的一个继承控制关键字.override确保在派生类中声明的重载函数跟基类的虚函数有相同的声明. override明确地表示一个函数是对基类中一个虚函数的重载.更重要的是, ...

  4. Java 重写(Override)与重载(Overload)

    TestDog.java /*  * 重写(Override)  * 重写是子类对父类的允许访问的方法的实现过程进行重新编写, 返回值和形参都不能改变.即外壳不变,核心重写!  * 重写的好处在于子类 ...

  5. 坚持使用Override 注解(36)

    2019独角兽企业重金招聘Python工程师标准>>> 1.覆盖超类时千万小心,一不小心就变成重载了 2.现代的IDE 会在覆盖父类方法而没有使用@Override 时给出一个警告 ...

  6. 在有@Override方法上面会报错如下

    在有@Override方法上面会报错如下: The method oncreate(Bundle) of type HelloWorld must override or implement a su ...

  7. 重载和覆盖的区别?(overload vs override)

    override与overload的区别? override 表示重写,overload 表示重载. override是子类和父类之间的关系,是垂直关系:overload是同一个类中方法之间的关系,是 ...

  8. 新装myeclispse8.6GA、@Override出错

    过几天要考试,重新配下环境.下载好myeclispse8.6.tomcat6.0.myeclispse优化工具.myeclispse语言转换工具. 开始干活,因为myeclispse8.6集成JDK, ...

  9. java override overwrite,重写(overwrite)、重载(overload)和覆盖(override)

    覆盖(override):子类继承了父类的同名无参函数.当子类从父类继承了一个无参函数,而又定义了一个同样的无参函数,则子类定义的方法覆盖父类的方法,称为覆盖.废弃父方法 1.覆盖的方法的标志必须要和 ...

最新文章

  1. C Capture Full IE Document
  2. 【产品】阿里产品经理内训:能力模型解读
  3. 王盛:QUIC让B站在20%丢包时实现零卡顿
  4. 新浪微博授权认证过程
  5. C语言入门基础——Brute-Force算法
  6. Android--快速接入微信支付
  7. 【披着递推皮的动态规划】 山区建小学 题解
  8. appfuse_AppFuse 3.0
  9. opencontrail 2.20
  10. 【VOIP】 yate源码编译和部署
  11. 光纤信号服务器,485转光纤的两种方式
  12. 姓潘取名:潘姓有气质的女孩名字
  13. POJ 1392 Ouroboros Snake(数位欧拉:输出路径)
  14. 做项目的一些心得体会
  15. 鸿蒙升级后桌面背景底纹怎么弄,ps添加背景怎么弄
  16. AtCoder Beginner Contest 190 D - Staircase Sequences
  17. ArcGIS提取栅格数据中的指定部分(可以是矢量数据也可时栅格数据)
  18. php 函数索引 中文索引
  19. 跨页面清除Cookie信息
  20. python算法(基础)----无序列表抽象数据类型

热门文章

  1. 从Chapman–Kolmogorov 方程推导出n步转移矩阵
  2. Powershell中安装cnpm
  3. linux 安装 cnpm
  4. java.lang.ClassNotFoundException: Cannot find class: com.***.****.***.***.NewStudentDto
  5. python调用aspen_用Matlab与Aspen Plus通信
  6. W11手动添加python环境变量
  7. HTML5期末大作业:旅游景点网站设计——成都(6页) HTML+CSS+JavaScript 大学生家乡网页设计作业模板下载 四川成都城市网页设计作业成品 静态HTML旅游景点网页制作下载
  8. 史上最全“大数据”学习资源集合
  9. 插入,选择和冒泡排序原理
  10. Maven - name artifactId 区别?