home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Troubleshooting Netware Systems
/
CSTRIAL0196.BIN
/
attach
/
msj
/
v10n08
/
mfcpart3.exe
/
MOUSECAP.CPP
next >
Wrap
C/C++ Source or Header
|
1995-08-01
|
3KB
|
105 lines
//***************************************************************************
//
// MouseCap demonstrates mouse capturing.
//
//***************************************************************************
#include <afxwin.h>
#include "mousecap.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_LBUTTONUP ()
ON_WM_MOUSEMOVE ()
ON_WM_NCLBUTTONDOWN ()
END_MESSAGE_MAP ()
CMainWindow::CMainWindow ()
{
m_bTracking = FALSE;
m_bCaptureEnabled = TRUE;
Create (NULL, "Mouse Capture Demo (Capture Enabled)");
::SetClassLong (m_hWnd, GCL_HCURSOR,
(LONG) myApp.LoadStandardCursor (IDC_CROSS));
}
void CMainWindow::OnLButtonDown (UINT nFlags, CPoint point)
{
m_pointFrom = point;
m_pointTo = point;
m_bTracking = TRUE;
if (m_bCaptureEnabled)
SetCapture ();
}
void CMainWindow::OnLButtonUp (UINT nFlags, CPoint point)
{
if (m_bTracking) {
m_bTracking = FALSE;
if (GetCapture () == this)
ReleaseCapture ();
CClientDC dc (this);
dc.SetROP2 (R2_XORPEN);
dc.SelectStockObject (WHITE_PEN);
dc.MoveTo (m_pointFrom);
dc.LineTo (m_pointTo);
dc.SetROP2 (R2_COPYPEN);
CPen pen (PS_SOLID, 16, RGB (255, 0, 0));
dc.SelectObject (&pen);
dc.MoveTo (m_pointFrom);
dc.LineTo (point);
}
}
void CMainWindow::OnMouseMove (UINT nFlags, CPoint point)
{
if (m_bTracking) {
CClientDC dc (this);
dc.SetROP2 (R2_XORPEN);
dc.SelectStockObject (WHITE_PEN);
dc.MoveTo (m_pointFrom);
dc.LineTo (m_pointTo);
dc.MoveTo (m_pointFrom);
dc.LineTo (point);
m_pointTo = point;
}
}
void CMainWindow::OnNcLButtonDown (UINT nHitTest, CPoint point)
{
if (nHitTest == HTCAPTION) {
m_bCaptureEnabled = m_bCaptureEnabled ? FALSE : TRUE;
SetWindowText (m_bCaptureEnabled ?
"Mouse Capture Demo (Capture Enabled)" :
"Mouse Capture Demo (Capture Disabled)");
}
CFrameWnd::OnNcLButtonDown (nHitTest, point);
}