?? calcborn.cpp
字號:
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 + -