📄 vscapview.cpp
字号:
if ((a.left==b.left) && (a.right==b.right) && (a.top==b.top) && (a.bottom==b.bottom))
return TRUE;
else return FALSE;
}
//****************************************************************************
//
// Function: FrameWindow()
//
// Purpose: Highlight the window frame
//
//
//***************************************************************************
RECT FrameWindow(HWND hWnd)
{
HDC hdc;
RECT rectWin;
RECT rectFrame;
rectWin.left=0;
rectWin.top=0;
rectWin.right=maxxScreen-1;
rectWin.bottom=maxyScreen-1;
#define DINV 3
if (!IsWindow(hWnd))
return rectWin;
hdc = GetWindowDC(hWnd);
GetWindowRect(hWnd, &rectWin);
rectFrame=rectWin;
OffsetRect(&rectFrame, -rectFrame.left, -rectFrame.top);
if (!IsRectEmpty(&rectFrame))
{
HBRUSH newbrush = (HBRUSH) CreateHatchBrush(HS_BDIAGONAL, RGB(0,0,100));
HBRUSH oldbrush = (HBRUSH) SelectObject(hdc,newbrush);
PatBlt(hdc, rcClip.left, rcClip.top, rcClip.right-rcClip.left, DINV, PATINVERT);
PatBlt(hdc, rcClip.left, rcClip.bottom-DINV, DINV, -(rcClip.bottom-rcClip.top-2*DINV), PATINVERT);
PatBlt(hdc, rcClip.right-DINV, rcClip.top+DINV, DINV, rcClip.bottom-rcClip.top-2*DINV, PATINVERT);
PatBlt(hdc, rcClip.right, rcClip.bottom-DINV, -(rcClip.right-rcClip.left), DINV, PATINVERT);
SelectObject(hdc,oldbrush);
DeleteObject(newbrush);
}
ReleaseDC(hWnd, hdc);
return rectWin;
}
//***************************************************************************
//
// DrawSelect
//
// Draws the selected clip rectangle with its dimensions on the DC
//
//***************************************************************************
void SaveBitmapCopy(HDC hdc,HDC hdcbits, int x, int y, int sx, int sy) {
if (savedBitmap) DeleteObject(savedBitmap);
savedBitmap = NULL;
savedBitmap = (HBITMAP) CreateCompatibleBitmap(hdc,sx, sy);
HBITMAP oldbitmap = (HBITMAP) SelectObject(hdcbits,savedBitmap);
BitBlt(hdcbits, 0, 0, sx, sy, hdc, x, y, SRCCOPY);
SelectObject(hdcbits,oldbitmap);
}
void RestoreBitmapCopy(HDC hdc,HDC hdcbits, int x, int y, int sx, int sy) {
if (savedBitmap) {
HBITMAP oldbitmap = (HBITMAP) SelectObject(hdcbits,savedBitmap);
BitBlt(hdc, x, y, sx, sy, hdcbits, 0, 0, SRCCOPY);
SelectObject(hdcbits,oldbitmap);
if (savedBitmap) DeleteObject(savedBitmap);
savedBitmap = NULL;
}
}
void DrawSelect(HDC hdc, BOOL fDraw, LPRECT lprClip)
{
DWORD dw;
int x, y, dx, dy;
HDC hdcBits;
RECT rectDraw;
SIZE sExtent;
rectDraw = *lprClip;
if (!IsRectEmpty(&rectDraw))
{
// If a rectangular clip region has been selected, draw it
HBRUSH newbrush = (HBRUSH) CreateHatchBrush(HS_BDIAGONAL, RGB(0,0,100));
HBRUSH oldbrush = (HBRUSH) SelectObject(hdc,newbrush);
//PatBlt SRCINVERT regardless fDraw is TRUE or FALSE
PatBlt(hdc, rectDraw.left, rectDraw.top, rectDraw.right-rectDraw.left, DINV, PATINVERT);
PatBlt(hdc, rectDraw.left, rectDraw.bottom-DINV, DINV, -(rectDraw.bottom-rectDraw.top-2*DINV), PATINVERT);
PatBlt(hdc, rectDraw.right-DINV, rectDraw.top+DINV, DINV, rectDraw.bottom-rectDraw.top-2*DINV, PATINVERT);
PatBlt(hdc, rectDraw.right, rectDraw.bottom-DINV, -(rectDraw.right-rectDraw.left), DINV, PATINVERT);
SelectObject(hdc,oldbrush);
DeleteObject(newbrush);
hdcBits = CreateCompatibleDC(hdc);
#if 0
// ANSI_VAR_FONT does not support DBCS text
HFONT newfont = (HFONT) GetStockObject(ANSI_VAR_FONT);
#else
HFONT newfont = (HFONT) GetStockObject(DEFAULT_GUI_FONT);
#endif
HFONT oldfont = (HFONT) SelectObject(hdc, newfont);
//HFONT oldfont = (HFONT) SelectObject(hdcBits, newfont);
CString csRectCaption;
csRectCaption.Format(ID_RECT_CAPTION_FORMAT,
rectDraw.left, rectDraw.top,
rectDraw.right - rectDraw.left+1, rectDraw.bottom - rectDraw.top+1);
dw = GetTextExtentPoint(hdc, csRectCaption, csRectCaption.GetLength(), &sExtent);
//dw = GetTextExtentPoint(hdcBits, sz, len, &sExtent);
dx = sExtent.cx;
dy = sExtent.cy;
x= rectDraw.left +10;
if (rectDraw.top < (dy + DINV + 2))
y= rectDraw.bottom + DINV + 2;
else
y= rectDraw.top - dy - DINV - 2;
if (fDraw) {
//Save Original Picture
SaveBitmapCopy(hdc,hdcBits, x-4, y-4, dx+8, dy+8);
//Text
COLORREF oldtextcolor = SetTextColor(hdc,RGB(0,0,0));
COLORREF oldbkcolor = SetBkColor(hdc,RGB(255,255,255));
SetBkMode(hdc,TRANSPARENT);
//Rectangle(hdc,x-1,y-1,x+dx, y+dy);
RoundRect(hdc,x-4,y-4,x+dx+4, y+dy+4,10,10);
SetBkMode(hdc,OPAQUE);
ExtTextOut(hdc, x, y, 0, NULL, csRectCaption, csRectCaption.GetLength(), NULL);
SetBkColor(hdc,oldbkcolor);
SetTextColor(hdc,oldtextcolor);
SelectObject(hdc, oldfont);
}
else
RestoreBitmapCopy(hdc,hdcBits, x-4, y-4, dx+8, dy+8);
//Icon
if ((rectDraw.right-rectDraw.left-10 > 35) && (rectDraw.bottom-rectDraw.top-10 > dy + 40)) {
HBITMAP hbv = LoadBitmap( AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP1));
HBITMAP old_bitmap = (HBITMAP) SelectObject(hdcBits, hbv);
BitBlt(hdc, rectDraw.left+10, rectDraw.bottom-42, 30, 32,hdcBits, 0,0, SRCINVERT);
SelectObject(hdcBits,old_bitmap);
DeleteObject(hbv);
}
DeleteDC(hdcBits);
}
}
void DrawFlashingRect(BOOL bDraw , int mode) {
if (mode == 1) {
pFrame->PaintInvertedBorder(RGB(0,255,80));
}
else {
if (bDraw)
pFrame->PaintBorder(RGB(255,255,180));
else
pFrame->PaintBorder(RGB(0,255,80));
}
}
//**********************************************************************
//
// MouseCaptureWndProc()
//
//
//*********************************************************************
long WINAPI MouseCaptureWndProc(HWND hWnd, UINT wMessage, WPARAM wParam, LPARAM lParam)
{
switch (wMessage)
{
case WM_MOUSEMOVE:
{
if (MouseCaptureMode==0) { //Fixed Region
POINT pt;
GetCursorPos(&pt);
rcClip.left = pt.x+rcOffset.left; // Update rect with new mouse info
rcClip.top = pt.y+rcOffset.top;
rcClip.right = pt.x+rcOffset.right;
rcClip.bottom = pt.y+rcOffset.bottom;
if (rcClip.left<0) {
rcClip.left=0;
rcClip.right=((rc.right)-(rc.left));
}
if (rcClip.top<0) {
rcClip.top=0;
rcClip.bottom=((rc.bottom)-(rc.top));
}
if (rcClip.right>maxxScreen-1) {
rcClip.right=maxxScreen-1;
rcClip.left=maxxScreen-1-((rc.right)-(rc.left));
}
if (rcClip.bottom>maxyScreen-1) {
rcClip.bottom=maxyScreen-1;
rcClip.top=maxyScreen-1-((rc.bottom)-(rc.top));
}
if (!isRectEqual(old_rcClip,rcClip)) {
HDC hScreenDC = GetDC(hWnd);
DrawSelect(hScreenDC, FALSE, &old_rcClip); // erase old rubber-band
DrawSelect(hScreenDC, TRUE, &rcClip); // new rubber-band
ReleaseDC(hWnd,hScreenDC);
}// if old
old_rcClip=rcClip;
}
else if (MouseCaptureMode==1) { //Variable Region
if (bCapturing)
{
POINT pt;
GetCursorPos(&pt);
HDC hScreenDC = GetDC(hWnd);
DrawSelect(hScreenDC, FALSE, &rcClip); // erase old rubber-band
rcClip.left = ptOrigin.x;
rcClip.top = ptOrigin.y;
rcClip.right = pt.x;
rcClip.bottom = pt.y;
NormalizeRect(&rcClip);
DrawSelect(hScreenDC, TRUE, &rcClip); // new rubber-band
//TextOut(hScreenDC,pt.x,pt.y,"Lolo",4);
ReleaseDC(hWnd,hScreenDC);
}
}
return DefWindowProc(hWnd, wMessage, wParam, lParam);
}
case WM_LBUTTONUP:
{
if (MouseCaptureMode==0) {
//erase final
HDC hScreenDC = GetDC(hWnd);
DrawSelect(hScreenDC, FALSE, &old_rcClip);
old_rcClip=rcClip;
ReleaseDC(hWnd,hScreenDC);
}
else if (MouseCaptureMode==1) {
NormalizeRect(&rcClip);
old_rcClip=rcClip;
bCapturing = FALSE;
}
ShowWindow(hWnd,SW_HIDE);
if (!IsRectEmpty(&old_rcClip)) {
NormalizeRect(&old_rcClip);
CopyRect(&rcUse, &old_rcClip);
if (DefineMode==0)
PostMessage (hWndGlobal,WM_USER_RECORDSTART,0,(LPARAM) 0);
else
PostMessage (hWnd_FixedRegion,WM_USER_REGIONUPDATE,0,(LPARAM) 0);
}
return DefWindowProc(hWnd, wMessage, wParam, lParam);
}
case WM_LBUTTONDOWN:
{
// User pressed left button, initialize selection
// Set origin to current mouse position (in window coords)
if (MouseCaptureMode==1) {
POINT pt;
GetCursorPos(&pt);
ptOrigin=pt;
rcClip.left = rcClip.right = pt.x;
rcClip.top = rcClip.bottom = pt.y;
NormalizeRect(&rcClip); // Make sure it is a normal rect
HDC hScreenDC = GetDC(hWnd);
DrawSelect(hScreenDC, TRUE, &rcClip); // Draw the rubber-band box
ReleaseDC(hWnd,hScreenDC);
bCapturing = TRUE;
}
return DefWindowProc(hWnd, wMessage, wParam, lParam);
}
case WM_RBUTTONDOWN:
{
if (MouseCaptureMode==0) { //Cancel the operation
//erase final
HDC hScreenDC = GetDC(hWnd);
DrawSelect(hScreenDC, FALSE, &old_rcClip);
ReleaseDC(hWnd,hScreenDC);
//Cancel the operation
ShowWindow(hWnd,SW_HIDE);
//ver 1.2
AllowNewRecordStartKey = TRUE;
}
return DefWindowProc(hWnd, wMessage, wParam, lParam);
}
case WM_KEYDOWN:
{
int nVirtKey = (int) wParam; // virtual-key code
int lKeyData = lParam; // key data
//ver 1.2
if (nVirtKey==(int) keyRecordCancel) { //Cancel the operation
//if (nVirtKey==VK_ESCAPE) {
if (MouseCaptureMode==0) {
//erase final
HDC hScreenDC = GetDC(hWnd);
DrawSelect(hScreenDC, FALSE, &old_rcClip);
ReleaseDC(hWnd,hScreenDC);
}
else if (MouseCaptureMode==1) {
NormalizeRect(&rcClip);
old_rcClip=rcClip;
if (bCapturing) bCapturing = FALSE;
}
ShowWindow(hWnd,SW_HIDE);
//ver 1.2
AllowNewRecordStartKey = TRUE;
} //VK_ESCAPE (keyRecordCancel)
return DefWindowProc(hWnd, wMessage, wParam, lParam);
}
default:
return DefWindowProc(hWnd, wMessage, wParam, lParam);
}
return 0;
}
int CreateShiftWindow() {
// Code For Creating a Window for Specifying Region
// A borderless, invisible window used only for capturing mouse input for the whole screen
HINSTANCE hInstance = AfxGetInstanceHandle( );
WNDCLASS wndclass;
wndclass.style = 0;
wndclass.lpfnWndProc = (WNDPROC)MouseCaptureWndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(hInstance, "WINCAP");
HICON hcur= LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDI_ICONCROSSHAIR));
//wndclass.hCursor = LoadCursor(NULL, IDC_CROSS);
wndclass.hCursor = hcur;
wndclass.hbrBackground = NULL;
//wndclass.lpszMenuName = (LPSTR)"MAINMENU";
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = (LPSTR) "ShiftRegionWindow";
if (!RegisterClass(&wndclass))
return 0;
HDC hScreenDC=::GetDC(NULL);
maxxScreen = GetDeviceCaps(hScreenDC,HORZRES);
maxyScreen = GetDeviceCaps(hScreenDC,VERTRES);
::ReleaseDC(NULL,hScreenDC);
hMouseCaptureWnd = CreateWindowEx(WS_EX_TOPMOST,"ShiftRegionWindow", "Title",WS_POPUP,0,0,maxxScreen,maxyScreen,NULL,NULL, hInstance, NULL);
return 0;
}
int InitSelectRegionWindow() {
return 0;
}
int InitDrawShiftWindow() {
HDC hScreenDC = ::GetDC(hMouseCaptureWnd);
FixRectSizePos(&rc, maxxScreen, maxyScreen);
rcClip.left=rc.left;
rcClip.top=rc.top;
rcClip.right=rc.right;
rcClip.bottom=rc.bottom;
DrawSelect(hScreenDC, TRUE, &rcClip);
old_rcClip = rcClip;
//Set Curosr at the centre of the clip rectangle
POINT ptOrigin;
ptOrigin.x=(rcClip.right+rcClip.left)/2;
ptOrigin.y=(rcClip.top+rcClip.bottom)/2;
rcOffset.left=rcClip.left-ptOrigin.x;
rcOffset.top=rcClip.top-ptOrigin.y;
rcOffset.right=rcClip.right-ptOrigin.x;
rcOffset.bottom=rcClip.bottom-ptOrigin.y;
::ReleaseDC(hMouseCaptureWnd,hScreenDC);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -