#include #include Capture::Capture(void) : mhWnd(0), mIsInCapture(FALSE), mHasCapture(FALSE) { reset(); } Capture::~Capture() { } void Capture::leftButtonDown(LPARAM lParam) { HDC hDC; if(!mhWnd)return; mIsInCapture=TRUE; mHasCapture=FALSE; hDC=::GetDC(mhWnd); ::DrawFocusRect(hDC,(RECT FAR *)&mZoomRect); ::ReleaseDC(mhWnd,hDC); ::memset((char*)&mZoomRect,0,sizeof(RECT)); ::SetCapture(mhWnd); ::GetClientRect(mhWnd,(RECT FAR *)&mZoomRect); ::ClientToScreen(mhWnd,(POINT FAR *)&mZoomRect); ::ClientToScreen(mhWnd,(POINT FAR *)&mZoomRect+1); ::ClipCursor((RECT FAR *)&mZoomRect); mZoomRect.top=mZoomRect.bottom=HIWORD(lParam); mZoomRect.left=mZoomRect.right=LOWORD(lParam); } void Capture::mouseMove(LPARAM lParam) { HDC hDC; if(!mIsInCapture)return; hDC=::GetDC(mhWnd); ::DrawFocusRect(hDC,(RECT FAR *)&mZoomRect); mZoomRect.bottom=HIWORD(lParam); mZoomRect.right=LOWORD(lParam); ::DrawFocusRect(hDC,(RECT FAR *)&mZoomRect); ::ReleaseDC(mhWnd,hDC); } void Capture::leftButtonUp(void) { HDC hDC; int width; int height; int temp; if(!mIsInCapture)return; mIsInCapture=FALSE; ::ClipCursor(NULL); ::ReleaseCapture(); hDC=::GetDC(mhWnd); ::DrawFocusRect(hDC,(RECT FAR *)&mZoomRect); if(mZoomRect.left>mZoomRect.right) { temp=mZoomRect.left; mZoomRect.left=mZoomRect.right; mZoomRect.right=temp; } if(mZoomRect.top>mZoomRect.bottom) { temp=mZoomRect.top; mZoomRect.top=mZoomRect.bottom; mZoomRect.bottom=temp; } width=mZoomRect.right-mZoomRect.left; height=mZoomRect.bottom-mZoomRect.top; ::DrawFocusRect(hDC,(RECT FAR *)&mZoomRect); ::ReleaseDC(mhWnd,hDC); if(width>7 && height>7) { mClipRect.right=mZoomRect.right; mClipRect.left=mZoomRect.left; mClipRect.top=mZoomRect.top; mClipRect.bottom=mZoomRect.bottom; mHasCapture=TRUE; } } WORD Capture::boundedRect(RECT &boundingRect) { HDC hDC; if(!mHasCapture)return FALSE; boundingRect.right=mClipRect.right; boundingRect.left=mClipRect.left; boundingRect.top=mClipRect.top; boundingRect.bottom=mClipRect.bottom; hDC=::GetDC(mhWnd); ::DrawFocusRect(hDC,(RECT FAR *)&mZoomRect); ::ReleaseDC(mhWnd,hDC); ::memset((char*)&mZoomRect,0,sizeof(RECT)); return TRUE; } void Capture::reset(void) { HDC hDC(::GetDC(mhWnd)); if(mHasCapture) { ::DrawFocusRect(hDC,(RECT FAR *)&mZoomRect); mHasCapture=FALSE; } ::memset((char *)&mZoomRect,0,sizeof(RECT)); ::ReleaseDC(mhWnd,hDC); }