?? calcborn.cpp
字號(hào):
/////////////////////////////////////////////////////////////////////////////
// CalcBorn.cpp : Defines the class behaviors for the application.
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "CalcBorn.h"
#include "CalcBornDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
// 構(gòu)造函數(shù)
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
m_sHelps = _T("");
//}}AFX_DATA_INIT
}
// 數(shù)據(jù)交換
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
DDX_Text(pDX, IDC_EDIT_HELPS, m_sHelps);
//}}AFX_DATA_MAP
}
// 消息映射
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
ON_WM_LBUTTONDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// 點(diǎn)擊左鍵,可以移動(dòng)窗體
void CAboutDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
CDialog::OnLButtonDown(nFlags, point);
SetCursor(LoadCursor(NULL, IDC_SIZEALL));
PostMessage(WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(point.x, point.y));
}
// 關(guān)于會(huì)話框的初始化窗體
BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CString s; GetDlgItemText(IDC_VERS, s);
s += " - ["; s += SYS_UPD_DATE; s += ']';
SetDlgItemText(IDC_VERS, s);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
/////////////////////////////////////////////////////////////////////////////
// CCalcBornApp
BEGIN_MESSAGE_MAP(CCalcBornApp, CWinApp)
//{{AFX_MSG_MAP(CCalcBornApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCalcBornApp construction
CCalcBornApp::CCalcBornApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CCalcBornApp object
CCalcBornApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CCalcBornApp initialization
BOOL CCalcBornApp::InitInstance()
{
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
CCalcBornDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
/////////////////////////////////////////////////////////////////////////////
// 天誠盛業(yè)指紋算法工程常用小算法工具集合 sck007 2006.08.16 Updated //
/////////////////////////////////////////////////////////////////////////////
/* 釋放文件名列表所占有的所有內(nèi)存空間 */
VOID CDirFileList::RemoveAll(BOOL bFreeAll, BOOL bDelPath)
{
if(bFreeAll == FALSE) return; /* 禁止釋放空間 */
if(m_chDirPath && bDelPath)
{delete[] m_chDirPath; m_chDirPath = NULL;} /* 釋放路徑內(nèi)存 */
m_FileNameList.Rewind(1); /* 回到鏈表尾部 */
for(;;)
{
if(!m_FileNameList.Sum()) break;
if(m_FileNameList()) delete[] m_FileNameList();
m_FileNameList.Del(); /* 逐點(diǎn)釋放資源 */
}
}
/* 設(shè)置目錄名稱,申請(qǐng)所需空間,拷貝路徑串到內(nèi)部 */
BOOL CDirFileList::SetPath(LPCTSTR chPath, LPCTSTR chFilter)
{
if(!chPath || !chPath[0]) return (FALSE); /* 是否為有效參 */
int nLen = lstrlen(chPath);
if(m_chDirPath) delete[] m_chDirPath; /* 除舊迎新分配 */
m_chDirPath = new char[nLen + 2];
if(m_chDirPath == NULL) return (FALSE); /* 復(fù)制到新空間 */
memcpy(m_chDirPath, chPath, nLen + 1);
if(chPath[nLen - 1] != '\\') /* 末位添加'\\' */
{m_chDirPath[nLen++] = '\\'; m_chDirPath[nLen] = '\0';}
if(!chFilter || !chFilter[0]) return (TRUE);
return (ListPathFile(chFilter, TRUE)); /* 取文件名列表 */
}
/* 添加文件名到新的節(jié)點(diǎn),可以選擇是否排升序,不排序則加到鏈表尾部 */
BOOL CDirFileList::AddName(LPCTSTR chName, BOOL bSort)
{
if(!chName || !chName[0]) return (FALSE);
int nLen = lstrlen(chName) + 1; /* 多申請(qǐng)'\0'位 */
char *chTemp = new char[nLen];
if(chTemp == NULL) return (FALSE); /* 拷貝到臨時(shí)串 */
memcpy(chTemp, chName, nLen);
if(bSort) _strupr(chTemp); /* 變成大寫字串 */
if(m_FileNameList.Sum() == 0 || !bSort) /* 直接追尾添加 */
{
if(m_FileNameList.Add(chTemp)) return (TRUE);
}
else /* 二分排序追加 */
{
LONG lf = 0, rt = m_FileNameList.Sum() - 1;
LONG cn = -1, bType = 1, nRet; /* 0前 后1 插入 */
for(;;)
{
cn = (lf + rt) / 2; /* 求中點(diǎn)后比較 */
nRet = lstrcmp(m_FileNameList[cn], chTemp);
if(rt - lf > 1) /* 至少有1個(gè)間隔 */
{
if(nRet > 0) rt = cn; else lf = cn;
}
else /* 左右緊緊相鄰 */
{
if(rt != lf && nRet <= 0)
nRet = lstrcmp(m_FileNameList[rt], chTemp);
bType = (nRet > 0) ? 0 : 1; break; /* 確定插入位置 */
}
}
if(m_FileNameList.Ins(chTemp, bType, 1)) return (TRUE);
}
delete[] chTemp; return (FALSE); /* 追加節(jié)點(diǎn)失敗 */
}
/* 刪存貯當(dāng)前文件名的節(jié)點(diǎn),釋放相關(guān)資源 */
BOOL CDirFileList::DelCurr(VOID)
{
if(m_bAlowFreeAll == FALSE) return (FALSE); /* 不處理空鏈表 */
if(!m_FileNameList.Sum()) return (FALSE);
if(m_FileNameList()) delete[] m_FileNameList();
m_FileNameList.Del(1); return (TRUE); /* 刪除當(dāng)前節(jié)點(diǎn) */
}
/* 列出當(dāng)前已定目錄下的文件(目錄)名,可選擇是否排升序 */
BOOL CDirFileList::ListPathName(BOOL bFile, LPCTSTR chFilter,
BOOL bSort)
{
if(!chFilter || !chFilter[0] || !m_chDirPath) /* 檢查環(huán)境狀態(tài) */
return (FALSE);
RemoveAll(TRUE, FALSE); char chFind[MAX_PATH]; /* 釋放所有節(jié)點(diǎn) */
int nBase = lstrCpy(chFind, m_chDirPath); /* 構(gòu)造搜索條件 */
lstrcpy(&chFind[nBase], chFilter);
WIN32_FIND_DATA findData; BOOL bDirA; /* 搜索數(shù)據(jù)返回 */
memset(&findData, 0, sizeof(findData));
HANDLE hFindFile = NULL; /* 搜索專用句柄 */
hFindFile = ::FindFirstFile(chFind, &findData);
if(hFindFile != INVALID_HANDLE_VALUE) { /* 所有文件遍歷 */
do
{
if(!lstrcmp(findData.cFileName, ".") || !lstrcmp( \
findData.cFileName, "..")) continue; /* 排除兩點(diǎn)目錄 */
bDirA = (findData.dwFileAttributes & 0x10) != 0;
if((bDirA && bFile) || (!bDirA && !bFile)) /* 處理目錄名稱 */
continue;
if(!AddName(findData.cFileName, bSort)) /* 記錄到名節(jié)點(diǎn) */
break;
}
while(::FindNextFile(hFindFile, &findData));
::FindClose(hFindFile); hFindFile = NULL;} /* 結(jié)束遍歷循環(huán) */
return (BOOL)(m_FileNameList.Sum() > 0); /* 是否找到文件 */
}
//=========================================================================//
/* 自定義使用文件操作(打開/保存)對(duì)話框,默認(rèn)BMP過濾 */
BOOL ShowFileDialog(HWND hWnd, BOOL bOpen, char *chFile,
LPCTSTR chFilter/* = NULL */)
{
char chFxlter[MAX_PATH] = "8-Bits Gray Win32 Bitmaps"
" (*.BmP)\0*.BmP\0\0";
char chExtsn[5] = "BmP";
OPENFILENAME ofn; /* infor exch */
if(!chFile) return (FALSE);
memset(&ofn, 0, sizeof(ofn));
if(chFilter && chFilter[0]) /* cnvt & extn */
{
LPCTSTR s = chFilter, q = s;
char *p = chFxlter;
do
{
if(*s != '|')
{
*p = *s;
if(*s == '.') q = s;
}
else *p = '\0';
if(++p - chFxlter >= MAX_PATH - 2)
{
*(p++) = '\0'; *p = '\0'; break;
}
}
while(*(s++) != '\0');
lstrcpyn(chExtsn, q + 1, 4);
}
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hWnd; /* init struct */
ofn.hInstance = NULL;
ofn.lpstrFilter = chFxlter;
ofn.lpstrCustomFilter = NULL;
ofn.nMaxCustFilter = 0;
ofn.nFilterIndex = 0;
ofn.lpstrFile = chFile;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.lpstrTitle = NULL;
ofn.Flags = bOpen ? OFN_FILEMUSTEXIST : OFN_OVERWRITEPROMPT;
LPCTSTR chCurr = chFile, chRec = chCurr;
while(*chCurr) {if(*(chCurr++) == '\\') chRec = chCurr;}
ofn.nFileOffset = chRec - chFile; /* name */
chCurr = chFile; chRec = chCurr;
while(*chCurr) {if(*(chCurr++) == '.') chRec = chCurr;}
ofn.nFileExtension = chRec - chFile; /* extn */
ofn.lpstrDefExt = chExtsn;
ofn.lCustData = 0;
ofn.lpfnHook = NULL; /* no hook and template */
ofn.lpTemplateName = NULL;
return (bOpen ? (::GetOpenFileName(&ofn) != 0) : \
(::GetSaveFileName(&ofn) != 0)); /* ret */
}
/* 明文(字符串):"天誠盛業(yè)指紋算法測(cè)試驗(yàn)專用工程"=一般加密 */
static const BYTE TCBOX_TITLE[] =
{
0x69, 0x49, 0x16, 0x6A, 0x6F, 0x07, 0x77, 0x10, 0x73, 0x1D,
0x6B, 0x63, 0x6E, 0x46, 0x12, 0x0D, 0x17, 0x47, 0x6F, 0x71,
0x74, 0x4C, 0x72, 0x0D, 0x76, 0x66, 0x1C, 0x01, 0x16, 0x69, 0xA5
};
/* 獲取操作系統(tǒng)中的文件夾(目錄)的專用接口類 */
class CSeekFolder
{
friend int CALLBACK BrowseCallbackProc(HWND hWnd,
UINT uMsg, LPARAM lParam, LPARAM lpData);
friend BOOL ShowFolderDialog(HWND hWnd, char *chDir,
LPCTSTR chHit);
HWND m_hWnd; /* 瀏覽窗口句柄 */
BROWSEINFO m_bi; /* 瀏覽信息配置 */
char chSlctDir[MAX_PATH]; /* 用戶所選目錄 */
void InitSlctPath(LPCTSTR chSlct); /* 初始化首選值 */
void SetStatusTxt(LPCTSTR chStat); /* 設(shè)置狀態(tài)字串 */
void EnableOK(BOOL bEnable); /* 設(shè)置OK鈕狀態(tài) */
void OnSelChanged(LPARAM lParam); /* 選擇發(fā)生改變 */
public:
CSeekFolder(); /* 初始構(gòu)造函數(shù) */
};
/* 瀏覽文件夾類,構(gòu)造函數(shù),初始化內(nèi)部變量 */
CSeekFolder::CSeekFolder()
{
m_hWnd = NULL;
chSlctDir[0] = '\0';
}
/* 初始化會(huì)話框首次顯示的路徑 */
void CSeekFolder::InitSlctPath(LPCTSTR chSlct)
{
if(!m_hWnd) return;
SendMessage(m_hWnd, BFFM_SETSELECTION, \
(WPARAM)TRUE, (LPARAM)chSlct);
}
/* 設(shè)置狀態(tài)條的顯示字符串 */
void CSeekFolder::SetStatusTxt(LPCTSTR chStat)
{
if(!m_hWnd) return;
SendMessage(m_hWnd, BFFM_SETSTATUSTEXT, \
(WPARAM)NULL, (LPARAM)chStat);
}
/* 設(shè)置OK鈕狀態(tài),使能或禁止 */
void CSeekFolder::EnableOK(BOOL bEnable)
{
if(!m_hWnd) return;
SendMessage(m_hWnd, BFFM_ENABLEOK, \
(WPARAM)bEnable, (LPARAM)NULL);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -