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

📄 vscapview.cpp

📁 AVI这个软件是用VC编写的
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	// TODO: Add your command handler code here
	MouseCaptureMode=2;
	
}


void CVscapView::OnPaint() 
{
	CPaintDC dc(this); // device context for painting

	if (!doneOnce) {
	
		((CMainFrame*) AfxGetMainWnd())->UpdateViewtype(); 
		doneOnce=1;

	}
	
	DrawClientArea(m_hWnd, dc.m_hDC);	
	
	// Do not call CView::OnPaint() for painting messages
}

int CVscapView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	CreateShiftWindow();
	
	HDC hScreenDC = ::GetDC(NULL);	
	bits = ::GetDeviceCaps(hScreenDC, BITSPIXEL );	
	nColors = bits;
	::ReleaseDC(NULL,hScreenDC);		
	
	compfccHandler = mmioFOURCC('M', 'S', 'V', 'C');	

	hLogoBM = LoadBitmap( AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP3)); 

	pFrame = new CFlashingWnd;	
	CRect rect(0, 0, maxxScreen-1, maxyScreen-1);
	pFrame->CreateFlashing(getString(ID_TITLE_FLASHING), rect);		

		
	//Ver 1.2 
	//cursordir default
	char dirx[300];
	GetWindowsDirectory(dirx,300);
	CString windir(dirx);
	cursordir = windir + "\\cursors";			

	//savedir default
	savedir=GetProgPath();

	
	//Ver 1.1
	//SuggestRecordingFormat();
	//SuggestCompressFormat();

	return 0;
}

void CVscapView::OnDestroy() 
{
	CView::OnDestroy();
	
	// TODO: Add your message handler code here

	//ver 1.2
	DecideSaveSettings();	
	
	//ver 1.2
	UninstallMyKeyHook(hWndGlobal);	

	//ver 1.2
	finishTrayIconData();

	DestroyShiftWindow();

	if  (compressor_info != NULL) {		
	
		free(compressor_info);
		num_compressor = 0;

	}

	if (savedBitmap) {
		DeleteObject(savedBitmap);
		savedBitmap = NULL;
	}

	
	if (hLogoBM) {
		DeleteObject(hLogoBM);
		hLogoBM = NULL;
	}

	
	if (pFrame) {
	
		pFrame->DestroyWindow();
		delete pFrame;

	}	

	if (pwfx) {
		
		GlobalFreePtr(pwfx);
		pwfx = NULL;

	}

	FreeVideoCompressParams();
	FreeParamsUse();
	
}


LRESULT CVscapView::OnRecordStart (UINT wParam, LONG lParam) {

	
	CStatusBar* pStatus = (CStatusBar*) AfxGetApp()->m_pMainWnd->GetDescendantWindow(AFX_IDW_STATUS_BAR);
	pStatus->SetPaneText(0,getString(ID_STATUSTEXT_RECORDSTARTED));


	//if (minimizeOnStart == 1)
	//	AfxGetMainWnd()->ShowWindow(SW_MINIMIZE);

	//ver 1.2
	if (minimizeOnStart == 1)
		::PostMessage(AfxGetMainWnd()->m_hWnd,WM_SYSCOMMAND,SC_MINIMIZE,0);
	
	
	
	//Check validity of rc and fix it		
	HDC hScreenDC = ::GetDC(NULL);	
	maxxScreen = GetDeviceCaps(hScreenDC,HORZRES);
	maxyScreen = GetDeviceCaps(hScreenDC,VERTRES);		
	FixRectSizePos(&rc,maxxScreen, maxyScreen);		
	
	
	::ReleaseDC(NULL,hScreenDC);	

	
	InstallMyHook(hWndGlobal,WM_USER_SAVECURSOR);	
	
		
	recordstate=1;	
	interruptkey = 0;
	
	CWinThread * pThread = AfxBeginThread(RecordAVIThread, &tdata);	

	//Ver 1.3
	if (pThread)
		pThread->SetThreadPriority(threadPriority);


	//Ver 1.2
	AllowNewRecordStartKey = TRUE; //allow this only after recordstate is set to 1
	
 
	return 0;	

}


//ver 1.2
LRESULT CVscapView::OnKeyStart (UINT wParam, LONG lParam) {

		
	if ((lParam>0) && (wParam==keyRecordStart))  //lParam>0 means keydown??
	{					
			if (recordstate==0) {			

				if (AllowNewRecordStartKey) { 
					AllowNewRecordStartKey = FALSE; //prevent the case which CamStudio presents more than one region for the user to select 
					OnRecord(); 
				}
		
			}
			else if (recordstate==1) {	
				
				
				if (recordpaused==0)
					OnPause() ; //pause if currently recording
				else
					OnRecord(); 					  

			}			
		
	}
	else if ((lParam>0) && (wParam==keyRecordEnd)) 
	{					
		if (recordstate==1) 
			OnRecordInterrupted (wParam,0);
		
	}
	else if ((lParam>0) && (wParam==keyRecordCancel))  
	{

		if (recordstate==1) 
			OnRecordInterrupted (wParam,0);

	}	
	
			
	return 0;

}


LRESULT CVscapView::OnRecordInterrupted (UINT wParam, LONG lParam) {

	//if (recordstate==0) return;
		
	UninstallMyHook(hWndGlobal);	
	
	//Ver 1.1	
	if (recordpaused) {
		recordpaused = 0;
		SetTitleBar(L_CAMSTUDIO);
	}
	
	recordstate=0;
	
	//Store the interrupt key in case this function is triggered by a keypress
	interruptkey = wParam;	
	
	CStatusBar* pStatus = (CStatusBar*) AfxGetApp()->m_pMainWnd->GetDescendantWindow(AFX_IDW_STATUS_BAR);
	pStatus->SetPaneText(0,getString(ID_RECORD_INTERRUPTED));

	Invalidate();

	//ver 1.2
	::SetForegroundWindow( AfxGetMainWnd()->m_hWnd ); 			
	AfxGetMainWnd()->ShowWindow(SW_RESTORE);	

	return 0;

}

LRESULT CVscapView::OnSaveCursor (UINT wParam, LONG lParam) {	

	hSavedCursor = (HCURSOR) wParam;		

	return 0;

}



//This function is called when the avi saving is completed
LRESULT CVscapView::OnUserGeneric	(UINT wParam, LONG lParam) {
	
	//ver 1.2
	::SetForegroundWindow( AfxGetMainWnd()->m_hWnd ); 
	AfxGetMainWnd()->ShowWindow(SW_RESTORE);	
	
	//ver 1.2
	if (interruptkey==keyRecordCancel) {
	//if (interruptkey==VK_ESCAPE) {

		//Perform processing for cancel operation
		DeleteFile(tempfilepath);
		if (recordaudio) DeleteFile(tempaudiopath);
		return 0;

	}
	
	//Normal thread exit
	//Prompt the user for the filename
	CString csFileExtFilter;
	csFileExtFilter.LoadString(ID_FILEEXT_FILTER);
	csFileExtFilter += "|*.avi||";

	CFileDialog fdlg(FALSE,"*.avi","*.avi",OFN_LONGNAMES,csFileExtFilter,this);	

	CString csFileDlgTitle;
	csFileDlgTitle.LoadString(ID_TITLE_SELECTFILE);
	fdlg.m_ofn.lpstrTitle=csFileDlgTitle;	
	
	if (savedir=="") 
		savedir=GetProgPath();
	
	fdlg.m_ofn.lpstrInitialDir = savedir;
	
	CString m_newfile;
	CString m_newfileTitle;
	if(fdlg.DoModal() == IDOK)
	{
		m_newfile = fdlg.GetPathName();
		
		m_newfileTitle = fdlg.GetPathName();		
		m_newfileTitle=m_newfileTitle.Left(m_newfileTitle.ReverseFind('\\'));		
		savedir = m_newfileTitle;
	}
	else {
		
		DeleteFile(tempfilepath);
		if (recordaudio) DeleteFile(tempaudiopath);
		return 0;

	}
	
	//Ver 1.1
	if (recordaudio) {	

		//Check if file exists  and if so, does it allow overwite		
		HANDLE hfile = CreateFile(
			  m_newfile,          // pointer to name of the file
			  GENERIC_WRITE,       // access (read-write) mode
			  0,           // share mode
			  NULL,        // pointer to security attributes
			  CREATE_ALWAYS,  // how to create
			  FILE_ATTRIBUTE_NORMAL,  // file attributes
			  NULL        // handle to file with attributes to                            // copy
			);

		if (hfile == INVALID_HANDLE_VALUE) {
			generalErrorMsg(ID_ERR_CREATENEWFILE);
			::PostMessage(hWndGlobal,WM_USER_GENERIC,0,0);	
			return 0;

		}
		else {			
			
			CloseHandle(hfile);
			DeleteFile(m_newfile);

		}



		//Mergefile video with audio		
		int result = Merge_Video_And_Sound_File(tempfilepath, tempaudiopath, m_newfile, bAudioCompression, pwfx, cbwfx,interleaveFrames,interleaveFactor, interleaveUnit);

		//Check Results : Attempt Recovery on error		
		if (result==0) {

			//Successful
			DeleteFile(tempfilepath);
			DeleteFile(tempaudiopath);

		}
		else if (result==1) { //video file broken

			//Unable to recover
			DeleteFile(tempfilepath);
			DeleteFile(tempaudiopath);


		}
		else if (result==3) { //this case is rare

			//Unable to recover
			DeleteFile(tempfilepath);
			DeleteFile(tempaudiopath);


		}
		else if ((result==2) || (result==4)) { //recover video file

			//video file is ok, but not audio file
			//so copy the video file as avi	and ignore the audio
			if (!CopyFile( tempfilepath,m_newfile,FALSE)) {
			
				//Although there is error copying, the temp file still remains in the temp directory and is not deleted, in case user wants a manual recover
				generalErrorMsg(ID_ERR_CREATE_FILE);
				return 0;	
			
			}
			else {
		
				
				DeleteFile(tempfilepath);
				DeleteFile(tempaudiopath);
		
			} 	
			generalErrorMsg(ID_ERR_NOSOUNDTRACK);
		}
		else if (result == 5) { //recover both files, but as separate files

			CString m_audiofile;
			CString m_audioext(".wav");
			m_audiofile = m_newfile + m_audioext;

			if (!CopyFile( tempfilepath,m_newfile,FALSE)) {
				generalErrorMsg(ID_ERR_CREATE_FILE2);
				return 0;					
					
			}		
			else {
		
				DeleteFile(tempfilepath);				
		
			} 	
			
			if (!CopyFile(tempaudiopath,m_audiofile,FALSE)) {
				generalErrorMsg(ID_ERR_CREATE_FILE3);
				return 0;					
					
			}		
			else {
		
				DeleteFile(tempaudiopath);
		
			}
			CString msgstr;
			msgstr.Format(ID_ERR_MERGE_FORMAT, (LPCTSTR)m_newfile, (LPCTSTR)m_audiofile);
			::MessageBox(NULL,msgstr,getString(ID_TITLE_MSGBOX_NOTE),MB_OK | MB_ICONEXCLAMATION);		

		} //if result


	
	}	   //if record audio

	else { //no audio, just do a plain copy of temp avi to final avi

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

			//Ver 1.1
			//DeleteFile(m_newfile);
			generalErrorMsg(ID_ERR_CREATE_FILE4);
	
			//Repeat this function until success
			::PostMessage(hWndGlobal,WM_USER_GENERIC,0,0);			
			return 0;
	
		}
		else {
	
			DeleteFile(tempfilepath);
			if (recordaudio) DeleteFile(tempaudiopath);
	
		} 	
		
	} 
	
	
	//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 {
			generalErrorMsg(ID_ERR_LAUNCH_PLAYER);
		}	

	}

	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) {

⌨️ 快捷键说明

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