⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vscapview.cpp

📁 一个摄像机的程序
💻 CPP
📖 第 1 页 / 共 5 页
字号:


	if (!CopyFile( tempfilepath,m_newfile,FALSE)) {

		//DeleteFile(m_newfile);
		MessageBox("File Creation Error. Unable to rename/copy file.","Note",MB_OK | MB_ICONEXCLAMATION);

		//Repeat this function until success
		::PostMessage(hWndGlobal,WM_USER_GENERIC,0,0);			

	}
	else {

		DeleteFile(tempfilepath);

	} 	
	
	//Launch the player
	if (launchPlayer == 1) {

		CString AppDir=GetProgPath();
		CString launchPath;
		CString exefileName("\\player.exe ");
		launchPath=AppDir+exefileName+m_newfile;

		if (WinExec(launchPath,SW_SHOW)!=0) {

				
		}
		else {
			MessageBox("Error launching avi player!","Note",MB_OK | MB_ICONEXCLAMATION);

		}	

	}

	return 0;

}




//**********************************************************************
//
// Utility()
//
//**********************************************************************

void WINAPI NormalizeRect(LPRECT prc)
{
    if (prc->right  < prc->left) SWAP(prc->right,  prc->left);
    if (prc->bottom < prc->top)  SWAP(prc->bottom, prc->top);
}


void FixRectSizePos(LPRECT prc,int maxxScreen, int maxyScreen)
{
	NormalizeRect(prc);
    
	int width=((prc->right)-(prc->left))+1;
	int height=((prc->bottom)-(prc->top))+1;
	
	if (width>maxxScreen) {
		
		prc->left=0;
		prc->right=maxxScreen-1;

	}

	if (height>maxyScreen) {
		
		prc->top=0;
		prc->bottom=maxyScreen-1;

	}

	if (prc->left <0) {

		prc->left= 0;
		prc->right=width-1;

	}

	if (prc->top <0) {

		prc->top= 0;
		prc->bottom=height-1;

	}

	if (prc->right > maxxScreen-1 ) {

		prc->right = maxxScreen-1;
		prc->left= maxxScreen-width;

	}

	if (prc->bottom > maxyScreen-1 ) {

		prc->bottom = maxyScreen-1;
		prc->top= maxyScreen-height;

	}


	
}

BOOL isRectEqual(RECT a, RECT b) {

	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)
{
    char sz[80];
    DWORD dw;
    int x, y, len, 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);
		HFONT newfont = (HFONT) GetStockObject(ANSI_VAR_FONT);
		HFONT oldfont = (HFONT) SelectObject(hdc, newfont);            
		//HFONT oldfont = (HFONT) SelectObject(hdcBits, newfont);            
		
		wsprintf(sz, "Left : %d  Top : %d  Width : %d  Height : %d", rectDraw.left, rectDraw.top, rectDraw.right - rectDraw.left+1, rectDraw.bottom -  rectDraw.top+1);
        len = lstrlen(sz);        
		dw = GetTextExtentPoint(hdc, sz, len, &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, sz, len, 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);				

				}

			return DefWindowProc(hWnd, wMessage, wParam, lParam);    

		}		
		case WM_KEYDOWN:
        {
			int nVirtKey = (int) wParam;    // virtual-key code 
			int lKeyData = lParam;          // key data 			

			if (nVirtKey==VK_ESCAPE) { //Cancel the operation

				if (MouseCaptureMode==0) {
				
					//erase final
					HDC hScreenDC = GetDC(hWnd);		
					DrawSelect(hScreenDC, FALSE, &old_rcClip);    
					ReleaseDC(hWnd,hScreenDC);

				}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -