Introduction to digitaldevice encapsulation for digital simulation instruments

Source: Internet
Author: User
Body
To use this class, add the digitaldevice. h and digitaldevice. cpp files to the project. Add # include "digitaldevice. H" to the header file of the class to be used.
I. Introduction to Classes
This class is derived from the cstatic class, which is actually a complete subwindow. It can simulate any number of digits of the digital display, and display numbers 0 ~ 9, minus sign, colon and decimal point. It can work in two ways: dd_string (string mode) or dd_number (numeric mode ). When the numeric mode is used, the user can call the dd_setcurrentnumber (double num) function to set the value to be displayed on the digital screen, which can display numbers, decimal points, and negative numbers. When the string mode is used, you can call the dd_setcurrentstring (cstring string) function to set the string to be displayed. Besides displaying numbers, decimal points, and negative numbers, you can also display colons and spaces, this is suitable for displaying a clock. In fact, when the meter is set to dd_string mode and in the self-check status, the meter is a clock accurate to seconds. To set the working mode of the Instrument, call the dd_setworkmode (uint mode) function. The mode value can only be dd_number or dd_string.
You can use the dd_setbits (uint bits) function to dynamically set the number of digits displayed on the digital screen. Make sure that the size of the digital screen can be displayed. Otherwise, too many digits will be cropped. You can use the dd_setsize (uint width, uint height) function to set the size of a digital screen. You can use the dd_settextstyle (uint charwidth, uint charheight, uint charthick, uint charspace) function to set the style of each display bit. The charwidth is the character width, and the charheight is the character height, charthick is the width of a character stroke, and charspace is the spacing between characters. The dd_settextpos (int x, int y) function can set the position of the character relative to the upper left corner of the display.
The instrument has the following states:
Dd_test: The self-check status of the instrument. The number automatically changes. It is a clock in the dd_string mode.
Dd_work: the working status of the instrument, which is also the default status when it is created. Wait for the value or string to change.
Dd_shutdown: the shutdown status of the meter. No action is taken.
You can call the dd_setstatus (uint status) function to switch the meter to the preceding status.
The dd_setbdcolor (colorref lightcolor, colorref darkcolor) function can be used to set the color of the 3D border of the instrument. The parameter lightcolor is the color of the highlighted border, and darkcolor is the color of the dark border. The dd_setborderwidth (uint width) function can set the Border width. The dd_setborderstyle (uint left, uint top, uint right, uint bottom) function allows you to set the border style. Each parameter determines whether the left, top, right, and bottom borders are displayed, 1 is displayed, and 0 is not displayed. Setting some borders to do not display is often used for display combination. An example of a display combination is displayed. The three displays are combined in appearance by adjusting the position and display of individual boundaries, just like a display.

The dd_setbkcolor (colorref color) function can set the background color of the display. The default value is black. To set the color of a digital text, call the dd_settextlightcolor (colorref color) function. To set the color of a digital data output, call the dd_settextdarkcolor (colorref color) function.
When a gauge is created, the default position is in the upper left corner of the form. You can use the dd_movewindow (int x, int y) function to move it to the desired position.

II. Application Examples
The following example shows how to use this class.
Now we use the digitaldevice class in the dialog box-based program to create a Timer Program. Add the following code to the header file ccontroltestdlg. H of the dialog box class:
# Include "digitaldevice. H"
..................
Class ctimewatchdlg: Public cdialog
{
// Construction
Public:
Digitaldevice * m_dd;
...............
}
Then, add a simple code in the oninitdialog () function of the CPP file of the dialog box class:
M_dd = new digitaldevice (this );
In this way, an instance of the digitaldevice class is successfully created. It has the default parameters and the default Interface (here it is a clock), and will be correctly displayed in the upper left corner of the dialog box. Then we can set different parameters to make it have different attributes.
The following code creates a 7-digit display on the right.
M_dd-> dd_setsize (117, 32); // you can specify the display size.
M_dd-> dd_settextstyle (12, 25, 2, 2); // you can specify the text size, stroke width, and text spacing.
M_dd-> dd_settextpos (3, 3); // you can specify the offset between the text and the upper-left corner of the display.
M_dd-> dd_setworkmode (dd_string); // sets the display mode.
M_dd-> dd_settextlightcolor (RGB (0,255, 0); // you can specify the color of the highlighted text.
M_dd-> dd_settextdarkcolor (RGB (55, 55, 0); // you can specify the color of the output text.
M_dd-> dd_setbits (8); // you can specify the number of digits to display.
M_dd-> dd_setbkcolor (RGB (0, 0, 0); // you can specify the background color of the display.
M_dd-> dd_setborderwidth (2); // you can specify the 3D Border width of the display.
M_dd-> dd_movewindow (2, 0 );
Note that m_dd-> dd_setworkmode (dd_string) is used to set the display to the clock mode, so it is not displayed as a numerical style. M_dd-> dd_setbits (8) indicates that the number of digits is 8 bits.
Int iinstallresult;
Iinstallresult = settimer (1,1, null );
If (iinstallresult = 0)
{
MessageBox ("can not install timer! ");
} // Set the timer

Next, the ontimer function is used:
Void ctimewatchdlg: ontimer (uint nidevent)
{
If (m_bstart = true)
{

M_msecond = m_msecond + 1;
If (m_msecond >=100)
{
M_msecond = 0;
M_second = m_second + 1;
}
If (m_second> = 60)
{
M_second = 0;
M_minute = m_minute + 1;
}
If (m_minute> = 60)
{
M_minute = 0;
M_hour = m_hour + 1;
}
If (m_hour> = 24)
{
M_second = 0;
M_msecond = 0;
M_minute = 0;
M_hour = 0;
}
If (m_hour <10)
{
If (m_minute <10 & m_second <10)
{
Strtime. Format ("0% D: 0% D: 0% D", m_hour, m_minute, m_second );
}
If (m_minute <10 & m_second> 10)
{
Strtime. Format ("0% D: 0% D: % d", m_hour, m_minute, m_second );
}
If (m_minute> 10 & m_second> 10)
{
Strtime. Format ("0% D: % d", m_hour, m_minute, m_second );
}
}
Else
{
If (m_minute <10 & m_second <10)
{
Strtime. Format ("% d: 0% D: 0% D", m_hour, m_minute, m_second );
}
If (m_minute> 10 & m_second <10)
{
Strtime. Format ("% d: 0% D", m_hour, m_minute, m_second );
}
If (m_minute> 10 & m_second> 10)
{
Strtime. Format ("% d: % d", m_hour, m_minute, m_second );
}
}

M_dd-> dd_setcurrentstring (strtime );

}
Cdialog: ontimer (nidevent );
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.