123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- // TestDlg.cpp : 实现文件
- //
- #include "stdafx.h"
- #include "Test.h"
- #include "TestDlg.h"
- #include "CalendarEx.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #endif
- #if 1
- typedef INT (*GetLunarDate)(OUT LPTSTR ,IN const int &, IN const int &, IN const int &);
- typedef BOOL (*LuanrToSolarDate)(OUT LPTSTR ,IN const int &, IN const int &, IN const int &, BOOL);
- #else
- typedef INT (__stdcall *GetLunarDate)(OUT LPTSTR ,IN const int &, IN const int &, IN const int &);
- typedef BOOL (__stdcall *LuanrToSolarDate)(OUT LPTSTR ,IN const int &, IN const int &, IN const int &, BOOL);
- #endif
- GetLunarDate g_GetLunarDate;
- LuanrToSolarDate g_LuanrToSolarDate;
- // 用于应用程序“关于”菜单项的 CAboutDlg 对话框
- class CAboutDlg : public CDialog
- {
- public:
- CAboutDlg();
- // 对话框数据
- enum { IDD = IDD_ABOUTBOX };
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
- // 实现
- protected:
- DECLARE_MESSAGE_MAP()
- };
- CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
- {
- }
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- }
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- END_MESSAGE_MAP()
- // CTestDlg 对话框
- CTestDlg::CTestDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CTestDlg::IDD, pParent)
- {
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
- void CTestDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- DDX_Control(pDX, IDC_DATETIMEPICKER1, m_ctlDT);
- }
- BEGIN_MESSAGE_MAP(CTestDlg, CDialog)
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- //}}AFX_MSG_MAP
- ON_BN_CLICKED(IDC_BUTTON1, &CTestDlg::OnBnClickedButton1)
- ON_BN_CLICKED(IDC_BUTTON2, &CTestDlg::OnBnClickedButton2)
- ON_BN_CLICKED(IDC_CHECK1, &CTestDlg::OnBnClickedCheck1)
- ON_BN_CLICKED(BT_GETAGE, &CTestDlg::OnBnClickedGetage)
- END_MESSAGE_MAP()
- // CTestDlg 消息处理程序
- BOOL CTestDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // 将“关于...”菜单项添加到系统菜单中。
- // IDM_ABOUTBOX 必须在系统命令范围内。
- ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
- ASSERT(IDM_ABOUTBOX < 0xF000);
- CMenu* pSysMenu = GetSystemMenu(FALSE);
- if (pSysMenu != NULL)
- {
- BOOL bNameValid;
- CString strAboutMenu;
- bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
- ASSERT(bNameValid);
- if (!strAboutMenu.IsEmpty())
- {
- pSysMenu->AppendMenu(MF_SEPARATOR);
- pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
- }
- }
- // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
- // 执行此操作
- SetIcon(m_hIcon, TRUE); // 设置大图标
- SetIcon(m_hIcon, FALSE); // 设置小图标
- SetDlgItemText(ET_LUNAR_BRITHDAY,_T("2014-11-22"));
- // TODO: 在此添加额外的初始化代码
- LoadMyDllLibrary();
- return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
- }
- void CTestDlg::OnSysCommand(UINT nID, LPARAM lParam)
- {
- if ((nID & 0xFFF0) == IDM_ABOUTBOX)
- {
- CAboutDlg dlgAbout;
- dlgAbout.DoModal();
- }
- else
- {
- CDialog::OnSysCommand(nID, lParam);
- }
- }
- // 如果向对话框添加最小化按钮,则需要下面的代码
- // 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
- // 这将由框架自动完成。
- void CTestDlg::OnPaint()
- {
- if (IsIconic())
- {
- CPaintDC dc(this); // 用于绘制的设备上下文
- SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
- // 使图标在工作区矩形中居中
- int cxIcon = GetSystemMetrics(SM_CXICON);
- int cyIcon = GetSystemMetrics(SM_CYICON);
- CRect rect;
- GetClientRect(&rect);
- int x = (rect.Width() - cxIcon + 1) / 2;
- int y = (rect.Height() - cyIcon + 1) / 2;
- // 绘制图标
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
- CDialog::OnPaint();
- }
- }
- //当用户拖动最小化窗口时系统调用此函数取得光标
- //显示。
- HCURSOR CTestDlg::OnQueryDragIcon()
- {
- return static_cast<HCURSOR>(m_hIcon);
- }
- void CTestDlg::OnBnClickedButton1() // 公历转农历;
- {
- // TODO: 在此添加控件通知处理程序代码
- COleDateTime oleDT;
- m_ctlDT.GetTime(oleDT);
- int nYear = oleDT.GetYear();
- int nMonth = oleDT.GetMonth();
- int nDay = oleDT.GetDay();
- CString strLunarDate;
- TCHAR szLunarDate[11] = {0};
- //if(g_GetLunarDate(szLunarDate, nYear,nMonth,nDay) != 0)
- if ( !CalendarEx::SolarToLuanrDate(nYear, nMonth, nDay, szLunarDate))
- {
- AfxMessageBox(_T("出错"));
- return;
- }
- SetDlgItemText(Edit_Lunar,szLunarDate);
- }
- void CTestDlg::OnBnClickedButton2() // 农历转公历;
- {
- // TODO: 在此添加控件通知处理程序代码
- CString strLunarDate;
- GetDlgItemText(Edit_LunarDate,strLunarDate);
- int nYear = _ttoi(strLunarDate.Left(4));
- int nMonth = _ttoi(strLunarDate.Mid(5, 2));
- int nDay = _ttoi(strLunarDate.Mid(8, 2));
- TCHAR szSolarDate[11] = {0};
- //if(g_LuanrToSolarDate(szSolarDate,nYear,nMonth,nDay,m_IsLeapMonth) == FALSE)
- if ( !CalendarEx::LuanrToSolarDate(nYear, nMonth, nDay, szSolarDate, m_IsLeapMonth))
- {
- AfxMessageBox(_T("出错"));
- return;
- }
- SetDlgItemText(Edit_Solar,szSolarDate);
- }
- void CTestDlg::LoadMyDllLibrary()
- {
- m_MyDllModule = LoadLibrary(_T("LunarCalendar.dll"));
- DWORD dwEr = 0;
- if (m_MyDllModule == NULL)
- {
- dwEr = GetLastError();
- CString strShow;
- strShow.Format(_T(".初始化动态加失败(%d),请检查文件是否存在或损坏..."), dwEr);
- return;
- }
- // 2.加载全部需要的方法;
- g_GetLunarDate = (GetLunarDate)::GetProcAddress(m_MyDllModule, "GetLunarDate");
- g_LuanrToSolarDate = (LuanrToSolarDate)::GetProcAddress(m_MyDllModule, "LuanrToSolarDate");
- }
- void CTestDlg::FreeMyDllLibrary()
- {
- if (m_MyDllModule != NULL)
- {
- FreeLibrary(m_MyDllModule);
- }
- }
- void CTestDlg::OnBnClickedCheck1()
- {
- // TODO: 在此添加控件通知处理程序代码
- if ( ((CButton*)GetDlgItem(IDC_CHECK1))->GetCheck())
- {
- m_IsLeapMonth = TRUE;
- }
- else
- m_IsLeapMonth = FALSE;
-
- }
- void CTestDlg::OnBnClickedGetage()
- {
- // TODO: 在此添加控件通知处理程序代码
- CString strLunarBrithday;
- GetDlgItemText(ET_LUNAR_BRITHDAY, strLunarBrithday);
- INT nAge = CalendarEx::GetAge(strLunarBrithday.GetString(), m_IsLeapMonth);
- if ( nAge != -1 )
- {
- SetDlgItemInt(ET_AGE, nAge);
- }
- }
|