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:
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)); |
CTime dateStart, dateEnd; m_wndCal.GetSelRange (dateStart, dateEnd); |
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;
// 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);m_wndDTP.SetFormat (_T ("H/':/'mm/':/'ss"));