#include <afxwin.h>
class CSimpleApp : public CWinApp
{
public:
BOOL InitInstance();
};
class CMainFrame : public CFrameWnd
{
public:
CMainFrame();
afx_msg void OnLButtonDown( UINT, CPoint );
afx_msg void OnLButtonUp( UINT, CPoint );
afx_msg void OnLButtonDblClk( UINT, CPoint );
afx_msg void OnRButtonDown( UINT, CPoint );
afx_msg void OnRButtonUp( UINT, CPoint );
afx_msg void OnRButtonDblClk( UINT, CPoint );
afx_msg void OnNcLButtonDown( UINT, CPoint );
afx_msg void CMainFrame::textoutput(CString,int,int);
int tpy;
DECLARE_MESSAGE_MAP()
};
BOOL CSimpleApp::InitInstance(){
m_pMainWnd = new CMainFrame();
m_pMainWnd->ShowWindow(m_nCmdShow);
return TRUE;
}
CMainFrame::CMainFrame()
{
CRect rect(12,12,500,400);
Create(NULL, "MFC Mouse Demo",WS_CAPTION| WS_SYSMENU| WS_MAXIMIZEBOX| WS_MINIMIZEBOX);//,rect);
tpy=0;
}
BEGIN_MESSAGE_MAP(CMainFrame,CFrameWnd)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_LBUTTONDBLCLK()
ON_WM_RBUTTONDOWN()
ON_WM_RBUTTONUP()
ON_WM_RBUTTONDBLCLK()
ON_WM_NCLBUTTONDOWN()
ON_WM_NCRBUTTONDOWN()
END_MESSAGE_MAP()
CSimpleApp MFCApp1;
//deals with left mouse down and ctrl and shift keys
afx_msg void CMainFrame::OnLButtonDown(UINT flags,CPoint pt)
{
CClientDC dc(this);
CString action;
action="Left Mouse button down";
if (flags & MK_CONTROL)
action=action+" with control key ";
if (flags & MK_SHIFT)
action=action+" with shift key ";
textoutput(action,pt.x,pt.y);
}
//deals with left mouse up
afx_msg void CMainFrame::OnLButtonUp(UINT flags,CPoint pt)
{
CClientDC dc(this);
CString action;
action="Left Mouse Button Up ";
textoutput(action,pt.x,pt.y);
}
//deals with left mouse double click
afx_msg void CMainFrame::OnLButtonDblClk(UINT flags,CPoint pt)
{
CClientDC dc(this);
CString action;
action="Left Mouse Double click ";
textoutput(action,pt.x,pt.y);
}
//deals with right mouse down
afx_msg void CMainFrame::OnRButtonDown(UINT flags,CPoint pt)
{
CClientDC dc(this);
CString action;
action="Right Mouse Down ";
textoutput(action,pt.x,pt.y);
}
//deals with right mouse up
afx_msg void CMainFrame::OnRButtonUp(UINT flags,CPoint pt)
{
CClientDC dc(this);
CString action;
action="Right Mouse Up ";
textoutput(action,pt.x,pt.y);
}
//deals with right button double click
afx_msg void CMainFrame::OnRButtonDblClk(UINT flags,CPoint pt)
{
CClientDC dc(this);
CString action;
action="Right Mouse Double click ";
textoutput(action,pt.x,pt.y);
}
//deals with client area clicks
afx_msg void CMainFrame::OnNcLButtonDown(UINT flags,CPoint pt)
{
CClientDC dc(this);
CString action;
switch(flags)
{
case HTCLOSE:
action="Close ";
PostQuitMessage(0 );
break;
case HTCAPTION:
action="Title Bar ";
break;
case HTREDUCE:
action="Minimise Button ";
break;
case HTZOOM:
action="Maximise Button ";
break;
case HTSYSMENU:
action="System Menu ";
break;
}
textoutput(action,pt.x,pt.y);
}
afx_msg void CMainFrame::textoutput(CString action, int x,int y)
{
CClientDC dc(this);
CString locstr;
locstr.Format("%d", x);
action=action+" x="+locstr;
locstr.Format("%d", y);
action=action+" y="+locstr;
CRect clientRect;
ASSERT( AfxGetMainWnd()!=NULL );
AfxGetMainWnd()->GetClientRect(&clientRect);
int heightclient;
heightclient=clientRect.bottom-clientRect.left;
if (tpy>=heightclient-15)
{
AfxGetMainWnd()->ScrollWindow(0, -15, NULL, &clientRect);
AfxGetMainWnd()->UpdateWindow();
dc.TextOut(0,tpy-25,action);
}
else
{
dc.TextOut(0,tpy,action);
tpy=tpy+15;
}
}