#include
#include "Mouse.h"
CMyApp myApp;
/////////////////////////////////////////////////////////////////////////
// CMyApp member functions
BOOL CMyApp::InitInstance ()
{
m_pMainWnd = new CMainWindow;
m_pMainWnd->ShowWindow (m_nCmdShow);
m_pMainWnd->UpdateWindow ();
return TRUE;
}
/////////////////////////////////////////////////////////////////////////
// CMainWindow message map and member functions
BEGIN_MESSAGE_MAP (CMainWindow, CFrameWnd)
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONUP()
END_MESSAGE_MAP ()
CMainWindow::CMainWindow ()
{
Create (NULL, _T ("Testing Programs"));
}
void CMainWindow::OnLButtonDown(UINT flag,CPoint pt)
{
endpoint=startpoint=pt;
}
void CMainWindow::OnLButtonUp(UINT flag,CPoint pt)
{
CClientDC dc (this);
dc.SetROP2(R2_COPYPEN);
dc.MoveTo(startpoint);
dc.LineTo(endpoint);
}
void CMainWindow::OnMouseMove(UINT flag,CPoint pt)
{
CClientDC dc(this);
if(flag==MK_LBUTTON)
{
dc.SetROP2(R2_NOTXORPEN);
//erase line
dc.MoveTo(startpoint);
dc.LineTo(endpoint);
//draw line
dc.MoveTo(startpoint);
dc.LineTo(pt);
endpoint=pt;
}
}
//save it from as mouse.h in source filein visual studio 6
class CMyApp : public CWinApp
{
public:
virtual BOOL InitInstance ();
};
class CMainWindow : public CFrameWnd
{
private:
CPoint startpoint,endpoint;
public:
CMainWindow ();
protected:
afx_msg void OnLButtonDown (UINT,CPoint);
afx_msg void OnMouseMove(UINT,CPoint);
afx_msg void OnLButtonUp(UINT,CPoint);
DECLARE_MESSAGE_MAP ()
};
No comments:
Post a Comment