📄 vscapview.cpp
字号:
panrect_dest.right = panrect_current.right;
panrect_dest.left = panrect_current.left;
}
if (xPoint.y < exttop ) { //need to pan up
panrect_dest.top = xPoint.y - height/2;
panrect_dest.bottom = panrect_dest.top + height - 1;
if (panrect_dest.top < 0) {
panrect_dest.top = 0;
panrect_dest.bottom = panrect_dest.top + height - 1;
}
}
else if (xPoint.y > extbottom ) { //need to pan down
panrect_dest.top = xPoint.y - height/2;
panrect_dest.bottom = panrect_dest.top + height - 1;
if (panrect_dest.bottom >= maxyScreen) {
panrect_dest.bottom = maxyScreen - 1;
panrect_dest.top = panrect_dest.bottom - height + 1;
}
}
else {
panrect_dest.top = panrect_current.top;
panrect_dest.bottom = panrect_current.bottom;
}
//Determine Pan Values
int xdiff,ydiff;
xdiff = panrect_dest.left - panrect_current.left;
ydiff = panrect_dest.top - panrect_current.top;
if (abs(xdiff) < maxpan) {
panrect_current.left += xdiff;
}
else {
if (xdiff<0)
panrect_current.left -= maxpan;
else
panrect_current.left += maxpan;
}
if (abs(ydiff) < maxpan) {
panrect_current.top += ydiff;
}
else {
if (ydiff<0)
panrect_current.top -= maxpan;
else
panrect_current.top += maxpan;
}
panrect_current.right = panrect_current.left + width - 1;
panrect_current.bottom = panrect_current.top + height - 1;
alpbi=captureScreenFrame(panrect_current.left,panrect_current.top,width, height,0);
}
else
alpbi=captureScreenFrame(left,top,width, height,0);
if (initcapture==0) {
if (timelapse>1000)
frametime++;
else
frametime = (DWORD) (((double) timeexpended /1000.0 ) * (double) (1000.0/timelapse));
}
else
initcapture = 0;
fTimeLength = ((float) timeexpended) /((float) 1000.0);
if ((frametime==0) || (frametime>oldframetime)) {
//if frametime repeats...the avistreamwrite will cause an error
hr = AVIStreamWrite(psCompressed, // stream pointer
frametime, // time of this frame
1, // number to write
(LPBYTE) alpbi + // pointer to data
alpbi->biSize +
alpbi->biClrUsed * sizeof(RGBQUAD),
alpbi->biSizeImage, // size of this frame
//AVIIF_KEYFRAME, // flags....
0, //Dependent n previous frame, not key frame
NULL,
NULL);
if (hr != AVIERR_OK)
break;
nActualFrame ++ ;
nCurrFrame = frametime;
fRate = ((float) nCurrFrame)/fTimeLength;
fActualRate = ((float) nActualFrame)/fTimeLength;
//Update record stats every half a second
divx = timeexpended / 500;
if (divx != oldsec) {
oldsec=divx;
InvalidateRect(hWndGlobal,NULL, FALSE);
}
//free memory
FreeFrame(alpbi);
alpbi=NULL;
oldframetime = frametime;
} // if frametime is different
//introduce time lapse
//maximum lapse when recordstate changes will be less than 100 milliseconds
int no_iteration = timelapse/50;
int remainlapse = timelapse - no_iteration*50;
for (int j=0;j<no_iteration;j++)
{
::Sleep(50); //Sleep for 50 milliseconds many times
if (recordstate==0) break;
}
if (recordstate==1) Sleep(remainlapse);
} //for loop
error:
//
// Now close the file
//
if (flashingRect) {
pFrame->ShowWindow(SW_HIDE);
}
AVISaveOptionsFree(1,(LPAVICOMPRESSOPTIONS FAR *) &aopts);
if (pfile)
AVIFileClose(pfile);
if (ps)
AVIStreamClose(ps);
if (psCompressed)
AVIStreamClose(psCompressed);
AVIFileExit();
if (hr != NOERROR) {
PostMessage(hWndGlobal,WM_USER_RECORDINTERRUPTED,0,0);
/*
char *ErrorBuffer; // This really is a pointer - not reserved space!
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), (LPTSTR)&ErrorBuffer, 0, NULL);
CString reasonstr(ErrorBuffer);
CString errorstr("File Creation Error. Unable to rename file.\n\n");
CString reportstr;
reportstr = errorstr + reasonstr;
MessageBox(NULL,reportstr,"Note",MB_OK | MB_ICONEXCLAMATION);
*/
if (compfccHandler != mmioFOURCC('M', 'S', 'V', 'C')) {
if (IDYES == MessageBox(NULL, "Error recording AVI file using current compressor. Use default compressor ? ", "Note", MB_YESNO | MB_ICONEXCLAMATION)) {
compfccHandler = mmioFOURCC('M', 'S', 'V', 'C');
strCodec = "Default Compressor";
PostMessage(hWndGlobal,WM_USER_RECORDSTART,0,0);
}
}
else
MessageBox(NULL, "Error Creating AVI File", "Error", MB_OK | MB_ICONEXCLAMATION);
return 0;
}
//Save the file on success
PostMessage(hWndGlobal,WM_USER_GENERIC,0,0);
return 0;
}
//Round positive numbers
long rounddouble(double dbl) {
long num = (long) dbl;
double diff = dbl - (double) num;
if (diff>=0.5) num++;
return num;
}
LPBITMAPINFOHEADER captureScreenFrame(int left,int top,int width, int height,int tempDisableRect)
{
HDC hScreenDC = ::GetDC(NULL);
//if flashing rect
if (flashingRect && !tempDisableRect) {
if (autopan) {
pFrame->SetUpRegion(left,top,width,height,1);
DrawFlashingRect( TRUE , 1);
}
else
DrawFlashingRect( TRUE , 0);
}
HDC hMemDC = ::CreateCompatibleDC(hScreenDC);
HBITMAP hbm;
hbm = CreateCompatibleBitmap(hScreenDC, width, height);
HBITMAP oldbm = (HBITMAP) SelectObject(hMemDC, hbm);
BitBlt(hMemDC, 0, 0, width, height, hScreenDC, left, top, SRCCOPY);
//Get Cursor Pos
POINT xPoint;
GetCursorPos( &xPoint );
HCURSOR hcur= FetchCursorHandle();
xPoint.x-=left;
xPoint.y-=top;
//Draw the HighLight
if (g_highlightcursor==1) {
POINT highlightPoint;
highlightPoint.x = xPoint.x -64 ;
highlightPoint.y = xPoint.y -64 ;
InsertHighLight( hMemDC, highlightPoint.x, highlightPoint.y);
}
//Draw the Cursor
if (g_recordcursor==1) {
ICONINFO iconinfo ;
BOOL ret;
ret = GetIconInfo( hcur, &iconinfo );
if (ret) {
xPoint.x -= iconinfo.xHotspot;
xPoint.y -= iconinfo.yHotspot;
//need to delete the hbmMask and hbmColor bitmaps
//otherwise the program will crash after a while after running out of resource
if (iconinfo.hbmMask) DeleteObject(iconinfo.hbmMask);
if (iconinfo.hbmColor) DeleteObject(iconinfo.hbmColor);
}
::DrawIcon( hMemDC, xPoint.x, xPoint.y, hcur);
}
SelectObject(hMemDC,oldbm);
LPBITMAPINFOHEADER pBM_HEADER = (LPBITMAPINFOHEADER)GlobalLock(Bitmap2Dib(hbm, bits));
//LPBITMAPINFOHEADER pBM_HEADER = (LPBITMAPINFOHEADER)GlobalLock(Bitmap2Dib(hbm, 24));
if (pBM_HEADER == NULL) {
MessageBox(NULL,"Error reading a frame!","Error",MB_OK | MB_ICONEXCLAMATION);
exit(1);
}
DeleteObject(hbm);
DeleteDC(hMemDC);
//if flashing rect
if (flashingRect && !tempDisableRect) {
if (autopan) {
DrawFlashingRect(FALSE , 1);
}
else
DrawFlashingRect(FALSE , 0);
}
ReleaseDC(NULL,hScreenDC) ;
return pBM_HEADER;
}
void FreeFrame(LPBITMAPINFOHEADER alpbi)
{
if (!alpbi)
return ;
GlobalFreePtr(alpbi);
//GlobalFree(alpbi);
alpbi = NULL;
}
HCURSOR FetchCursorHandle() {
if (g_cursortype == 0) {
if (hSavedCursor == NULL)
hSavedCursor = GetCursor();
return hSavedCursor;
}
else if (g_cursortype == 1) {
return g_customcursor ;
}
else {
return g_loadcursor;
}
}
CString GetTempPath()
{
char dirx[300];
GetWindowsDirectory(dirx,300);
CString tempdir(dirx);
tempdir = tempdir + "\\temp";
return tempdir;
}
void DrawClientArea(HWND hwnd, HDC hdc) {
RECT rect;
::GetClientRect(hwnd, &rect );
//OffScreen Buffer
HBITMAP hbm = NULL;
HBITMAP old_bitmap;
HDC hdcBits = CreateCompatibleDC(hdc);
hbm = (HBITMAP) CreateCompatibleBitmap(hdc,rect.right-rect.left+1,rect.bottom-rect.top+1);
old_bitmap = (HBITMAP) SelectObject(hdcBits,hbm);
//Drawing to OffScreen Buffer
//TRACE("\nRect coords: %d %d %d %d ",rect.left,rect.top,rect.right,rect.bottom);
//HBRUSH dgbrush = (HBRUSH) ::GetStockObject(DKGRAY_BRUSH);
HBRUSH dgbrush = (HBRUSH) ::GetStockObject(BLACK_BRUSH);
HBRUSH oldbrush = (HBRUSH) ::SelectObject(hdcBits,dgbrush);
::Rectangle(hdcBits, rect.left,rect.top,rect.right,rect.bottom);
//Display the record information when recording
if (recordstate==1) {
COLORREF rectcolor = RGB(225,225,225);
COLORREF textcolor = RGB(0,0,100);
RECT txRect;
int xoffset =10 ;
int yoffset =10 ;
HFONT hFont = (HFONT) ::GetStockObject(ANSI_VAR_FONT);
HFONT hOld_Font = (HFONT) ::SelectObject(hdcBits,hFont);
COLORREF oldTextColor = SetTextColor(hdcBits, textcolor);
COLORREF oldBkColor = SetBkColor(hdcBits,rectcolor);
HBRUSH bkBrush = CreateSolidBrush(rectcolor);
HBRUSH old2_Brush = (HBRUSH) ::SelectObject(hdcBits,bkBrush);
char msgstr[100];
SIZE Extent;
sprintf(msgstr,"Current Frame : %d", nCurrFrame);
GetTextExtentPoint32( hdcBits,msgstr, strlen(msgstr), &Extent);
txRect = rect;
txRect.top = yoffset -2 ;
txRect.bottom = yoffset + Extent.cy + 4 ;
::Rectangle(hdcBits, txRect.left,txRect.top,txRect.right,txRect.bottom);
TextOut(hdcBits,xoffset,yoffset, msgstr, strlen(msgstr));
/*
yoffset+=Extent.cy+10;
sprintf(msgstr,"Theoretical Frame Rate : %.2f fps", fRate);
GetTextExtentPoint32( hdcBits,msgstr, strlen(msgstr), &Extent);
txRect.top = yoffset -2 ;
txRect.bottom = yoffset + Extent.cy + 4 ;
::Rectangle(hdcBits, txRect.left,txRect.top,txRect.right,txRect.bottom);
TextOut(hdcBits,xoffset,yoffset, msgstr, strlen(msgstr));
*/
yoffset+=Extent.cy+10;
sprintf(msgstr,"Time Elasped : %.2f sec", fTimeLength);
GetTextExtentPoint32( hdcBits,msgstr, strlen(msgstr), &Extent);
txRect.top = yoffset -2 ;
txRect.bottom = yoffset + Extent.cy + 4 ;
::Rectangle(hdcBits, txRect.left,txRect.top,txRect.right,txRect.bottom);
TextOut(hdcBits,xoffset,yoffset, msgstr, strlen(msgstr));
yoffset+=Extent.cy+10;
sprintf(msgstr,"Number of Colors : %d bits", nColors);
GetTextExtentPoint32( hdcBits,msgstr, strlen(msgstr), &Extent);
txRect.top = yoffset -2 ;
txRect.bottom = yoffset + Extent.cy + 4 ;
::Rectangle(hdcBits, txRect.left,txRect.top,txRect.right,txRect.bottom);
TextOut(hdcBits,xoffset,yoffset, msgstr, strlen(msgstr));
yoffset+=Extent.cy+10;
sprintf(msgstr,"Codec : %s", LPCTSTR(strCodec));
GetTextExtentPoint32( hdcBits,msgstr, strlen(msgstr), &Extent);
txRect.top = yoffset -2 ;
txRect.bottom = yoffset + Extent.cy + 4 ;
::Rectangle(hdcBits, txRect.left,txRect.top,txRect.right,txRect.bottom);
TextOut(hdcBits,xoffset,yoffset, msgstr, strlen(msgstr));
yoffset+=Extent.cy+10;
sprintf(msgstr,"Actual Input Rate : %.2f fps", fActualRate);
GetTextExtentPoint32( hdcBits,msgstr, strlen(msgstr), &Extent);
txRect.top = yoffset -2 ;
txRect.bottom = yoffset + Extent.cy + 4 ;
::Rectangle(hdcBits, txRect.left,txRect.top,txRect.right,txRect.bottom);
TextOut(hdcBits,xoffset,yoffset, msgstr, strlen(msgstr));
yoffset+=Extent.cy+10;
sprintf(msgstr,"Dimension : %d X %d", actualwidth,actualheight);
GetTextExtentPoint32( hdcBits,msgstr, strlen(msgstr), &Extent);
txRect.top = yoffset -2 ;
txRect.bottom = yoffset + Extent.cy + 4 ;
::Rectangle(hdcBits, txRect.left,txRect.top,txRect.right,txRect.bottom);
TextOut(hdcBits,xoffset,yoffset, msgstr, strlen(msgstr));
::SelectObject(hdcBits,old2_Brush);
DeleteObject(bkBrush);
SetBkColor(hdcBits, oldBkColor);
SetTextColor(hdcBits, oldTextColor);
::SelectObject(hdcBits,hOld_Font);
}
else {
if (nColors > 8)
SelectObject(hdcBits,hLogoBM);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -