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

📄 calcborn.cpp

📁 预产期的计算
💻 CPP
📖 第 1 页 / 共 5 页
字号:
		dwCrc32 = ((dwCrc32 >> 8) & 0x00FFFFFF) ^ \
			Crc32Table[(*pData++) ^ (BYTE)(dwCrc32 & 0xFF)];
	}
	return (~dwCrc32);
}

/* 处理路径加or减"\\",nCut==0 为加上"\\" */
void HandleSckPath(char *pStr, int nCut)
{
	int nLen = lstrlen(pStr);
	if(pStr == NULL || nLen <= 0) return;
	char *p = pStr + nLen - 1;
	if(!nCut && *p != '\\') {*(++p) = '\\'; *(++p) = '\0';}
	else if(nCut && *p == '\\') *p = '\0';
}

/* 字符串之间的拷贝,可设置源缓存大小,返回不带'\0'的长度 */
int lstrCpy(char *chDes, const char *chSrc, int nMax/* = 0*/)
{
	if(!chDes) return 0;
	if(!chSrc) {chDes[0] = '\0'; return 0;}
	int nLen = 0;
	for(;;)
	{
		chDes[nLen] = chSrc[nLen];
		if(chDes[nLen] == '\0') break;
		nLen++;
		if(nMax && nLen >= nMax - 1)
		{
			chDes[nLen] = '\0'; break;
		}
	}
	return nLen;
}

/* 获取文件名的开始位置(字符串数据索引) */
int GetNamePos(LPCTSTR chFile)
{
	LPCTSTR chCurr = chFile, chRec = chFile;
	while(*chCurr) {if(*(chCurr++) == '\\') chRec = chCurr;}
	return (chRec - chFile);
}

/* 获取文件的全路径中的文件名首指针 */
char *GetNamePtr(const char *chFile)
{
	const char *chCurr = chFile, *chRec = chFile;
	while(*chCurr) {if(*(chCurr++) == '\\') chRec = chCurr;}
	LONG nOff = (LONG)chRec; return ((char *)nOff);
}

/* 得到文件名的长度(小数点的位置) */
int GetNameLen(LPCTSTR chFile)
{
	LPCTSTR chCurr = chFile, chRec = NULL;
	for(;;)
	{
		if(*chCurr == '.') chRec = chCurr;
		else if(*chCurr == '\0')
		{
			if(!chRec) chRec = chCurr;
			break;
		}
		chCurr++;
	}
	return (chRec ? (chRec - chFile) : 0);
}

/* 判断文件扩展名与指定的是否相同,不带'.'点 */
BOOL IsSameExt(LPCTSTR chFile, LPCTSTR chExt)
{
	if(!chFile || !chExt) return (FALSE);
	int nPos = GetNameLen(chFile) + 1;
	return (stricmp(&chFile[nPos], chExt) == 0);
}

/* 备份指定的文件,在同一目录下,使用指定扩展名 */
BOOL BackupFile(LPCTSTR chFile, LPCTSTR chExt)
{
	char chBak[MAX_PATH];
	lstrcpy(chBak, chFile);
	int nPos = GetNameLen(chBak) + 1;
	lstrcpy(&chBak[nPos], chExt);
	SetFileAttributes(chBak, 0x20);
	return (CopyFile(chFile, chBak, FALSE));
}

/* 将给定路径去除最后一级目录,求得上层目录 */
void GetUpperFolder(char *chPath)
{
	char *chUp = NULL, *chTp = NULL;
	while(*chPath)
	{
		if(*(chPath++) == '\\')
		{
			chUp = chTp;
			chTp = chPath;
		}
	}
	if(!chTp) *chPath = '\0';
	else if(!chUp) *chTp = '\0';
	else *chUp = '\0';
}

/* 使字符串自适应给定长度,中间填充"..." */
void AutoAdaptLength(char *pDes, const char *pSrc, int nObj)
{
	if(!pDes || !pSrc || nObj < 0) return;
	
	if(nObj < 5) {memcpy(pDes, pSrc, nObj);
		pDes[nObj] = '\0'; return;}
	
	int nLen = lstrlen(pSrc);
	if(nLen <= nObj) {lstrcpy(pDes, pSrc); return;}
	
	int nLf = (nObj - 3) / 2, nRt = nObj - (nLf + 3);
	memcpy(pDes, pSrc, nLf);
	pDes[nLf] = pDes[nLf + 1] = pDes[nLf + 2] = '.';
	lstrcpy(&pDes[nLf + 3], &pSrc[nLen - nRt]);
}

/* 更新原有的文件名,只是复制了新的文件名过去,再加上新的扩展名 */
void RenewFileName(char *chDesFile, const char *chSrcFile,
					const char *chFileExt)
{
	if(chDesFile == NULL || chSrcFile == NULL) return;
	int i = 0, j = 0, nLen[2] = {lstrlen(chSrcFile), lstrlen(chDesFile)};
	if(nLen[0] < 1) return;
	if(nLen[1] < 1) {lstrcpy(chDesFile, chSrcFile); nLen[1] = nLen[0];}
	for(i=nLen[0]-1; i>=0; i--) {if(chSrcFile[i] == '\\') break;} i++;
	for(j=nLen[1]-1; j>=0; j--) {if(chDesFile[j] == '\\') break;} j++;
	while(i <= nLen[0])
	{
		if(chSrcFile[i] == '.' && chFileExt != NULL) break;
		chDesFile[j++] = chSrcFile[i++];
	}
	if(chFileExt == NULL) return; chDesFile[j++] = '.'; i = 0;
	for(;;) {chDesFile[j++] = chFileExt[i]; if(chFileExt[i++] == '\0') break;}
}

/* 求出参考路径的最顶目录(有以'\\'结束的),并复制到chNew */
int GenPathTopDir(char *chNew, const char *chOld)
{
	if(!chNew || !chOld) return 0;
	int nPos[2] = {-1, -1}, nLen = 0;
	for(;;)
	{
		if(chOld[nLen] == '\0') break;
		else if(chOld[nLen] == '\\')
		{
			nPos[0] = nPos[1];
			nPos[1] = nLen + 1;
		}
		nLen++;
	}
	if(nPos[0] < 0) nLen = lstrCpy(chNew, "OutPut\\");
	else
	{
		nLen = nPos[1] - nPos[0];
		memcpy(chNew, &chOld[nPos[0]], nLen);
		chNew[nLen] = '\0';
	}
	return (nLen);
}

/* 将64位无符号整型数显示到字符中去 */
void GetNumString(char *chData, DWORD64 dwData, int bHex)
{
	if(chData == NULL) return;
	if(dwData <= MAXDWORD)
	{
		if(bHex) sprintf(chData, "00000000%08X", (DWORD)dwData);
		else sprintf(chData, "%u", dwData);
	}
	else
	{
		DWORD dwHigh, dwLow;
		if(bHex)
		{
			dwHigh = (DWORD)((dwData >> 32) & 0xFFFFFFFF);
			dwLow = (DWORD)(dwData & 0xFFFFFFFF);
			sprintf(chData, "%08X%08X", dwHigh, dwLow);
		}
		else
		{
			dwHigh = (DWORD)(dwData / 1000000);
			dwLow  = (DWORD)(dwData - dwHigh * (DWORD64)1000000);
			sprintf(chData, "%u%u", dwHigh, dwLow);
		}
	}
}

//=========================================================================//

/* 系统用信息对话框:窗口句柄,按钮类型,信息字符串 */
INT MsgBox(HWND hWnd, UINT uType, LPCTSTR chInfor, ...)
{
	char chTitle[sizeof(TCBOX_TITLE)];
	CryptXOR(chTitle, TCBOX_TITLE, sizeof(TCBOX_TITLE));
	CString sInfor = "";
	if(chInfor && chInfor[0])
	{
		va_list argptr;
		va_start(argptr, chInfor);
		sInfor.FormatV(chInfor, argptr);
		va_end(argptr);
	}
	else sInfor = chTitle;
	return (MessageBox(hWnd, sInfor, chTitle, uType));
}

/* 判断窗口的有效性,若是则保存其屏幕坐标的窗口位置 */
BOOL ReadWndRect(CRect &rc, CWnd *pWnd)
{
	if(!pWnd || !pWnd->m_hWnd) return (FALSE);
	if(pWnd->IsIconic()) return (FALSE);
	pWnd->GetWindowRect(&rc); return (TRUE);
}

/* 将指定的屏幕坐标矩形恢复到指定的窗口,判断有效性 */
BOOL WritWndRect(CRect &rc, CWnd *pWnd, INT nCmd/* = SW_SHOWNORMAL*/)
{
	if(!pWnd || !pWnd->m_hWnd) return (FALSE);
	if(!rc.IsRectEmpty() && !rc.IsRectNull() && \
		rc.Width() >= 32 && rc.Width() <= 4096 &&
		rc.Height() >= 32 && rc.Height() <= 3072)
	{
		CRect src; pWnd->GetWindowRect(&src);
		rc.right = rc.left + src.Width();
		rc.bottom = rc.top + src.Height();
		pWnd->MoveWindow(&rc);
	}
	else pWnd->CenterWindow();
	pWnd->ShowWindow(nCmd); return (TRUE);
}

/* 判断给定的窗口指针,是否是有效的,可见的 */
BOOL IsVisWnd(const CWnd *pWnd)
{
	if(!pWnd || !IsWindow(pWnd->m_hWnd))
		return (FALSE);
	return (pWnd->IsWindowVisible());
}

/////////////////////////////////////////////////////////////////////////////

/* 为指定扩展名,增加子键操作,使用指定程序操作(含命令行) */
BOOL AddRunAtExt(LPCTSTR chExt, LPCTSTR chKey, LPCTSTR chCap, LPCTSTR chRun)
{
	HKEY hKey = NULL; LONG nRet, nLen; 
	DWORD dwRet = 0, dwLen = 0;
	char chXidKey[MAX_PATH * 2];
	
	/*===========================================================*/
	
	/* 1、首先确认.EXT所关联的XID键值,位于默认值 */
	nRet = RegCreateKeyEx(HKEY_CLASSES_ROOT, chExt,
		0L, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,
		NULL, &hKey, &dwRet);
	if(nRet == ERROR_SUCCESS && hKey)
	{
		BOOL bNew = (dwRet == REG_CREATED_NEW_KEY);
		
		if(!bNew) /* 打开已经存在的 */
		{
			dwLen = sizeof(chXidKey);
			nRet = RegQueryValueEx(hKey, "", 0, NULL,
				(BYTE *)chXidKey, &dwLen);
		}
		else /* 原来不存在,现开始创建 */
		{
			dwLen = sprintf(chXidKey, "TCSY.%s", chKey) + 1;
			nRet = RegSetValueEx(hKey, "", 0, REG_SZ,
				(BYTE *)chXidKey, dwLen);
		}
	}
	if(hKey) {RegCloseKey(hKey); hKey = NULL;}
	if(nRet != ERROR_SUCCESS || dwLen <= 1) return (FALSE);
	nLen = dwLen - 1; /* chXidKey键名的字串长度 */
	
	/*===========================================================*/
	
	/* 2、确认所增加的菜单的项目名称,位于默认值 */
	nLen += sprintf(&chXidKey[nLen], "\\shell\\%s", chKey);
	nRet = RegCreateKeyEx(HKEY_CLASSES_ROOT, chXidKey, 0L,
			NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,
			NULL, &hKey, NULL);
	if(nRet == ERROR_SUCCESS && hKey) /* 右键菜单名称 */
	{
		dwLen = lstrlen(chCap) + 1;
		nRet = RegSetValueEx(hKey, "", 0, REG_SZ,
			(BYTE *)chCap, dwLen);
	}
	if(hKey) {RegCloseKey(hKey); hKey = NULL;}
	if(nRet != ERROR_SUCCESS) return (FALSE);
	
	/*===========================================================*/
	
	/* 3、确认此菜单所使用的命令行及参数,位于默认值 */
	sprintf(&chXidKey[nLen], "\\%s", "Command");
	nRet = RegCreateKeyEx(HKEY_CLASSES_ROOT, chXidKey, 0L,
			NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,
			NULL, &hKey, NULL);
	if(nRet == ERROR_SUCCESS && hKey) /* 设置执行命令 */
	{
		char chOrder[MAX_PATH * 2] = "";
		dwLen = sprintf(chOrder, "\"%s\" \"%%1\"", chRun) + 1;
		nRet = RegSetValueEx(hKey, "", 0, REG_SZ,
			(BYTE *)chOrder, dwLen);
	}
	if(hKey) {RegCloseKey(hKey); hKey = NULL;}
	return (nRet == ERROR_SUCCESS); /* 返回是否成功 */
}

/* 为指定扩展名,删除子键操作,即程序不再绑定扩展名的使用 */
BOOL DelRunAtExt(LPCTSTR chExt, LPCTSTR chKey)
{
	HKEY hKey = NULL; LONG nRet, nLen;
	DWORD dwLen = 0;
	char chXidKey[MAX_PATH * 2];
	
	nRet = RegOpenKeyEx(HKEY_CLASSES_ROOT, chExt, 0L,
		KEY_ALL_ACCESS, &hKey);
	if(nRet == ERROR_SUCCESS && hKey) /* 获取子键位置 */
	{
		dwLen = sizeof(chXidKey);
		nRet = RegQueryValueEx(hKey, "", 0, NULL,
			(BYTE *)chXidKey, &dwLen);
	}
	if(hKey) {RegCloseKey(hKey); hKey = NULL;}
	if(nRet != ERROR_SUCCESS || dwLen <= 1) return (FALSE);
	nLen = --dwLen; /* chXidKey键名的字串长度 */
	
	nLen += sprintf(&chXidKey[nLen], "\\shell\\%s", chKey);
	nRet = RegOpenKeyEx(HKEY_CLASSES_ROOT, chXidKey, 0L,
		KEY_ALL_ACCESS, &hKey);
	if(nRet == ERROR_SUCCESS && hKey) /* 删除执行命令 */
		nRet = RegDeleteKey(hKey, "Command");
	if(hKey) {RegCloseKey(hKey); hKey = NULL;}
	if(nRet != ERROR_SUCCESS) return (FALSE);
	nLen = dwLen; /* chXidKey键名的字串长度 */
	
	nLen += lstrCpy(&chXidKey[nLen], "\\shell");
	nRet = RegOpenKeyEx(HKEY_CLASSES_ROOT, chXidKey, 0L,
		KEY_ALL_ACCESS, &hKey);
	if(nRet == ERROR_SUCCESS && hKey) /* 删除子键值 */
		nRet = RegDeleteKey(hKey, chKey);
	if(hKey) {RegCloseKey(hKey); hKey = NULL;}
	return (nRet == ERROR_SUCCESS); /* 返回是否成功 */
}

/* 为指定扩展名,将指定的子键操作,设置为默认的,恢复须备份 */
BOOL DefRunAtExt(LPCTSTR chExt, LPCTSTR chKey, char *chBak)
{
	HKEY hKey = NULL; LONG nRet, nLen;
	DWORD dwLen = 0;
	char chXidKey[MAX_PATH * 2];
	
	nRet = RegOpenKeyEx(HKEY_CLASSES_ROOT, chExt, 0L,
		KEY_ALL_ACCESS, &hKey);
	if(nRet == ERROR_SUCCESS && hKey) /* 获取子键位置 */
	{
		dwLen = sizeof(chXidKey);
		nRet = RegQueryValueEx(hKey, "", 0, NULL,
			(BYTE *)chXidKey, &dwLen);
	}
	if(hKey) {RegCloseKey(hKey); hKey = NULL;}
	if(nRet != ERROR_SUCCESS || dwLen <= 1) return (FALSE);
	nLen = --dwLen; /* chXidKey键名的字串长度 */
	
	nLen += sprintf(&chXidKey[nLen], "\\shell");
	nRet = RegOpenKeyEx(HKEY_CLASSES_ROOT, chXidKey, 0L,
		KEY_ALL_ACCESS, &hKey);
	if(nRet == ERROR_SUCCES

⌨️ 快捷键说明

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