Mouse Programming
Handler functions are mainly used for handling messages .Messages are of two types Client and non-client messages .When double clciking ,draging from windows title bar Non Client message is generated.
Client message
---------------
Message Handler Sent When
-------------------------------------------------------------
WM_LBUTTONDOWN OnLButtonDown Left button is pressed
WM_LBUTTONUP OnLButtonUp Left button is released
WM_LBUTTONDBCLCICK OnLButtonDblClk Left button double clicked
WM_MBUTTONDOWN OnMButtonDown Middle button is pressed
WM_MBUTTONUP OnMButtonUp Middle button is released
WM_MBUTTONDBCLICK OnMButtonDblClk Middle button double clicked
WM_RBUTTONDOWN OnRButtonDown Right button is pressed
WM_RBUTTONUP OnRButtonUp Right button is released
WM_RBUTTONDBCLCICK OnRButtonDblClk Right button double clicked
WM_MUSEMOVE OnMouseMove Mouse is Moved Over Window's client area
Non-Client message
---------------
Message Handler Sent When
-------------------------------------------------------------
WM_NCLBUTTONDOWN OnNcLButtonDown Left button is pressed
WM_NCLBUTTONUP OnNcLButtonUp Left button is released
WM_NCLBUTTONDBCLCICK OnNcLButtonDblClk Left button double clicked
WM_NCMBUTTONDOWN OnNcMButtonDown Middle button is pressed
WM_NCMBUTTONUP OnNcMButtonUp Middle button is released
WM_NCMBUTTONDBCLICK OnNcMButtonDblClk Middle button double clicked
WM_NCRBUTTONDOWN OnNcRButtonDown Right button is pressed
WM_NCRBUTTONUP OnNcRButtonUp Right button is released
WM_NCRBUTTONDBCLCICK OnNcRButtonDblClk Right button double clicked
WM_NCMUSEMOVE OnNcMouseMove Mouse is Moved Over Window's client area
Code to check wether mouse is present or not ,if present display the count of buttons.
#include
class mousestatus:public CFrameWnd
{
public:
mousestatus()
{
Create (0,"Mouse status");
}
void checkmouse()
{
int status,count;
char message;
status=::GetSystemMetric(SM_MOUSEPRESENT);
if (status==1)
{
MessageBox("Mouse present","User");
Count=::GetSystemMetric(SM_CMMOUSEBUTTONS);
Sprintf(Message,"%d",Count);
MessageBox(message,"Number of buttons");
}
else
{
MessageBox("Mouse absent","User");
}
}//end of checkmouse
};
class MS : public CWinApp
{
public:
int InitInstance()
{
mousestatus *ptrms =new mousestatus ( );
ptrms -> ShowWindow(1);
ptrms -> checkmouse();
m_pMainWnd =ptrms;
return(1);
}
};
MS myobject;
Program to swap mouse buttons
#include
class Swapmouse:public CFrameWnd
{
public:
Swapmouse()
{
Create (0,"Swapping Mouse button");
}
void swap()
{
int status;
status=::GetSystemMetric(SM_SWAPBUTTON);
if (status==1)
{
MessageBox("Mouse Buttons are swapped","User");
}
else
{
MessageBox("Mouse Not Swapped","User");
}
}//end of checkmouse
};
class Swpms : public CWinApp
{
public:
int InitInstance()
{
Swpms *ptrms =new swpms ( );
ptrms -> ShowWindow(1);
ptrms -> Swap();
m_pMainWnd =ptrswpms;
return(1);
}
};
Swpms myobject;
File Programming
-----------------
Storing of application data into computer drives is called Serialisation and viceversa is known as deserialisation.
For serialisation there are two MFC class CArchive and CFile
CArchive is given in Serialize named function as argument .In CArchive class there are two functions for read and write ; IsLoading and IsStoring.
Eg : Void CFileDemo :: Serialize ( CArchive &obj)
For object Serialization what all steps are followed
----------------------------------------------------
Macro statements like DECLARE_SERIAL and IMPLEMENT_SERAIL are to be defined in class declaration and class implementation.In DECLARE_SERAIL macro one argument should be passed ;the agrument is the name of the class for which serialization should be attained.
In IMPLEMENT_SERAIL macro three arguments should be passed ,first one is same we used in DECLARE_SERAIL macro second one is super base class of our class and third one is version number of our file.
//Class declaration
class CFileClass::public CObject
{
DECLARE_SERIAL(CFileclass)
public :
Virtual void Serialize (CArchive obj);
CFileClass();
virtual `CFileClass();
};
// class implementation
#include "stdafx.h"
#include "FileClass.h"
#ifdef_DEBUG
#undef THIS_FILE
static char THIS_FILE[]=FILE_;
#define new DEBUG_NEW
#end if;
IMPLEMENT_SERAIL(CFileClass,CObject,1)
// Construction
CFileClass:: CFileClass()
{
//add code
}
// distruction
CFileClass::`CFileClass()
{
//add code
}
Handler functions are mainly used for handling messages .Messages are of two types Client and non-client messages .When double clciking ,draging from windows title bar Non Client message is generated.
Client message
---------------
Message Handler Sent When
-------------------------------------------------------------
WM_LBUTTONDOWN OnLButtonDown Left button is pressed
WM_LBUTTONUP OnLButtonUp Left button is released
WM_LBUTTONDBCLCICK OnLButtonDblClk Left button double clicked
WM_MBUTTONDOWN OnMButtonDown Middle button is pressed
WM_MBUTTONUP OnMButtonUp Middle button is released
WM_MBUTTONDBCLICK OnMButtonDblClk Middle button double clicked
WM_RBUTTONDOWN OnRButtonDown Right button is pressed
WM_RBUTTONUP OnRButtonUp Right button is released
WM_RBUTTONDBCLCICK OnRButtonDblClk Right button double clicked
WM_MUSEMOVE OnMouseMove Mouse is Moved Over Window's client area
Non-Client message
---------------
Message Handler Sent When
-------------------------------------------------------------
WM_NCLBUTTONDOWN OnNcLButtonDown Left button is pressed
WM_NCLBUTTONUP OnNcLButtonUp Left button is released
WM_NCLBUTTONDBCLCICK OnNcLButtonDblClk Left button double clicked
WM_NCMBUTTONDOWN OnNcMButtonDown Middle button is pressed
WM_NCMBUTTONUP OnNcMButtonUp Middle button is released
WM_NCMBUTTONDBCLICK OnNcMButtonDblClk Middle button double clicked
WM_NCRBUTTONDOWN OnNcRButtonDown Right button is pressed
WM_NCRBUTTONUP OnNcRButtonUp Right button is released
WM_NCRBUTTONDBCLCICK OnNcRButtonDblClk Right button double clicked
WM_NCMUSEMOVE OnNcMouseMove Mouse is Moved Over Window's client area
Code to check wether mouse is present or not ,if present display the count of buttons.
#include
class mousestatus:public CFrameWnd
{
public:
mousestatus()
{
Create (0,"Mouse status");
}
void checkmouse()
{
int status,count;
char message;
status=::GetSystemMetric(SM_MOUSEPRESENT);
if (status==1)
{
MessageBox("Mouse present","User");
Count=::GetSystemMetric(SM_CMMOUSEBUTTONS);
Sprintf(Message,"%d",Count);
MessageBox(message,"Number of buttons");
}
else
{
MessageBox("Mouse absent","User");
}
}//end of checkmouse
};
class MS : public CWinApp
{
public:
int InitInstance()
{
mousestatus *ptrms =new mousestatus ( );
ptrms -> ShowWindow(1);
ptrms -> checkmouse();
m_pMainWnd =ptrms;
return(1);
}
};
MS myobject;
Program to swap mouse buttons
#include
class Swapmouse:public CFrameWnd
{
public:
Swapmouse()
{
Create (0,"Swapping Mouse button");
}
void swap()
{
int status;
status=::GetSystemMetric(SM_SWAPBUTTON);
if (status==1)
{
MessageBox("Mouse Buttons are swapped","User");
}
else
{
MessageBox("Mouse Not Swapped","User");
}
}//end of checkmouse
};
class Swpms : public CWinApp
{
public:
int InitInstance()
{
Swpms *ptrms =new swpms ( );
ptrms -> ShowWindow(1);
ptrms -> Swap();
m_pMainWnd =ptrswpms;
return(1);
}
};
Swpms myobject;
File Programming
-----------------
Storing of application data into computer drives is called Serialisation and viceversa is known as deserialisation.
For serialisation there are two MFC class CArchive and CFile
CArchive is given in Serialize named function as argument .In CArchive class there are two functions for read and write ; IsLoading and IsStoring.
Eg : Void CFileDemo :: Serialize ( CArchive &obj)
For object Serialization what all steps are followed
----------------------------------------------------
Macro statements like DECLARE_SERIAL and IMPLEMENT_SERAIL are to be defined in class declaration and class implementation.In DECLARE_SERAIL macro one argument should be passed ;the agrument is the name of the class for which serialization should be attained.
In IMPLEMENT_SERAIL macro three arguments should be passed ,first one is same we used in DECLARE_SERAIL macro second one is super base class of our class and third one is version number of our file.
//Class declaration
class CFileClass::public CObject
{
DECLARE_SERIAL(CFileclass)
public :
Virtual void Serialize (CArchive obj);
CFileClass();
virtual `CFileClass();
};
// class implementation
#include "stdafx.h"
#include "FileClass.h"
#ifdef_DEBUG
#undef THIS_FILE
static char THIS_FILE[]=FILE_;
#define new DEBUG_NEW
#end if;
IMPLEMENT_SERAIL(CFileClass,CObject,1)
// Construction
CFileClass:: CFileClass()
{
//add code
}
// distruction
CFileClass::`CFileClass()
{
//add code
}
No comments:
Post a Comment