The study of Programming Windows with MFC--Ip Address control and Date control
2010-08-10 10:21
701 查看
1.Ip Address Control
CIPAddressCtrl m_wndIPAddress;
// In CMyDialog's class declaration
BYTE m_nField1, m_nField2, m_nField3, m_nField4;
BOOL CMyDialog::OnInitDialog ()
{
CDialog::OnInitDialog ();
m_wndIPAddress.SetAddress (m_nField1, m_nField2,
m_nField3, m_nField4);
return TRUE;
}
void CMyDialog::OnOK ()
{
m_wndIPAddress.GetAddress (m_nField1, m_nField2,
m_nField3, m_nField4);
CDialog::OnOK ();
}
m_wndIPAddress.SetFieldRange (0, 10, 100); // Field 1
m_wndIPAddress.SetFieldRange (3, 100, 155); // Field 4
2.HotKey
CHotKeyCtrl m_wndHotkey;
m_wndHotkey.SetHotKey (_T (`P'), HOTKEYF_CONTROL ¦ HOTKEYF_ALT);
WORD wKeyCode, wModifiers;
m_wndHotkey.GetHotKey (wKeyCode, wModifiers);
m_wndHotkey.SetRules (HKCOMB_A ¦ HKCOMB_CA ¦ HKCOMB_SA ¦ HKCOMB_SCA, 0);
2.Month Calendar Controls
CMonthCalCtrl m_wndCal;
m_wndCal.SetCurSel (CTime (1999, 9, 30, 0, 0, 0));
CTime date;
m_wndCal.GetCurSel (date);
Contrary to what the documentation says, a calendar control sometimes returns random data in the hours, minutes, seconds, and milliseconds fields of the SYSTEMTIME structure it uses to divulge dates in response to MCM_GETCURSEL messages. Because CTime factors the time into the dates it obtains from SYSTEMTIME structures, incrementing the day by 1, for example, if hours equals 25, CTime objects initialized by CMonthCalCtrl::GetCurSel can't be trusted. The solution is to retrieve the current date by sending the control an MCM_GETCURSEL message and zeroing the time fields of the SYSTEMTIME structure before converting it into a CTime, as demonstrated here:
This example sets dateStart equal to the selection's start date and dateEnd to the end date. If just one day is selected, dateStart will equal dateEnd. Fortunately, GetSelRange doesn't suffer from the randomness problems that GetCurSel does.
4.Date-Time Picker Controls (DTP controls)
CDateTimeCtrl m_wndDTP;
[/code]
CIPAddressCtrl m_wndIPAddress;
// In CMyDialog's class declaration
BYTE m_nField1, m_nField2, m_nField3, m_nField4;
BOOL CMyDialog::OnInitDialog ()
{
CDialog::OnInitDialog ();
m_wndIPAddress.SetAddress (m_nField1, m_nField2,
m_nField3, m_nField4);
return TRUE;
}
void CMyDialog::OnOK ()
{
m_wndIPAddress.GetAddress (m_nField1, m_nField2,
m_nField3, m_nField4);
CDialog::OnOK ();
}
m_wndIPAddress.SetFieldRange (0, 10, 100); // Field 1
m_wndIPAddress.SetFieldRange (3, 100, 155); // Field 4
2.HotKey
CHotKeyCtrl m_wndHotkey;
m_wndHotkey.SetHotKey (_T (`P'), HOTKEYF_CONTROL ¦ HOTKEYF_ALT);
WORD wKeyCode, wModifiers;
m_wndHotkey.GetHotKey (wKeyCode, wModifiers);
m_wndHotkey.SetRules (HKCOMB_A ¦ HKCOMB_CA ¦ HKCOMB_SA ¦ HKCOMB_SCA, 0);
2.Month Calendar Controls
CMonthCalCtrl m_wndCal;
m_wndCal.SetCurSel (CTime (1999, 9, 30, 0, 0, 0));
CTime date;
m_wndCal.GetCurSel (date);
Contrary to what the documentation says, a calendar control sometimes returns random data in the hours, minutes, seconds, and milliseconds fields of the SYSTEMTIME structure it uses to divulge dates in response to MCM_GETCURSEL messages. Because CTime factors the time into the dates it obtains from SYSTEMTIME structures, incrementing the day by 1, for example, if hours equals 25, CTime objects initialized by CMonthCalCtrl::GetCurSel can't be trusted. The solution is to retrieve the current date by sending the control an MCM_GETCURSEL message and zeroing the time fields of the SYSTEMTIME structure before converting it into a CTime, as demonstrated here:
SYSTEMTIME st; m_wndCal.SendMessage (MCM_GETCURSEL, 0, (LPARAM) &st); st.wHour = st.wMinute = st.wSecond = st.wMilliseconds = 0; CTime date (st); m_wndCal.SetMaxSelCount (14); m_wndCal.SetSelRange (CTime (1999, 9, 30, 0, 0, 0),(1999, 9, 30, 0, 0, 0)); [/code] |
CTime dateStart, dateEnd; m_wndCal.GetSelRange (dateStart, dateEnd); |
4.Date-Time Picker Controls (DTP controls)
CDateTimeCtrl m_wndDTP;
// In CMyDialog's class declaration CTime m_time; BOOL CMyDialog::OnInitDialog () { CDialog::OnInitDialog (); m_wndDTP.SetTime (&m_time); return TRUE; } void CMyDialog::OnOK () { m_wndDTP.GetTime (m_time); CDialog::OnOK (); }
DDX_DateTimeCtrl (pDX, IDC_DTP, m_time); [code]m_wndDTP.SetFormat (_T ("H/':/'mm/':/'ss"));
[/code]
相关文章推荐
- The Study of Programming Windows with MFC--Progress and Animate control
- The Study of Programming Windows with MFC--Imagelist and ComboBoxEx
- The study of chapter 13 in programming windows with mfc-printing with document and views
- The Study of Programming Windows with MFC--Slider,Spin,ToolTip
- The study of Programming Windows with MFC
- The study of Programming Windows with MFC--print's example
- The study of Programming Windows with MFC--BitMap
- The Study of Programming Windows with MFC--Bitmap2
- The study of Programming Windows with MFC-printing tips
- The study of Programming Windows with MFC-Palette
- The study of Programming Windows with MFC--CRgn
- The study of Programming Windows with MFC--Common Control
- the study of programmng windows with mfc--timer
- Test-Driven C# Improve the Design and Flexibility of Your Project with Extreme Programming Techniques
- The Essence of Object-Oriented Programming with Java and UML
- Test-Driven C# Improve the Design and Flexibility of Your Project with Extreme Programming Techniques
- The Introduction of Windows Programming and WTL
- Programming Windows with MFC - Capter 10. Scroll Views, HTML Views, and Other View Types
- Get Local IP Address and Set in the IP Control
- (翻译)Tricks of the windows game programming Gurus(Windows游戏大师之路) --- 前言(作者:ANDRE LAMOTHE 1999)