Presentation is loading. Please wait.

Presentation is loading. Please wait.

Week 3 C For Win Lecture :.  Mouse Message  Keyboard Message.

Similar presentations


Presentation on theme: "Week 3 C For Win Lecture :.  Mouse Message  Keyboard Message."— Presentation transcript:

1 Week 3 C For Win Lecture :

2  Mouse Message  Keyboard Message

3  Windows uses a number of different messages involving the mouse.  These message fall into two categories :  Client-area mouse messages  Nonclient-area mouse messages  Mouse Events will be learned :  The press and release of a mouse button  The double click of a mouse button  The movement of a mouse

4  Client-Area Mouse Messages

5  Nonclient-Area Mouse Messages

6  The press and release of a mouse button:  Mouse-Down Messages: User locate a position and press a left or right or middle mouse button. The message will be sent  Mouse-Up Messages: After pressing a mouse button, user release it. A mouse-up message is sent Example : WM_LBUTTONDOWN  WM_LBUTTONUP WM_RBUTTONDOWN  WM_RBUTTONUP

7  The syntax of mouse-down(up)messages is :  afx_msg void OnxButtonDown(UINT nFlags, CPoint point);  afx_msg void OnxButtonUp(UINT nFlags, CPoint point); Meanings :  x : replaced with L(left), R(Right), or M(Middle)  point : identify the location of the cursor  nFlags : state of mouse button

8  Example :

9  The double click of a mouse button  When two clicks of the same button occur within a very short period of time.  The second button-down message will be replaced by a WM_xBUTTONDBLCLK message the window's WNDCLASS includes the class style CS_DBLCLKS

10  The movement of a mouse:  After pressing one of mouse buttons, depending on the requirement, the user may not need to immediately release button. User can drag and move mouse to a new position. At that time the message WM_MOUSEMOVE is sent continuously  nFlags Indicates whether various virtual keys are down

11  Example : BOOL m_bTracking ; CPoint m_ptTo; CPoint m_ptFrom;  OnInitDialog : m_bTracking = FALSE;

12  Each key in our keyboard has a code that OS can regconize

13  The Key-Down Effect :  When user press a key, the message WM_KEYDOWN is sent  The syntax : void OnKeyDown(UINT nChar, UINT nRepCnt,UINT nFlags ); nChar : specify the virtual code of the key that was pressed nRepCnt : specify the number of times counted repeatedly as the key was held down. nFlags : specify the scan code, extended-key flag, context code, previous key-state flag, and transition-state flag.

14  If user need to use keyboard message. Do two steps :  Step 1: Add details to function PreTranslateMessage  Step 2: Check nChar in OnKeyDown function to do something OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) if (nChar == ‘{ký t ự }') {do yourself }(Ex: ‘A’,’B’,’1’,…) if (nChar == {Mã ký t ự ả o}) {do yourseft }

15  Example:  int NumofLetter[30];  OnInitDialog : for(int i = 0; i < 30 ; i++) NumofLetter[i] = 0;


Download ppt "Week 3 C For Win Lecture :.  Mouse Message  Keyboard Message."

Similar presentations


Ads by Google