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

📄 cappicture.cpp

📁 视频捕获程序代码,比较实用的东西。在61IC上下的
💻 CPP
📖 第 1 页 / 共 2 页
字号:
					
						isRecording = false;
						break;
					}
					
					if(!isRecording ) // we're not recording, but a file's selected
					{
						int a = 0;
						
						MessageBox(hwndMain, "Do you want to write over the open file?",
									"File warning", MB_YESNO | MB_ICONWARNING);
						if (a != IDYES)
						{
							isRecordFileOpen = false;
							SendMessage(hwndMain, WM_COMMAND, MAKEWPARAM(RECORDVIDEO, BN_CLICKED), (LPARAM) hwndRecord);
						}
						
						if (a == IDYES)
						{
							capCaptureSequence(hwndVideo);
							isRecording = true;
						}
						
					break;
					}
				}
			}	
         	break;
         }
      break;


/**************************************************************\
*     WM_CREATE:                                               *
\**************************************************************/

      case WM_CREATE:
      
      	RECT helpRect, minRect, exitRect;
      	HRGN helpRgn, minRgn, exitRgn;
      	
        // make the main region
        hRegion1 = CreateRoundRectRgn(0,0,500,400, 200, 200);   
      
        // create video capture window
	  	hwndVideo = capCreateCaptureWindow(
	  					(LPSTR) "My Capture Window",
	  					WS_CHILD | WS_VISIBLE,
	  					160, 120, 200, 148,
	  					(HWND) hwndMain,
	  					(int) 1);
	  	
	  // Create the main window's buttons
	  		  	
	  	// create the close button
		hwndExit = CreateWindow (
				"button", // Builtin button class 
				"x", // button text
				WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_CENTER | BS_VCENTER, // styles
				275, 10, BUTTONSIZE, BUTTONSIZE, // position and size
				hwndMain, // Parent is main window
				(HMENU) EXIT,// Control ID: EXIT
				(HINSTANCE)ghInstance,
				(LPVOID)NULL);
    
	  	// create the minimize button
		hwndMin = CreateWindow (
				"button", // Builtin button class 
				"-", // button text
				WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_CENTER | BS_VCENTER, // styles
				250, 10, BUTTONSIZE, BUTTONSIZE, // position and size
				hwndMain, // Parent is main window
				(HMENU) MINIMIZE,// Control ID: MINIMIZE
				(HINSTANCE)ghInstance,
				(LPVOID)NULL);  		

	  	// create the help button
		hwndHelp = CreateWindow (
				"button", // Builtin button class 
				"?", // button text
				WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_CENTER | BS_VCENTER, // styles
				225, 10, BUTTONSIZE, BUTTONSIZE, // position and size
				hwndMain, // Parent is main window
				(HMENU) HELP,// Control ID: HELP
				(HINSTANCE)ghInstance,
				(LPVOID)NULL);
				
	  	// create the record video button
		hwndRecord = CreateWindow (
				"button", // Builtin button class 
				"Record Video", // button text
				WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_CENTER | BS_VCENTER, // styles
				200, 280, 90, 28, // position and size
				hwndMain, // Parent is main window
				(HMENU) RECORDVIDEO,// Control ID: RECORDVIDEO
				(HINSTANCE)ghInstance,
				(LPVOID)NULL);				
				
	  	// get the button rectangles
	  	GetClientRect(hwndHelp, &helpRect);
	  	GetClientRect(hwndMin, &minRect);
	  	GetClientRect(hwndExit, &exitRect);
	  		  		  	
	  	// create the button regions
	  	helpRgn = CreateEllipticRgnIndirect(&helpRect);
		minRgn = CreateEllipticRgnIndirect(&minRect);
		exitRgn = CreateEllipticRgnIndirect(&exitRect);
	  		  		
   	    //Set the window to the region
	    SetWindowRgn(hwndExit,exitRgn,1);
	    SetWindowRgn(hwndMin,minRgn,1);					  		  		
	    SetWindowRgn(hwndHelp,helpRgn,1);				
	
	  	// create the SelCapDrv dialog
		hwndSelCapDrvDlg = CreateDialog((HINSTANCE)ghInstance, 
										MAKEINTRESOURCE( SELCAPDRVDLG  ), 
										0, (DLGPROC)SelCapDrvProc);
		// get the handle to the list box
		hwndSelCapDrvDlg_LBox = GetDlgItem(hwndSelCapDrvDlg, 
   										   SELCAPDRVDLG_LSTBOX);
	    EnumCapDrv();
      break;

/****************************************************************\
*WM_DESTROY: PostQuitMessage() is called and get rid of vfw stuff*
\****************************************************************/

      case WM_DESTROY:
      	 capPreview(hwndVideo, FALSE); // end preview
      	 capDriverDisconnect(hwndVideo); // disconnect from driver
         PostQuitMessage( 0 );
         break;

/**************************************************************\
*     Let the default window proc handle all other messages    *
\**************************************************************/

      default:
         return( DefWindowProc( hwndMain, msg, wParam, lParam ));

   }

   return 0;
}

LRESULT CALLBACK SelCapDrvProc( HWND hWnd, UINT msg, /*callback procedure */
								WPARAM wParam, LPARAM lParam )
{

	switch(msg)
	{
		// dialog created
		case WM_INITDIALOG:
		    return TRUE;
		// command    
		case WM_COMMAND:
			switch ( wParam )
			{
				// user clicked the select driver button
				case SELCAPDRVDLG_BUTTON:
					int sel = 0;
					// get the selected driver
					SendMessage( hwndSelCapDrvDlg_LBox, LB_GETSELITEMS, 1, sel);
					// connect to the driver
					SendMessage( hwndVideo, WM_CAP_DRIVER_CONNECT, sel, 0L); 
					// then close this dialog
					SendMessage( hwndSelCapDrvDlg, WM_CLOSE, 0, 0);
					// update the driver capabilities
					SendMessage( hwndVideo, WM_CAP_DRIVER_GET_CAPS,
								 sizeof(CAPDRIVERCAPS), (LONG) (LPVOID) &CapDrvCaps);
					
					// set preview rate to 66 miliseconds
					capPreviewRate( hwndVideo, 66 );
					// start preview video
					capPreview( hwndVideo, TRUE );
			}
			return TRUE;
		// user wants to close dialog
		case WM_CLOSE:
			DestroyWindow(hwndSelCapDrvDlg);
			return TRUE;
	}

	return( 0L );
}

int EnumCapDrv() // enumerate the installed capture drivers
{
	char szDeviceName[80]; // driver name
	char szDeviceVersion[80]; // driver version
	char item[161]; // concatinated string
	int i; // counter

	for (i=0; i<10; i++)
	{
		if ( capGetDriverDescription(i, szDeviceName, sizeof(szDeviceName),
									szDeviceVersion, sizeof(szDeviceVersion)) )
		{
				strcpy(item, szDeviceName);
				strcat(item, " ");
				strcat(item, szDeviceVersion);
		
				// add item to list box
				SendMessage(hwndSelCapDrvDlg_LBox, LB_ADDSTRING, 0, 
            			   (LPARAM) item);
            	SendMessage(hwndSelCapDrvDlg_LBox, LB_SETITEMDATA, i, (LPARAM) i);
        }
    }
    
    return 0;
}

/*int CreateWndButtons()
{//why doesnt this work
	RECT rc; // window rectangle
	GetClientRect(hwndMain, &rc);
	// create the button
	hwndExit = CreateWindow (
				"button", // Builtin button class 
				"X", // button text
				WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, // styles
				100, 100, BUTTONSIZE, BUTTONSIZE, // position and size
				hwndMain, // Parent is main window
				(HMENU) EXIT,// Control ID: EXIT
				(HINSTANCE)ghInstance,
				(LPVOID)NULL);
return 0;
}
*/
VOID APIENTRY HandlePopupMenu(HWND hwnd, POINT pt) 
{ 
    HMENU hmenu;            // menu template          
    HMENU hmenuTrackPopup;  // shortcut menu   
 
    //  Load the menu template containing the shortcut menu from the 
    // application's resources. 
 
    hmenu = LoadMenu((HINSTANCE)ghInstance, "PopupMenu"); 
    if (hmenu == NULL) 
        return; 
 
    // Get the first shortcut menu in the menu template. This is the 

    // menu that TrackPopupMenu displays. 
 
    hmenuTrackPopup = GetSubMenu(hmenu, 0); 
 
    // TrackPopup uses screen coordinates, so convert the 
    // coordinates of the mouse click to screen coordinates. 
 
    ClientToScreen(hwnd, (LPPOINT) &pt); 
 
    // Draw and track the shortcut menu.  
 
    TrackPopupMenu(hmenuTrackPopup, TPM_LEFTALIGN | TPM_LEFTBUTTON, 
        pt.x, pt.y, 0, hwnd, NULL); 
 
    // Destroy the menu. 
 
    DestroyMenu(hmenu); 

}

DWORD WINAPI videoThreadProc(LPVOID lParam)
{
	// make the record button say "Stop Recording"
	SetWindowText(hwndRecord, "Stop Recording");
	
	// capture the video
	capCaptureSequence(hwndVideo);
	isRecording = true;
	
	// don't exit the thread until the record button is pressed again
	while (!threadEnd)
		;
	
	MessageBox(NULL, "Leaving Thread", "thread", NULL);
	return 0;
}

⌨️ 快捷键说明

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