簡(jiǎn)介
我想要這樣一個(gè)控件,既包括標(biāo)準(zhǔn)date picker控件的功能,又能讓用戶任何時(shí)候都能自己輸入日期。標(biāo)準(zhǔn)的date picker控件有其自己的實(shí)現(xiàn)自編輯日期的方法,但是這并沒有達(dá)到我想要的。
文檔
此控件基于微軟的CDateTimeCtrl類,我使用了一些小技巧用我自己的編輯控件和按鈕替換了標(biāo)準(zhǔn)的控件,但是處理類仍繼承于CDateTimeCtrl。為了實(shí)現(xiàn)這個(gè)功能,我銷毀了已存在的窗口,并且創(chuàng)建了一個(gè)與類相關(guān)聯(lián)的我自己的窗口。工作原理參看CDateTimeEditCtrl::OnRecreate。
基于我的實(shí)現(xiàn)方法,這個(gè)控件的使用與標(biāo)準(zhǔn)的CDateTimeCtrl完全一樣。在你的對(duì)話框資源中加入一個(gè)標(biāo)準(zhǔn)的Date picker控件,然后為其創(chuàng)建CDateTimeEditCtrl類型的成員變量。
這個(gè)控件支持通常的Date picker風(fēng)格,下面幾個(gè)風(fēng)格不支持:DTS_UPDOWN, DTS_SHOWNONE, DTS_APPCANPARSE, DTS_LONGDATEFORMAT, and DTS_TIMEFORMAT。
消息傳遞與標(biāo)準(zhǔn)控件一樣,但是不支持DTM_GETRANGE, DTM_SETRANGE和DTM_SETFORMAT消息??丶惺录耐ㄖc標(biāo)準(zhǔn)控件一樣,發(fā)送給父窗口。
一些額外的公有函數(shù)也被加入以提供更強(qiáng)的功能擴(kuò)展,這些公有函數(shù)列表如下:
BOOL Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID);
與CDateTimeCtrl功能類似.
CEdit* GetEditControl() const;
返回一個(gè)指向編輯控件的指針,通過(guò)這個(gè)指針可以直接處理它的屬性。
void EnableButton(BOOL bEnable = TRUE);
允許或禁止用來(lái)下拉calendar control的按鈕
void RestoreFocus(BOOL bRestore = TRUE);
Determines the behaviour when clicking on the button. If TRUE then the control re-sets the focus back to the window whitch had the focus on clicking the button, else the focus is set to the edit control. If the control is not editable focus is always set back to the previously focused window. The default is for the focus to be set to the edit control.
void SetNonEditable(BOOL bNonEditable = TRUE);
Used to make the edit portion of the control non-editable. The default is editable.
BOOL GetNonEditable();
Returns whether the edit control is currently editable.
virtual BOOL IsValidDate(LPCTSTR lpszDate = NULL);
Returns whether the date string passed is valid. If lpszDate is NULL then it returns whether the text in the edit control is a valid date string.
void SetValidCharsOnly(BOOL bValidCharsOnly = TRUE);
Sets whether the user can only enter characters that are valid
BOOL GetValidCharsOnly();
Returns whether the user can only enter valid characters into the edit control
void SetValidChars(LPCTSTR lpszValidChars = NULL);
Sets the characters that are valid for the user to type into the edit control. If NULL is specified, then the default characters are used (0-9 and the current user's locale's date separator). If the user changes the locale settings then the control will detect this and use the new separator.
CString GetValidChars();
Returns the characters that have been set as being valid for the user to type into the edit control
void SetAllowUpDownKeys(BOOL bAllow = TRUE);
Sets whether the up/down arrow keys will increment/decrement the part of the date string that contains the cursor.
BOOL GetAllowUpDownKeys();
Returns whether the up/down keys will increment/decrement parts of the date string.
我想要這樣一個(gè)控件,既包括標(biāo)準(zhǔn)date picker控件的功能,又能讓用戶任何時(shí)候都能自己輸入日期。標(biāo)準(zhǔn)的date picker控件有其自己的實(shí)現(xiàn)自編輯日期的方法,但是這并沒有達(dá)到我想要的。
文檔
此控件基于微軟的CDateTimeCtrl類,我使用了一些小技巧用我自己的編輯控件和按鈕替換了標(biāo)準(zhǔn)的控件,但是處理類仍繼承于CDateTimeCtrl。為了實(shí)現(xiàn)這個(gè)功能,我銷毀了已存在的窗口,并且創(chuàng)建了一個(gè)與類相關(guān)聯(lián)的我自己的窗口。工作原理參看CDateTimeEditCtrl::OnRecreate。
基于我的實(shí)現(xiàn)方法,這個(gè)控件的使用與標(biāo)準(zhǔn)的CDateTimeCtrl完全一樣。在你的對(duì)話框資源中加入一個(gè)標(biāo)準(zhǔn)的Date picker控件,然后為其創(chuàng)建CDateTimeEditCtrl類型的成員變量。
這個(gè)控件支持通常的Date picker風(fēng)格,下面幾個(gè)風(fēng)格不支持:DTS_UPDOWN, DTS_SHOWNONE, DTS_APPCANPARSE, DTS_LONGDATEFORMAT, and DTS_TIMEFORMAT。
消息傳遞與標(biāo)準(zhǔn)控件一樣,但是不支持DTM_GETRANGE, DTM_SETRANGE和DTM_SETFORMAT消息??丶惺录耐ㄖc標(biāo)準(zhǔn)控件一樣,發(fā)送給父窗口。
一些額外的公有函數(shù)也被加入以提供更強(qiáng)的功能擴(kuò)展,這些公有函數(shù)列表如下:
BOOL Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID);
與CDateTimeCtrl功能類似.
CEdit* GetEditControl() const;
返回一個(gè)指向編輯控件的指針,通過(guò)這個(gè)指針可以直接處理它的屬性。
void EnableButton(BOOL bEnable = TRUE);
允許或禁止用來(lái)下拉calendar control的按鈕
void RestoreFocus(BOOL bRestore = TRUE);
Determines the behaviour when clicking on the button. If TRUE then the control re-sets the focus back to the window whitch had the focus on clicking the button, else the focus is set to the edit control. If the control is not editable focus is always set back to the previously focused window. The default is for the focus to be set to the edit control.
void SetNonEditable(BOOL bNonEditable = TRUE);
Used to make the edit portion of the control non-editable. The default is editable.
BOOL GetNonEditable();
Returns whether the edit control is currently editable.
virtual BOOL IsValidDate(LPCTSTR lpszDate = NULL);
Returns whether the date string passed is valid. If lpszDate is NULL then it returns whether the text in the edit control is a valid date string.
void SetValidCharsOnly(BOOL bValidCharsOnly = TRUE);
Sets whether the user can only enter characters that are valid
BOOL GetValidCharsOnly();
Returns whether the user can only enter valid characters into the edit control
void SetValidChars(LPCTSTR lpszValidChars = NULL);
Sets the characters that are valid for the user to type into the edit control. If NULL is specified, then the default characters are used (0-9 and the current user's locale's date separator). If the user changes the locale settings then the control will detect this and use the new separator.
CString GetValidChars();
Returns the characters that have been set as being valid for the user to type into the edit control
void SetAllowUpDownKeys(BOOL bAllow = TRUE);
Sets whether the up/down arrow keys will increment/decrement the part of the date string that contains the cursor.
BOOL GetAllowUpDownKeys();
Returns whether the up/down keys will increment/decrement parts of the date string.

