Virtual Developer Workshop: Containerized Development with Docker
Environment: Compiled using VC6.0 Sp3 and tested using Win95/98 WinNT4.0 and Win 2000
To use the CDynamicLED class, you can follow the guidelines stated below.
- Insert a new static frame where you want the LED. Setting the client edge property or the modal frame property for it looks better.
- Rename the static frame to something other than IDC_STATIC. Name it something like IDC_DYN_LED.
- Using the MFC ClassWizard, add a new member variable for IDC__DYN_LED. The category should be a control and the Variable Type should be CDynamicLED. If the CDynamicLED type does not show up in the Variable type dropdown combo, you need to re-create the .clw file. Delete the .clw file and run the class wizard again.
- Remember to add "DynamicLED.h" to your dialog's header file.
The various features in the CDynamicLED Class are outlined below.
- Use the following command:
SetLED( CWnd *pWnd, UINT nIDColor, UINT nIDShape, int nTimerInterval)where pWnd is your static window where you want the LED. nIDColor can be any of the following values:
ID_LED_RED ID_LED_GREEN ID_LED_BLUE ID_LED_YELLOWNIDShape can be any of the following values:
ID_SHAPE_ROUND ID_SHAPE_SQUAREHere, the nIDShape value determines whether the shape of the LED will be round or square.
And the nTimerInterval parameter denotes the number of milliseconds. The LED would flash once in every period denoted by this parameter. You can either have a rapidly blinking LED by setting this parameter to 100 or have a normally blinking LED which blinks once per second by setting this value to 1000.
This is the ONLY function that you need to know to use this class.
- In case you need more functionality to switch on or switch off the LED, you have two functions named:
SwitchOff();These two functions don't need any parameters.
Now, let's go to the implementation of this control in your dialog-based application. I have assumed that you have named your dialog class CMyDialog.
Remember that you have created a variable for this static frame. If you have forgotten about that, please refer to the implementation section above. Assuming that you have named your variable m_dynLEDRed for a LED control which is round in shape, it is going to blink once every half second and which is red in colour.
You have to add the following lines in your OnInitDialog function. I have also assumed that you have named your static frame IDC_STATIC_LED_RED.
CWnd *pWndRed = (CWnd *)GetDlgItem(IDC_STATIC_LED_RED); m_dynLEDRed.SetLED(pWndRed,ID_LED_RED, ID_SHAPE_ROUND,500);
In case you want to change the blinking interval of the LED at runtime from half a second to a full second, you can use the following code.
// Change the time interval of the LED to 1000 CWnd *pWndRed = (CWnd *)GetDlgItem(IDC_STATIC_LED_RED); m_dynLEDRed.SetLED(pWndBlue,ID_LED_BLUE, ID_SHAPE_ROUND,1000);
To change the shape of the LED from round to square or vice versa , you can follow this piece of code.
// Change the shape of the Blue LED from round to square CWnd *pWndRed = (CWnd *)GetDlgItem(IDC_STATIC_LED_RED); m_dynLEDRed.SetLED(pWndBlue,ID_LED_BLUE, ID_SHAPE_SQUARE,1000);
If you want to turn off the LED (I mean switching it off), you can use this.
// Switch OFF the Red LED CWnd *pWndRed = (CWnd *)GetDlgItem(IDC_STATIC_LED_RED); m_dynLEDRed.SwitchOff();
and to switch it on again, use
// Switch ON the Red LED CWnd *pWndRed = (CWnd *)GetDlgItem(IDC_STATIC_LED_RED); m_dynLEDRed.SwitchOn();
That's all, folks. All luck and have a great time.
With warm regards,
DownloadsDownload demo project - 48KB
Download source - 4KB