Week hours planning control






3.33/5 (5 votes)
Aug 7, 2002
1 min read

80898

2233
An article on making a week hours planning control
Introduction
Last week I saw a Windows 2000 server user's management. I have seen in
the session planning a control.
I think that this control is very important for applications which use
planning tasks. And the best use of this control is in
Internet/Network applications. This article demonstrate using of window
messages to create controls. This article uses WM_LBUTTONUP
,
WM_LBUTTONDOWN
, WM_MOUSEMOVE
. And demonstrate how to have a good method
of drawing by repainting only the area
which is modified. This is my first article for Code Project.
Usage
Simply include the header file.
#include "WeekHours.h"
Then you insert in the dialog a static control and enable the notify property (window styles).
And modify the control ID, for e.g. IDC_SESSIONS_PLANNING
(if you
don't modify the
IDC_STATIC
, class wizard won't let you create variable). Then create a variable for this control (the type will be
CStatic
)
change the type to CWeekHours
.
//{{AFX_DATA(CTimeTestDlg) enum { IDD = IDD_TIMETEST_DIALOG }; CWeekHours m_WeekHours; ... ... ... //}}AFX_DATA
To initialize the control
The initialization of the control will be in OnInitDialog
or
constructor of the dialog. The set state order is important.
BOOL CTimeTestDlg::OnInitDialog() { CDialog::OnInitDialog(); ... ... ... // TODO: Add extra initialization here // select a language for the week days m_WeekHours.m_Language = LNG_ENGLISH; // Selection button text m_WeekHours.m_SelBtnText = "Autorised connection"; // Deselection button text m_WeekHours.m_DeSelBtnText = "Refused connection"; // Select the 8 hour in all week days m_WeekHours.SetHourDaysState(8, HST_SELECTED); // Select the 9 hour in all week days m_WeekHours.SetHourDaysState(9, HST_SELECTED); // Select the 10 hour in all week days m_WeekHours.SetHourDaysState(10, HST_SELECTED); // Select the 11 hour in all week days m_WeekHours.SetHourDaysState(11, HST_SELECTED); // Disible the Thursday hours m_WeekHours.SetDayHoursState(5, HST_DESIBLED); // Disible the Friday hours m_WeekHours.SetDayHoursState(6, HST_DESIBLED); }
To get state of hour
Use the function GetHourState(int iDay, int iHour)
to
get the state of the hour. The class provide different functions to
manipulate the state of a hour and block of hours.
// Get state of a hour int GetHourState(int iDay, int iHour); // Set the state of a hour void SetHourState(int iDay, int iHour, int State); // Set the state of the day hours void SetDayHoursState(int iDay, int State); // Set the state of the hour in all week days void SetHourDaysState(int iHours, int State);
Conclusion
This article can show how to create own control from basic MFC window class. And demonstrates how to exploit a simple window message to create controls. If you use this control or you fixed bugs, sending mail for me will be a nice idea. Thanks.