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

📄 calcborn.cpp

📁 预产期的计算
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/////////////////////////////////////////////////////////////////////////////
// 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

// 构造函数
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	m_sHelps = _T("");
	//}}AFX_DATA_INIT
}

// 数据交换
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()

// 点击左键,可以移动窗体
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));
}

// 关于会话框的初始化窗体
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;
}

/////////////////////////////////////////////////////////////////////////////
// 天诚盛业指纹算法工程常用小算法工具集合  sck007   2006.08.16 Updated     //
/////////////////////////////////////////////////////////////////////////////

/* 释放文件名列表所占有的所有内存空间 */
VOID CDirFileList::RemoveAll(BOOL bFreeAll, BOOL bDelPath)
{
	if(bFreeAll == FALSE) return;					/* 禁止释放空间 */
	if(m_chDirPath && bDelPath)
		{delete[] m_chDirPath; m_chDirPath = NULL;}	/* 释放路径内存 */
	
	m_FileNameList.Rewind(1);						/* 回到链表尾部 */
	for(;;)
	{
		if(!m_FileNameList.Sum()) break;
		if(m_FileNameList()) delete[] m_FileNameList();
		m_FileNameList.Del();						/* 逐点释放资源 */
	}
}

/* 设置目录名称,申请所需空间,拷贝路径串到内部 */
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);			/* 复制到新空间 */
	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));			/* 取文件名列表 */
}

/* 添加文件名到新的节点,可以选择是否排升序,不排序则加到链表尾部 */
BOOL CDirFileList::AddName(LPCTSTR chName, BOOL bSort)
{
	if(!chName || !chName[0]) return (FALSE);
	int nLen = lstrlen(chName) + 1;					/* 多申请'\0'位 */
	
	char *chTemp = new char[nLen];
	if(chTemp == NULL) return (FALSE);				/* 拷贝到临时串 */
	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;						/* 求中点后比较 */
			nRet = lstrcmp(m_FileNameList[cn], chTemp);
			
			if(rt - lf > 1)							/* 至少有1个间隔 */
			{
				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);				/* 追加节点失败 */
}

/* 删存贮当前文件名的节点,释放相关资源 */
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);			/* 删除当前节点 */
}

/* 列出当前已定目录下的文件(目录)名,可选择是否排升序 */
BOOL CDirFileList::ListPathName(BOOL bFile, LPCTSTR chFilter,
								BOOL bSort)
{
	if(!chFilter || !chFilter[0] || !m_chDirPath)	/* 检查环境状态 */
		return (FALSE);
	RemoveAll(TRUE, FALSE); char chFind[MAX_PATH];	/* 释放所有节点 */
	
	int nBase = lstrCpy(chFind, m_chDirPath);		/* 构造搜索条件 */
	lstrcpy(&chFind[nBase], chFilter);
	
	WIN32_FIND_DATA findData; BOOL bDirA;			/* 搜索数据返回 */
	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;	/* 排除两点目录 */
		bDirA = (findData.dwFileAttributes & 0x10) != 0;
		if((bDirA && bFile) || (!bDirA && !bFile))	/* 处理目录名称 */
			continue;
		if(!AddName(findData.cFileName, bSort))		/* 记录到名节点 */
			break;
	}
	while(::FindNextFile(hFindFile, &findData));
	::FindClose(hFindFile); hFindFile = NULL;}		/* 结束遍历循环 */
	return (BOOL)(m_FileNameList.Sum() > 0);		/* 是否找到文件 */
}

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

/* 自定义使用文件操作(打开/保存)对话框,默认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 */
}

/* 明文(字符串):"天诚盛业指纹算法测试验专用工程"=一般加密 */
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
};

/* 获取操作系统中的文件夹(目录)的专用接口类 */
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);	/* 设置状态字串 */
	void EnableOK(BOOL bEnable);		/* 设置OK钮状态 */
	void OnSelChanged(LPARAM lParam);	/* 选择发生改变 */
	
public:
	CSeekFolder();						/* 初始构造函数 */
};

/* 浏览文件夹类,构造函数,初始化内部变量 */
CSeekFolder::CSeekFolder()
{
	m_hWnd = NULL;
	chSlctDir[0] = '\0';
}

/* 初始化会话框首次显示的路径 */
void CSeekFolder::InitSlctPath(LPCTSTR chSlct)
{
	if(!m_hWnd) return;
	SendMessage(m_hWnd, BFFM_SETSELECTION, \
		(WPARAM)TRUE, (LPARAM)chSlct);
}

/* 设置状态条的显示字符串 */
void CSeekFolder::SetStatusTxt(LPCTSTR chStat)
{
	if(!m_hWnd) return;
	SendMessage(m_hWnd, BFFM_SETSTATUSTEXT, \
		(WPARAM)NULL, (LPARAM)chStat);
}

/* 设置OK钮状态,使能或禁止 */
void CSeekFolder::EnableOK(BOOL bEnable)
{
	if(!m_hWnd) return;
	SendMessage(m_hWnd, BFFM_ENABLEOK, \
		(WPARAM)bEnable, (LPARAM)NULL);
}

⌨️ 快捷键说明

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