📄 vscapview.cpp
字号:
if ((frametime==0) || (frametime>oldframetime)) {
//if frametime repeats (frametime == oldframetime) ...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 recording 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
//Version 1.1
int haveslept = 0;
int pausecounter = 0;
int pauseremainder = 0;
int pauseindicator = 1;
DWORD timestartpause;
DWORD timeendpause;
DWORD timedurationpause;
while (recordpaused) {
if (!haveslept) timestartpause = timeGetTime();
//Flash Pause Indicator in Title Bar
pausecounter++;
if ((pausecounter % 8)==0) {
//if after every 400 milliseconds (8 * 50)
if (pauseindicator) {
SetTitleBar("");
pauseindicator = 0;
}
else {
SetTitleBar(getString(ID_TITLE_PAUSED));
pauseindicator = 1;
}
}
//do nothing.. wait
::Sleep(50); //Sleep for 50
haveslept=1;
}
//Version 1.1
if (haveslept) {
timeendpause = timeGetTime();
timedurationpause = timeendpause - timestartpause;
//CString msgstr;
//msgstr.Format("timestartpause %ld\ntimeendpause %ld\ntimedurationpause %ld",timeendpause,timeendpause,timedurationpause);
//MessageBox(NULL,msgstr,"Note",MB_OK);
initialtime = initialtime + timedurationpause;
}
else {
//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);
}
//Ver 1.2
//
if ((compfccHandler == CompressorStateIsFor) && (compfccHandler != 0)) {
//Detach pParamsUse from AVICOMPRESSOPTIONS so AVISaveOptionsFree will not free it
//(we will free it ourselves)
//Setting this is no harm even if pParamsUse is not attached to lpParams
aopts[0]->lpParms = 0;
aopts[0]->cbParms = 0;
}
AVISaveOptionsFree(1,(LPAVICOMPRESSOPTIONS FAR *) &aopts);
//////////////////////////////////////////////
// Recording Audio
//////////////////////////////////////////////
if (recordaudio) {
StopAudioRecording();
ClearAudioFile();
}
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, getString(ID_ERR_RECORD_AVI), getString(ID_TITLE_MSGBOX_NOTE), MB_YESNO | MB_ICONEXCLAMATION)) {
compfccHandler = mmioFOURCC('M', 'S', 'V', 'C');
strCodec = L_MS_VIDEO_1;
PostMessage(hWndGlobal,WM_USER_RECORDSTART,0,0);
}
}
else
generalErrorMsg(ID_ERR_CREATE_AVI, ID_TITLE_MSGBOX_ERROR);
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) {
generalErrorMsg(ID_ERR_READ_SCREAN_FRAME, ID_TITLE_MSGBOX_ERROR);
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";
//Verify the chosen temp path is valid
WIN32_FIND_DATA wfd;
memset(&wfd, 0, sizeof (wfd));
HANDLE hdir = FindFirstFile(LPCTSTR(tempdir), &wfd);
if (!hdir) {
return GetProgPath();
}
FindClose(hdir);
//If valid directory, return Windows\temp as temp directory
if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
return tempdir;
//else return program path as temp directory
return GetProgPath();
}
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(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) {
//Ver 1.1
COLORREF rectcolor;
COLORREF textcolor;
if (nColors <= 8) {
rectcolor = RGB(255,255,255);
textcolor = RGB(0,0,128);
}
else {
rectcolor = RGB(225,225,225);
textcolor = RGB(0,0,100);
}
RECT txRect;
int xoffset =10 ;
int yoffset =10 ;
#if 0
// ANSI_VAR_FONT does not support DBCS text
HFONT hFont = (HFONT) ::GetStockObject(ANSI_VAR_FONT);
#else
HFONT hFont = (HFONT) ::GetStockObject(DEFAULT_GUI_FONT);
#endif
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);
SIZE Extent;
CString msgstr;
msgstr.Format(ID_INFO_CURRENT_FRAME_FORMAT, 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;
msgstr.Format(ID_INFO_TIME_ELASPED_FORMAT, 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;
msgstr.Format(ID_INFO_COLORS_FORMAT, 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;
msgstr.Format(ID_INFO_CODEC_FORMAT, 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;
msgstr.Format(ID_INFO_ACTUAL_INPUT_RATE_FORMAT, 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;
msgstr.Format(ID_INFO_DIMENSION_FORMAT, 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);
D
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -