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
.
enum { IDD = IDD_TIMETEST_DIALOG };
CWeekHours m_WeekHours;
...
...
...
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();
...
...
...
m_WeekHours.m_Language = LNG_ENGLISH;
m_WeekHours.m_SelBtnText = "Autorised connection";
m_WeekHours.m_DeSelBtnText = "Refused connection";
m_WeekHours.SetHourDaysState(8, HST_SELECTED);
m_WeekHours.SetHourDaysState(9, HST_SELECTED);
m_WeekHours.SetHourDaysState(10, HST_SELECTED);
m_WeekHours.SetHourDaysState(11, HST_SELECTED);
m_WeekHours.SetDayHoursState(5, HST_DESIBLED);
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.
int GetHourState(int iDay, int iHour);
void SetHourState(int iDay, int iHour, int State);
void SetDayHoursState(int iDay, int State);
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.