新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     >>计算机科学论坛<<     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 本版讨论高级C/C++编程、代码重构(Refactoring)、极限编程(XP)、泛型编程等话题
    [返回] 计算机科学论坛计算机技术与应用『 C/C++编程思想 』 → Getting Input from the Keyboard 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 7589 个阅读者浏览上一篇主题  刷新本主题   平板显示贴子 浏览下一篇主题
     * 贴子主题: Getting Input from the Keyboard 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     卷积内核 帅哥哟,离线,有人找我吗?
      
      
      威望:8
      头衔:总统
      等级:博士二年级(版主)
      文章:3942
      积分:27590
      门派:XML.ORG.CN
      注册:2004/7/21

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给卷积内核发送一个短消息 把卷积内核加入好友 查看卷积内核的个人资料 搜索卷积内核在『 C/C++编程思想 』的所有贴子 访问卷积内核的主页 引用回复这个贴子 回复这个贴子 查看卷积内核的博客楼主
    发贴心情 Getting Input from the Keyboard

    一篇针对键盘技术非常不错的文章,由于时间关系没有翻译,看不懂的地方大家共同讨论。

    A windows application learns of keyboard events the same way it learns about mouse events: through messages. a program receives a message whenever a key is pressed or released. if you want to know when the page up or page down key is pressed so that your application can react accordingly, you process wm_keydown messages and check for key codes identifying the page up or page down key. if you'd rather know when a key is released, you process wm_keyup messages instead. for keys that produce printable characters, you can ignore key-down and key-up messages and process wm_char messages that denote characters typed at the keyboard. relying on wm_char messages instead of wm_keyup/down messages simplifies character processing by enabling windows to factor in events and circumstances surrounding the keystroke, such as whether the shift key is pressed, whether caps lock is on or off, and differences in keyboard layouts.

    the input focus
    like the mouse, the keyboard is a global hardware resource shared by all applications. windows decides which window to send mouse messages to by identifying the window under the cursor. keyboard messages are targeted differently. windows directs keyboard messages to the window with the "input focus." at any given time, no more than one window has the input focus. often the window with the input focus is the main window of the active application. however, the input focus might belong to a child of the main window or to a control in a dialog box. regardless, windows always sends keyboard messages to the window that owns the focus. if your application's window has no child windows, keyboard processing is relatively straightforward: when your application is active, its main window receives keyboard messages. if the focus shifts to a child window, keyboard messages go to the child window instead and the flow of messages to the main window ceases.

    windows notifies a window that it is about to receive or lose the input focus with wm_setfocus and wm_killfocus messages, which mfc programs process as shown here:

    // in cmainwindow's message map
    on_wm_setfocus ()
    on_wm_killfocus ()

      
    void cmainwindow::onsetfocus (cwnd* poldwnd)
    {
        // cmainwindow now has the input focus. poldwnd
        // identifies the window that lost the input focus.
        // poldwnd will be null if the window that lost the
        // focus was created by another thread.
    }

    void cmainwindow::onkillfocus (cwnd* pnewwnd)
    {
        // cmainwindow is about to lose the input focus.
        // pnewwnd identifies the window that will receive
        // the input focus. pnewwnd will be null if the
        // window that's receiving the focus is owned by
        // another thread.
    }

    an application can shift the input focus to another window with cwnd::setfocus:

    pwnd->setfocus ();

    or it can use the static cwnd::getfocus function to find out who currently has the input focus:

    cwnd* pfocuswnd = cwnd::getfocus ();


       收藏   分享  
    顶(0)
      




    ----------------------------------------------
    事业是国家的,荣誉是单位的,成绩是领导的,工资是老婆的,财产是孩子的,错误是自己的。

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2008/12/12 10:12:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 C/C++编程思想 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/5/19 23:05:44

    本主题贴数8,分页: [1]

     *树形目录 (最近20个回帖) 顶端 
    主题:  Getting Input from the Keyboard(3050字) - 卷积内核,2008年12月12日
        回复:  我先收藏了慢慢研究啊(22字) - 秋十三,2009年1月2日
        回复:  the caret, like the mouse cursor, is a shared res..(5509字) - 卷积内核,2008年12月12日
        回复:  while you might reasonably expect to overcome thi..(6011字) - 卷积内核,2008年12月12日
        回复:  returns a negative value if the shift key is held..(3410字) - 卷积内核,2008年12月12日
        回复:  if you look inside winuser.h, where the virtual k..(2333字) - 卷积内核,2008年12月12日
        回复:  the extended key flag allows an application to di..(3471字) - 卷积内核,2008年12月12日
        回复:  in the win32 environment, getfocus returns null i..(3962字) - 卷积内核,2008年12月12日

    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    78.125ms