Programming Windows with MFC - Capter 3. Mouse and keybord

  1. Device drivers process mouse and keyboard interrupts and place the resultant event notifications in a systemwide queue known as the raw input queue.

  2. A dedicated thread owned by the operating system monitors the raw input queue and transfers each message that shows up there to the appropriate thread message queue.

  3. Win32's asynchronous input model solves this problem by using the raw input queue as a temporary holding buffer and moving input messages to thread message queues at the earliest opportunity.

  4. Client-Area Mouse Messages

    MessageSent When
    WM_LBUTTONDOWNThe left mouse button is pressed.
    WM_LBUTTONUPThe left mouse button is released.
    WM_LBUTTONDBLCLKThe left mouse button is double-clicked.
    WM_MBUTTONDOWNThe middle mouse button is pressed.
    WM_MBUTTONUPThe middle mouse button is released.
    WM_MBUTTONDBLCLKThe middle mouse button is double-clicked.
    WM_RBUTTONDOWNThe right mouse button is pressed.
    WM_RBUTTONUPThe right mouse button is released.
    WM_RBUTTONDBLCLKThe right mouse button is double-clicked.
    WM_MOUSEMOVEThe cursor is moved over the window's client area.

    int nButtonCount = ::GetSystemMetrics (SM_CMOUSEBUTTONS) ;

  5. If pairing is essential, a program can "capture" the mouse on receipt of a button-down message and release it when a button-up message arrives.
  6. For a CS_DBLCLKS-style window, two rapid clicks of the left mouse button over the window's client area produce the following sequence of messages:

    WM_LBUTTONDOWN
    WM_LBUTTONUP
    WM_LBUTTONDBLCLK
    WM_LBUTTONUP

    Applications that process single and double clicks of the same button typically select an object on the first click and take some action upon that object on the second click.

  7.  As the mouse is moved, the window under the cursor receives a flurry of WM_MOUSEMOVE messages reporting the latest cursor position.

  8. Message-Map Macros and Message Handlers for Client-Area Mouse Messages

    MessageMessage-Map MacroHandling Function
    WM_LBUTTONDOWNON_WM_LBUTTONDOWNOnLButtonDown
    WM_LBUTTONUPON_WM_LBUTTONUPOnLButtonUp
    WM_LBUTTONDBLCLKON_WM_LBUTTONDBLCLKOnLButtonDblClk
    WM_MBUTTONDOWNON_WM_MBUTTONDOWNOnMButtonDown
    WM_MBUTTONUPON_WM_MBUTTONUPOnMButtonUp
    WM_MBUTTONDBLCLKON_WM_MBUTTONDBLCLKOnMButtonDblClk
    WM_RBUTTONDOWNON_WM_RBUTTONDOWNOnRButtonDown
    WM_RBUTTONUPON_WM_RBUTTONUPOnRButtonUp
    WM_RBUTTONDBLCLKON_WM_RBUTTONDBLCLKOnRButtonDblClk
    WM_MOUSEMOVEON_WM_MOUSEMOVEOnMouseMove

  9. The nFlags Parameter

    MaskMeaning If Set
    MK_LBUTTONThe left mouse button is pressed.
    MK_MBUTTONThe middle mouse button is pressed.
    MK_RBUTTONThe right mouse button is pressed.
    MK_CONTROLThe Ctrl key is pressed.
    MK_SHIFTThe Shift key is pressed.

    if( 1 == nFlags & MK_LBUTTON ){ //do std }
  10. When a WM_RBUTTONUP message is passed to the system for default processing, 
    Windows places a WM_CONTEXTMENU message in the message queue.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值