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

📄 filename.cpp

📁 用vc编写的视频采集端口编成
💻 CPP
字号:
// FileName.cpp: implementation of the CFileName class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "FileName.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CFileName::CFileName()
{
	
	HKEY hKey;
	if(RegOpenKeyEx(HKEY_CURRENT_USER, "software\\doggle\\AirGuard", 0, KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS)
		MessageBox(NULL, "Calling RegOpenKeyEx error", "error", MB_OK | MB_ICONERROR);


	char lpstrValue[100], lpszMessage[100];
	DWORD cbData = 100, dwType;
	unsigned long dwRtValue;

	dwRtValue = RegQueryValueEx(hKey, "doggle", NULL, &dwType, (LPBYTE)lpstrValue, &cbData);
	if (dwRtValue != ERROR_SUCCESS){

		sprintf(lpszMessage, "找不到指定文件, 请与供应商联系");
		MessageBox(NULL, lpszMessage, "error", MB_OK | MB_ICONERROR);
		exit(0);
	}


	cbData = 100;
	dwRtValue = RegQueryValueEx(hKey, "FileName", NULL, &dwType, (LPBYTE)lpstrValue, &cbData);
	if (dwRtValue != ERROR_SUCCESS){
	//	FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwRtValue, 0, lpszMessage, 100, NULL);
		sprintf(lpszMessage, "找不到指定文件, 请与供应商联系");
		MessageBox(NULL, lpszMessage, "error", MB_OK | MB_ICONERROR);

	}
	else strcpy(BaseFileToWriteName, lpstrValue);
	RegCloseKey(hKey);




	char lpszTemp[100];
	int iPointer;
	int iLen, i;
	strcpy(lpszTemp, GetCommandLine());
	iLen = strlen(lpszTemp);
	for(i = 0; i < iLen; i ++)
		lpszTemp[i] = lpszTemp[i + 1];
	lpszTemp[i - 2] = '\0';

	iPointer = strlen(lpszTemp);
	iPointer --;
	while(lpszTemp[iPointer] != '\\')
		iPointer --;
	iPointer ++;
	lpszTemp[iPointer] = '\0';
	strcpy(lpszExeFilePath, lpszTemp);

	sprintf(lpszCaptureFilePath, "%s\Capture\\", lpszTemp);


}


bool CFileName::SetBaseFileToWriteName(LPSTR lpstrFile)
// Function: Set base filename of the bmp file to be written.
//			 The BaseFileToWriteName and the corresponding value in the register
//				will be modified at the same time.
{
	if(strlen(lpstrFile) < MAXFILE){
		strcpy(BaseFileToWriteName, lpstrFile);
		HKEY hKey;

		if(RegOpenKeyEx(HKEY_CURRENT_USER, "software\\doggle\\AirGuard", 0, KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS)
			MessageBox(NULL, "Calling RegOpenKeyEx error", "error", MB_OK | MB_ICONERROR);
		RegSetValueEx(hKey, "FileName", NULL, REG_SZ, (BYTE*)BaseFileToWriteName, strlen(BaseFileToWriteName));
		RegCloseKey(hKey);
		return 1;
	}
	else return 0;
}




bool CFileName::GetNextFileToWrite(LPSTR lpstrFileName, unsigned int nMax)
{

	SYSTEMTIME st;
	int i;
	char lpszTemp[100];
	char string[10];

	if(nMax <= strlen(BaseFileToWriteName))
		return false;

	strcpy(lpstrFileName, BaseFileToWriteName);
	for(i = strlen(lpstrFileName); lpstrFileName[i] != '.'; i--)
		lpstrFileName[i] = '\0';
	lpstrFileName[i] = '\0';
	GetSystemTime(&st);
	if(st.wMonth < 10)
		sprintf(string, "0%d", st.wMonth);
		else sprintf(string, "%d", st.wMonth);
	strcpy(lpszTemp, string);
	if(st.wDay < 10)
		sprintf(string, "0%d", st.wDay);
		else sprintf(string, "%d", st.wDay);
	strcat(lpszTemp, string);
	st.wHour += 8;
	st.wHour = st.wHour % 24;
	if(st.wHour < 10)
		sprintf(string, "0%d", st.wHour);
		else sprintf(string, "%d", st.wHour);
	strcat(lpszTemp, string);
	if(st.wMinute < 10)
		sprintf(string, "0%d", st.wMinute);
		else sprintf(string, "%d", st.wMinute);
	strcat(lpszTemp, string);
	if(st.wSecond < 10)
		sprintf(string, "0%d", st.wSecond);
		else sprintf(string, "%d", st.wSecond);
	strcat(lpszTemp, string);
	strcat(lpszTemp, ".bmp");
	//sprintf(lpszTemp, "%d%d%d%d%d.bmp", st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
	if(nMax <= strlen(BaseFileToWriteName) + strlen(lpszTemp) - 4)
		return false;

	strcat(lpstrFileName, lpszTemp);

	return 1;
	
}


bool CFileName::myGetOpenFileName(HWND hWnd, LPSTR lpstrInitialDir, LPSTR lpstrFile, int nMaxFile)
// Function: Eject an Open File Box. 
//			 If the user specifies a filename and clicks the OK button, the 
//				return value is nonzero. The buffer pointed to by the lpstrFile 
//				member of the OPENFILENAME structure contains the full path and 
//				filename specified by the user.
//			 If the user cancels or closes the Open dialog box or an error occurs, 
//				the return value is zero.



{
	char lpstrFilter[100] = "Image File(*.bmp)#*.bmp#";
	char *ptr = lpstrFilter;
	while(*ptr){
		if (*ptr == '#')
			*ptr = '\0';
		ptr ++;
	}


	char lpstrFileTitle[MAXFILETITLE] = "\0";
	char lpstrTitle[100] = "Specify file name";
	char lpstrDefExt[50] = "bmp";
	char lpstrCustomFilter[MAXCUSTFILTER] = "\0";


	OPENFILENAME ofn;
	ZeroMemory(&ofn, sizeof(OPENFILENAME));
	ofn.lStructSize = sizeof(OPENFILENAME);
	ofn.hwndOwner = hWnd;
	ofn.lpstrFilter = lpstrFilter;
	ofn.nFilterIndex = 1;
	ofn.lpstrFile = lpstrFile;
	ofn.nMaxFile = nMaxFile;
	ofn.lpstrFileTitle = lpstrFileTitle;
	ofn.lpstrInitialDir = lpstrInitialDir;
	ofn.lpstrTitle = lpstrTitle;
	ofn.lpstrDefExt = lpstrDefExt;
	ofn.lpstrCustomFilter = lpstrCustomFilter;
	ofn.nMaxCustFilter = MAXCUSTFILTER;
	ofn.Flags = OFN_CREATEPROMPT;

	return (GetOpenFileName(&ofn) == 0) ? false : true;

}


CFileName::~CFileName()
{

}

⌨️ 快捷键说明

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