Mouse Programming under Windows

11
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.

description

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. - PowerPoint PPT Presentation

Transcript of Mouse Programming under Windows

Page 1: Mouse Programming under Windows

Mouse Programming under WindowsMouse:- 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.

Page 2: Mouse Programming under Windows

Mouse ActionsMouse 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 cursorin approximately the same place Form’s System Information class has two properties that give

thisinformation:– int DoubleClickTime– Size DoubleClickSize

Page 3: Mouse Programming under Windows

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

Page 4: Mouse Programming under Windows

Windows Client-area Messages

Message Handler Sent When

WM_LBUTTONDOWN OnLButtonDown The left mouse button is pressed.

WM_LBUTTONUP OnLButtonUP The left mouse button is released.

WM_LBUTTONDBCLICK OnLButtonDBClick

WM_MBUTTONDOWN OnMButtonDown

WM_MBUTTONUP OnButtonUp

WM_MBUTTONDBCLICK OnMButtonDblClk

WM_RBUTTONDOWN OnRButtonDown

WM_RBUTTONUP OnRButtonUp

WM_RBUTTONDBCLK OnRButtonDbCLK

WM_MOUSEMOVE OnMouseMove The mouse is moved over the window’s client area

Page 5: Mouse Programming under Windows

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);

}

Page 6: Mouse Programming under Windows

DECLARE_MESSAGE_MAP()};BEGIN_MESSAGE_MAP(myframe,CFrameWnd)ON_WM_LBUTTONDOWN()END_MESSAGE_MAP()class myapp:public CWinApp{public:

int InitInstance(){

myframe *p;p=new myframe;p->ShowWindow(3);m_pMainWnd=p;return 1;

}};myapp a;

Page 7: Mouse Programming under Windows

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

Page 8: Mouse Programming under Windows

Windows Non-Client Messages

• WM_NCMOUSEMOVE

• WM_NCLBUTTONDOWN

• WM_NCLBUTTONDBCLK

• WM_NCMBUTTONDOWN

• WM_NCMBUTTONUP

• WM_NCMBUTTONDBCLK

• WM_NCRBUTTONDOWN

• WM_NCRBUTTONUP

• WM_NCRBUTTONDBCLK

Page 9: Mouse Programming under Windows

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){

Page 10: Mouse Programming under Windows

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");

}

};

Page 11: Mouse Programming under Windows

class myapp :public CWinApp{public:

int InitInstance(){

myframe *p;p=new myframe;p->ShowWindow(3);p->test();m_pMainWnd=p;return 1;

}};myapp a;