?? datetime.cpp
字號:
// datetime.cpp : DDX_FieldDateTime的執(zhí)行代碼
#include "stdafx.h"
#include "datetime.h"
void AFXAPI DDX_FieldDateTime(CDataExchange* pDX, int nIDC, CTime ts, CRecordset* pSet )
{
//下面Edit控件的HWND是為DDX 或DDV作準備的
HWND hWndCtrl = pDX->PrepareEditCtrl(nIDC);
if(pDX->m_bSaveAndValidate)
{
if (!GetDateTime(hWndCtrl, ts))
{
//不能得到日期和時間;
AfxMessageBox("無效時間");
pDX->Fail();
}
}
else
{
SetDateTime(hWndCtrl, ts);
}
}
BOOL GetDateTime(CWnd* pWnd, CTime ts)
{
ASSERT(pWnd != NULL);
return GetDateTime(pWnd->m_hWnd, ts);
}
//從Edit box中取得日期和時間值
BOOL GetDateTime(HWND hWnd, CTime ts)
{
const int DATETIME_SIZE = 64;
char sBuffer[DATETIME_SIZE+1];
CString strBuffer;
COleDateTime datetime;
::GetWindowText(hWnd, sBuffer, DATETIME_SIZE);
//從Edit box取值
strBuffer = sBuffer;
if(strBuffer.IsEmpty())
{
ts.GetCurrentTime();
return TRUE;
}
// 注意ParseDateTime是幫助你測試日期和時間和時間完整性的
datetime.ParseDateTime(strBuffer, LOCALE_NOUSEROVERRIDE, LANG_USER_DEFAULT );
if( datetime.GetStatus() == COleDateTime::valid)
{
CTime tyj2( datetime.GetYear(),datetime.GetMonth(), datetime.GetDay(),datetime.GetHour(), datetime.GetMinute(), datetime.GetSecond());
//再傳回來
ts=tyj2;
return TRUE;
}
else
return FALSE;
}
void SetDateTime(CWnd* pWnd, CTime ts)
{
ASSERT(pWnd != NULL);
SetDateTime(pWnd->m_hWnd, ts);
}
//用于顯示日期和時間值到Edit box
void SetDateTime(HWND hWnd, CTime ts)
{
COleDateTime datetime( ts.GetYear(), ts.GetMonth(), ts.GetDay(), ts.GetHour(), ts.GetMinute(), ts.GetSecond());
CString sBuffer;
sBuffer = datetime.Format("%c");
//如果日期和時間值無效的話為空字符
if( datetime.GetStatus() == COleDateTime::invalid )
sBuffer = "";
::SetWindowText(hWnd, sBuffer.GetBufferSetLength(sBuffer.GetLength()));
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -