week 3 c for win lecture :. mouse message keyboard message

15
Week 3 C For Win Lecture :

Upload: chester-wilcox

Post on 23-Dec-2015

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Week 3 C For Win Lecture :.  Mouse Message  Keyboard Message

Week 3 C For Win Lecture :

Page 2: Week 3 C For Win Lecture :.  Mouse Message  Keyboard Message

Mouse Message Keyboard Message

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

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

Page 4: Week 3 C For Win Lecture :.  Mouse Message  Keyboard Message

Client-Area Mouse Messages

Page 5: Week 3 C For Win Lecture :.  Mouse Message  Keyboard Message

Nonclient-Area Mouse Messages

Page 6: Week 3 C For Win Lecture :.  Mouse Message  Keyboard Message

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

Page 7: Week 3 C For Win Lecture :.  Mouse Message  Keyboard Message

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

Page 8: Week 3 C For Win Lecture :.  Mouse Message  Keyboard Message

Example :

Page 9: Week 3 C For Win Lecture :.  Mouse Message  Keyboard Message

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

Page 10: Week 3 C For Win Lecture :.  Mouse Message  Keyboard Message

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

Page 11: Week 3 C For Win Lecture :.  Mouse Message  Keyboard Message

Example : BOOL m_bTracking ; CPoint m_ptTo; CPoint m_ptFrom;

OnInitDialog : m_bTracking = FALSE;

Page 12: Week 3 C For Win Lecture :.  Mouse Message  Keyboard Message

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

Page 13: Week 3 C For Win Lecture :.  Mouse Message  Keyboard Message

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 pressednRepCnt : 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.

Page 14: Week 3 C For Win Lecture :.  Mouse Message  Keyboard Message

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 somethingOnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)

if (nChar == ‘{ký tự}') {do yourself } (Ex: ‘A’,’B’,’1’,…)

if (nChar == {Mã ký tự ảo}) {do yourseft }

Page 15: Week 3 C For Win Lecture :.  Mouse Message  Keyboard Message

Example: int NumofLetter[30]; OnInitDialog :

for(int i = 0; i < 30 ; i++)NumofLetter[i] = 0;