Click here to Skip to main content
15,867,834 members
Articles / Desktop Programming / MFC
Article

Week hours planning control

Rate me:
Please Sign up or sign in to vote.
3.33/5 (5 votes)
6 Aug 20021 min read 80.1K   2.2K   32   11
An article on making a week hours planning control

Image 1

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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Algeria Algeria
ASM, C/C++, JAVA, PERL, PHP, PASCAL, data base, and victorial drawing Programmer. Live in Algeria.
Now i work in a company with VB 6 and SQl Server. I am interested by OOP using UML.

Comments and Discussions

 
GeneralIn C# Pin
canozurdo7-Mar-07 9:21
canozurdo7-Mar-07 9:21 
GeneralRe: In C# Pin
pita200024-Mar-07 10:21
pita200024-Mar-07 10:21 
GeneralIt's a great control... Pin
JinHyuck Jung.2-Jun-04 19:32
JinHyuck Jung.2-Jun-04 19:32 
GeneralRe: It's a great control... Pin
Mourad DEBBAH16-Sep-04 2:02
Mourad DEBBAH16-Sep-04 2:02 
Generalhelp me Pin
hongge13-Jul-03 15:39
hongge13-Jul-03 15:39 
GeneralSpelling Pin
ColinDavies12-Feb-03 22:12
ColinDavies12-Feb-03 22:12 
GeneralRe: Spelling Pin
The Computer Whisperer18-Feb-03 8:44
The Computer Whisperer18-Feb-03 8:44 
GeneralRe: Spelling Pin
ColinDavies18-Feb-03 9:04
ColinDavies18-Feb-03 9:04 
GeneralRe: Spelling Pin
Thomas West7-Jul-03 5:49
Thomas West7-Jul-03 5:49 
GeneralRedrawing problems Pin
Francisco José Sen del Prado12-Aug-02 2:29
Francisco José Sen del Prado12-Aug-02 2:29 
GeneralRe: Redrawing problems Pin
Mourad DEBBAH12-Aug-02 21:55
Mourad DEBBAH12-Aug-02 21:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.