Download
mouse programming under windows n.
Skip this Video
Loading SlideShow in 5 Seconds..
Mouse Programming under Windows PowerPoint Presentation
Download Presentation
Mouse Programming under Windows

Mouse Programming under Windows

176 Views Download Presentation
Download Presentation

Mouse Programming under Windows

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Mouse Programming under Windows Mouse:- A pointing device with one or more buttons. In computing, a mouse (plural mouses, mice, or mouse devices.) is a pointing device that functions by detecting two-dimensional motion relative to its supporting surface. Physically, a mouse consists of an object held under one of the user's hands, with one or more buttons. It sometimes features other elements, such as "wheels", which allow the user to perform various system-dependent operations, or extra buttons or features can add more control or dimensional input. The mouse's motion typically translates into the motion of a pointer on a display, which allows for fine control of a Graphical User Interface.

  2. Mouse Actions Mouse Actions • Button Down, Button Up • Wheel movement • Moving mouse • Clicking:- Pressing and releasing a mouse button • Dragging:- Moving mouse while a button is pressed down • Double Clicking:- Clicking a button twice in succession Must occur within a set period of time and with mouse cursor in approximately the same place • Form’s System Information class has two properties that give this information: – int DoubleClickTime – Size DoubleClickSize

  3. Mouse Messages • Mouse is the most common input device while working with windows. • As in the case of keyboard, the mouse input also comes in the form of messages. • There are about 20 messages which windows uses to report events that involve the mouse. • We will classify them into four groups:- Group count MessageID Client 10 WM_ Non-Client 10 WM_NC Hit Testing 1 WM_NCHITTEST ACTIVATION 1 WM_MOUSEACTIVATE

  4. Windows Client-area Messages

  5. Write a program which displays a message wherever you click the left mouse button in the client area. #include "afxwin.h" #include "stdafx.h" #include "resource.h" class myframe:public CFrameWnd { public: myframe() { Create(0,"On Single Left Mouse Button Click"); }  void OnLButtonDown(UINT flag,CPoint pt) { CClientDC d(this); d.SetTextColor(RGB(255,0,0)); d.TextOut(pt.x,pt.y,“Hello",5); }

  6. DECLARE_MESSAGE_MAP() }; BEGIN_MESSAGE_MAP(myframe,CFrameWnd) ON_WM_LBUTTONDOWN() END_MESSAGE_MAP() class myapp:publicCWinApp { public: intInitInstance() { myframe *p; p=new myframe; p->ShowWindow(3); m_pMainWnd=p; return 1; } }; myapp a;

  7. Non-Client Messages • This is the group of ten messages which are sent to the window procedure whenever the mouse cursor overlies one of the non-client areas of window. This could be the caption bar, the menu one of the border, or even the scroll bar. All the ten non-client messages closely duplicate the corresponding client area messages

  8. Windows Non-Client Messages • WM_NCMOUSEMOVE • WM_NCLBUTTONDOWN • WM_NCLBUTTONDBCLK • WM_NCMBUTTONDOWN • WM_NCMBUTTONUP • WM_NCMBUTTONDBCLK • WM_NCRBUTTONDOWN • WM_NCRBUTTONUP • WM_NCRBUTTONDBCLK

  9. Write a program to find out whether a mouse is a attached or not; and if it is attached, how many buttons are present on it. #include"afxwin.h" #include"resource.h" #include"stdafx.h" class myframe: public CFrameWnd { public: myframe() { Create(0,"Mouse present/absent"); } void test() { int value, num; char str[5]; value=::GetSystemMetrics(SM_MOUSEPRESENT); if(value==1) {

  10. MessageBox("mouse is present"); num=::GetSystemMetrics(SM_CMOUSEBUTTONS); sprintf(str,"%d",num); MessageBox(str,"number of mouse button"); } else MessageBox("mouse is not present","Attention"); } };

  11. class myapp :public CWinApp { public: intInitInstance() { myframe *p; p=new myframe; p->ShowWindow(3); p->test(); m_pMainWnd=p; return 1; } }; myapp a;