Introduction to csliderctrl

Source: Internet
Author: User

The member function of the csliderctrl class. You can query and set rail lines:

Use getrange and setrange to query and set the range of the rail bar. The default range is 0-100. The function declaration is
Void getrange (Int & Nmin, Int & Nmax) const;
Void setrange (INT Nmin, int Nmax, bool bredraw = false );
The Nmin and Nmax parameters are the minimum and maximum values respectively. If the bredraw parameter is true, the re-painting control is performed.

Use getpos and setpos to query and set the current value of the orbital bar. The declaration of the function is
Int getpos () const;
Void setpos (INT NPOs );

Use getlinesize and setlinesize to query and set the movement of the slide ruler when you click the left or right arrow keys. The default value of this movement is 1 unit. The function declaration is
Int getlinesize () const;
Int setlinesize (INT nsize );

Getpagesize and setpagesize are used to query and set the block movement of the slider. The Block Movement refers to the movement of the slider when the pgup or pgdown key is pressed. The function declaration is
Int getpagesize () const;
Int setpagesize (INT nsize );

Use setticfreq to set the frequency of the scale of the rail bar. the default frequency is that each unit has a scale. When the range is large, you need to call this function to set a reasonable frequency to prevent the scale from being too dense. the function declaration is
Void setticfreq (INT nfreq );
The nfreq parameter specifies the interval between two scales.

Use the settic function to set the scale at the specified position. The scale automatically displayed in Windows is even. You can use this function to manually set an uneven scale. The declaration of this function is
Bool settic (int ntic );

Use the cleartics function to clear all scales. The declaration of this function is
Void cleartics (bool bredraw = false );

 

Ii. csliderctrl instructions

 

Slider control (slider control) is also called rail bar control. It mainly uses a small window with track and sliding mark and a scale on the window to allow users to select a discrete data or a continuous Numerical range. Use the mouse or keyboard to select data, which can be seen in many applications in Win98/95, such as the mouse in the control panel, slide bars can be either horizontal or vertical. The sliding bar control style is as follows:

The tbs_horz slider is horizontally oriented.

The tbs_vert slider is vertical.

The tbs_left slider is located on the left of the window.

The tbs_right slider is on the right of the window.

The tbs_top slider is located at the top of the window.

The tbs_bottom slider is located at the bottom of the window.

Tbs_both slider on both sides of the window

The tbs_autoticks slider has a scale. The default value is

The tbs_noticks slider does not have a scale

The scale bar of the slider displays a scale mark at each numerical position. If a value selection interval is displayed on the slider bar, the style tbs_enableselrange should be used. At this time, the selected range is no longer a scale mark, it is a small triangle symbol. In addition, the style tbs_nothumb will hide the slide.

The slider control is encapsulated as csliderctrl control in the MFC class library. The main operations are to set the scale range, draw the scale mark, set the selection range and the current sliding position. When a user performs an interactive operation, the slider control sends the message wm_hscroll to the parent window. Therefore, the onhscroll () member function of the parent window should be reloaded in the application, this allows you to correctly process the notification code sent by the system, the sliding position, and the pointer to the csliderctrl object. The pointer variable in the onhscroll () function parameter table is defined as cscrollbar * Because messages are generated by slide bars, therefore, the pointer variable must be forcibly converted to the csliderctrl * type in the program. The message codes and meanings of Slide and scroll bars are very similar to those of tb_bottom. Therefore, this processing method is reasonable. The setrange () function is used to set the range. The setpos () function is used to set the current position.

(2) object structure controlled by slide bar

How to Create Sliding bar Control

Csliderctrl & sliderctrl create a slider control object structure

Create create a slider control object and bind the object

The call format of the slide bar control class csliderctrl: Create is as follows:

Bool create (DWORD dwstyle, const rect & rect, cwnd * pparentwnd, uint NID );

The dwstyle parameter is used to determine the sliding bar control style, the rect parameter is used to determine the size and position of the sliding bar control, and the pparentwnd parameter is used to determine the parent window pointer of the sliding bar control; the NID parameter is used to determine the control letter ID of the slider control.

2. class attributes controlled by slide bars

The class attributes of the slider control object include getlinesize, setlinesize, getpagesize, setpagesize, getrangemax, and getrangemin. getrange, setrangemin, setrangemax, setrangemax, setrange, getselection, setselection, and getpos and setpos.

3. Operation Method of slide bar Control

The slider control operation methods include clearing the currently selected clearsel slide, verifying whether the current position of the slider is between the maximum and minimum positions verifypos, and clearing the current scale mark cleartics.

Example of Sliding bar Control

1. Use the Application Wizard Appwizard to generate an object-box-based application cs1_dlg;

2. Set the slider control in the dialog box, and its ID is idc_slider;

3. Add the control range and position in the initial code of the dialog box:

(1) set the data member in sliddlg. h to indicate the current value of the slide bar:

// Sliddlg. h
Class csliddlg: Public cdialog
{... // Other code
Public:
Int m_ncur;
... // Other code
}

(2) set the initial status in sliddlg. cpp.
Bool cs1_dlg: oninitdialog ()
{Cdialog: oninitdialog ();
... // Other code
// Todo: add extra initialization here
Csliderctrl * ps1_ctrl = (csliderctrl *) getdlgitem (idc_sllider );
Ps1_ctrl-> setrange (, true); // you can specify the slider range.
Pslidctrl-> setpos (2); // you can specify the slider position.
... // Other code
Return true;
}

(3) Improve the Message Processing of Slide bars, use the Class Wizard classwizard to add the wm_hscroll message processing function in the dialog box window, and obtain the position value indicated by the slide:

Void csliddlg: onhscroll (uint nsbcode, uint NPOs, cscrollbar * pscrollbar)
{// Todo: add your message handler?
Cdialog: onhscroll (nsbcode, NPOs, pscrollbar );
Csliderctrl * ps1_ctrl = (csliderctrl *) getdlgitem (idc_sllider );
M_ncur = ps1_ctrl-> getpos (); // get the current position value
}

 

When there are multiple slide csliderctrl in a form, when processing the onhscroll () response, you do not need a pointer to determine which slide is currently working. Let's talk less about the Code:
Int X;
Cstring STR;
// Obtain the subwindow ID, and then stream it.
Switch (Pscrollbar-> getdlgctrlid())
{
Case idc_slh_length:
X = slhlength. getpos ();
Str. Format ("Length: % d", X );
Stclength. setwindowtext (STR );
Break;
Case idc_slh_width:
X = slhwidth. getpos ();
Str. Format ("width: % d", X );
Stcwidth. setwindowtext (STR );
Break;
Default:
Break;
}

The member function of the csliderctrl class. You can query and set rail lines:

Use getrange and setrange to query and set the range of the rail bar. The default range is 0-100. The function declaration is
Void getrange (Int & Nmin, Int & Nmax) const;
Void setrange (INT Nmin, int Nmax, bool bredraw = false );
The Nmin and Nmax parameters are the minimum and maximum values respectively. If the bredraw parameter is true, the re-painting control is performed.

Use getpos and setpos to query and set the current value of the orbital bar. The declaration of the function is
Int getpos () const;
Void setpos (INT NPOs );

Use getlinesize and setlinesize to query and set the movement of the slide ruler when you click the left or right arrow keys. The default value of this movement is 1 unit. The function declaration is
Int getlinesize () const;
Int setlinesize (INT nsize );

Getpagesize and setpagesize are used to query and set the block movement of the slider. The Block Movement refers to the movement of the slider when the pgup or pgdown key is pressed. The function declaration is
Int getpagesize () const;
Int setpagesize (INT nsize );

Use setticfreq to set the frequency of the scale of the rail bar. the default frequency is that each unit has a scale. When the range is large, you need to call this function to set a reasonable frequency to prevent the scale from being too dense. the function declaration is
Void setticfreq (INT nfreq );
The nfreq parameter specifies the interval between two scales.

Use the settic function to set the scale at the specified position. The scale automatically displayed in Windows is even. You can use this function to manually set an uneven scale. The declaration of this function is
Bool settic (int ntic );

Use the cleartics function to clear all scales. The declaration of this function is
Void cleartics (bool bredraw = false );

 

Ii. csliderctrl instructions

 

Slider control (slider control) is also called rail bar control. It mainly uses a small window with track and sliding mark and a scale on the window to allow users to select a discrete data or a continuous Numerical range. Use the mouse or keyboard to select data, which can be seen in many applications in Win98/95, such as the mouse in the control panel, slide bars can be either horizontal or vertical. The sliding bar control style is as follows:

The tbs_horz slider is horizontally oriented.

The tbs_vert slider is vertical.

The tbs_left slider is located on the left of the window.

The tbs_right slider is on the right of the window.

The tbs_top slider is located at the top of the window.

The tbs_bottom slider is located at the bottom of the window.

Tbs_both slider on both sides of the window

The tbs_autoticks slider has a scale. The default value is

The tbs_noticks slider does not have a scale

The scale bar of the slider displays a scale mark at each numerical position. If a value selection interval is displayed on the slider bar, the style tbs_enableselrange should be used. At this time, the selected range is no longer a scale mark, it is a small triangle symbol. In addition, the style tbs_nothumb will hide the slide.

The slider control is encapsulated as csliderctrl control in the MFC class library. The main operations are to set the scale range, draw the scale mark, set the selection range and the current sliding position. When a user performs an interactive operation, the slider control sends the message wm_hscroll to the parent window. Therefore, the onhscroll () member function of the parent window should be reloaded in the application, this allows you to correctly process the notification code sent by the system, the sliding position, and the pointer to the csliderctrl object. The pointer variable in the onhscroll () function parameter table is defined as cscrollbar * Because messages are generated by slide bars, therefore, the pointer variable must be forcibly converted to the csliderctrl * type in the program. The message codes and meanings of Slide and scroll bars are very similar to those of tb_bottom. Therefore, this processing method is reasonable. The setrange () function is used to set the range. The setpos () function is used to set the current position.

(2) object structure controlled by slide bar

How to Create Sliding bar Control

Csliderctrl & sliderctrl create a slider control object structure

Create create a slider control object and bind the object

The call format of the slide bar control class csliderctrl: Create is as follows:

Bool create (DWORD dwstyle, const rect & rect, cwnd * pparentwnd, uint NID );

The dwstyle parameter is used to determine the sliding bar control style, the rect parameter is used to determine the size and position of the sliding bar control, and the pparentwnd parameter is used to determine the parent window pointer of the sliding bar control; the NID parameter is used to determine the control letter ID of the slider control.

2. class attributes controlled by slide bars

The class attributes of the slider control object include getlinesize, setlinesize, getpagesize, setpagesize, getrangemax, and getrangemin. getrange, setrangemin, setrangemax, setrangemax, setrange, getselection, setselection, and getpos and setpos.

3. Operation Method of slide bar Control

The slider control operation methods include clearing the currently selected clearsel slide, verifying whether the current position of the slider is between the maximum and minimum positions verifypos, and clearing the current scale mark cleartics.

Example of Sliding bar Control

1. Use the Application Wizard Appwizard to generate an object-box-based application cs1_dlg;

2. Set the slider control in the dialog box, and its ID is idc_slider;

3. Add the control range and position in the initial code of the dialog box:

(1) set the data member in sliddlg. h to indicate the current value of the slide bar:

// Sliddlg. h
Class csliddlg: Public cdialog
{... // Other code
Public:
Int m_ncur;
... // Other code
}

(2) set the initial status in sliddlg. cpp.
Bool cs1_dlg: oninitdialog ()
{Cdialog: oninitdialog ();
... // Other code
// Todo: add extra initialization here
Csliderctrl * ps1_ctrl = (csliderctrl *) getdlgitem (idc_sllider );
Ps1_ctrl-> setrange (, true); // you can specify the slider range.
Pslidctrl-> setpos (2); // you can specify the slider position.
... // Other code
Return true;
}

(3) Improve the Message Processing of Slide bars, use the Class Wizard classwizard to add the wm_hscroll message processing function in the dialog box window, and obtain the position value indicated by the slide:

Void csliddlg: onhscroll (uint nsbcode, uint NPOs, cscrollbar * pscrollbar)
{// Todo: add your message handler?
Cdialog: onhscroll (nsbcode, NPOs, pscrollbar );
Csliderctrl * ps1_ctrl = (csliderctrl *) getdlgitem (idc_sllider );
M_ncur = ps1_ctrl-> getpos (); // get the current position value
}

 

When there are multiple slide csliderctrl in a form, when processing the onhscroll () response, you do not need a pointer to determine which slide is currently working. Let's talk less about the Code:
Int X;
Cstring STR;
// Obtain the subwindow ID, and then stream it.
Switch (Pscrollbar-> getdlgctrlid())
{
Case idc_slh_length:
X = slhlength. getpos ();
Str. Format ("Length: % d", X );
Stclength. setwindowtext (STR );
Break;
Case idc_slh_width:
X = slhwidth. getpos ();
Str. Format ("width: % d", X );
Stcwidth. setwindowtext (STR );
Break;
Default:
Break;
}

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.