Slider application and message

Source: Internet
Author: User

The program is easy to use with the slider control. You can share your experience with me.

 

I. Application

 

 

Ctestdlg: onhscroll (uint nsbcode, uint NPOs, cscrollbar * pscrollbar) <br/>{< br/> // todo: add your message handler code here and/or call default <br/> csliderctrl * ps1_ctrl = (csliderctrl *) getdlgitem (idc_slider1 ); <br/> int m_ncur = ps1_ctrl-> getpos (); <br/> cstring STR; <br/> Str. format ("% d/N", m_ncur); <br/> trace (STR); </P> <p> cdialog: onhscroll (nsbcode, NPOs, pscrollbar ); <br/>}< br/>

 

[MFC] onvscroll () and onhscroll () functions in the dialog box
Therefore, to effectively control the slider, you must control these two functions (rewrite the two functions in the dialog box.

For example:
//////////////////////////////////////// //////////////////////////////////////// ///// // <Br/> // horizontal movement <br/> ///////// //////////////////////////////////////// //////////////////////////////////////// ///////// <br/> void ctestdialog:: onhscroll (uint nsbcode, uint NPOs, cscrollbar * pscrollbar) <br/>{< br/> // todo: add the message processing program code and/or call the default value <br/> // slider <br/> csliderctrl * pslider = (csliderctrl *) pscrollbar; <br/> cstring strtext; </P> <p> int dvalue [10] = {0 }; <br/> // control multiple slider controls <br/> switch (pslider-> getdlgctrlid ()) <br/>{< br/> // slider1 <br/> case idc_slider1: <br/> strtext. format (_ T ("% d"), pslider-> getpos (); <br/> setdlgitemtext (idc_static_slider1, strtext); <br/> break; <br/> // slider2 <br/> case idc_slider2: <br/> strtext. format (_ T ("% 3.1f"), dvalue [pslider-> getpos ()]); <br/> setdlgitemtext (idc_static_slider2, strtext); <br/> break; <br/> // dvalue [6] = {1.5, 3.0, 4.5, 6.0, 7.5 };< br/>}< br/> cdialog :: onhscroll (nsbcode, NPOs, pscrollbar ); <br/>}</P> <p> //////////////////////////// //////////////////////////////////////// /// // <br/> // vertical scroll <br/> ///////////////////////////////////// //////////////////////////////////////// /// // <br/> void ctestdialog:: onvscroll (uint nsbcode, uint NPOs, cscrollbar * pscrollbar) <br/>{< br/> // todo: add the message processing program code and/or call the default value <br/> If (nsbcode = sb_endscroll) <br/>{< br/> return; <br/>}< br/> // spin button <br/> If (pscrollbar-> getdlgctrlid () = idc_spin1) <br/>{< br/> cstring strvalue; <br/> strvalue. format (_ T ("% 3.1f"), (double) NPOs/10.0); <br/> // (cspinbuttonctrl *) pscrollbar)-> getbuddy () -> setwindowtextw (strvalue); <br/> cedit * pedit = (cedit *) (cspinbuttonctrl *) pscrollbar)-> getbuddy (); <br/> pedit-> setwindowtextw (strvalue); <br/>}</P> <p> cdialog: onvscroll (nsbcode, NPOs, pscrollbar ); <br/>}< br/>

 

 

 

Ii. Slider notification message

Visual c ++ concept: Add a function slider to notify messages

The slider control is sent to the parent windowWm_hscrollOrWm_vscrollMessage (depending on the slider control), notifies the parent window of user operations. To process these messagesWm_hscrollAndWm_vscrollAdd the message handler to the parent window. The onhscroll and onvscroll member functions will be passed with the notification code, the slider position, and the pointer to the csliderctrl object. Note that the pointer type isCscrollbar *, Even if it pointsCsliderctrlObject. To operate the slider control, you may need to convert the pointer type.

 

The slider control does not use the scroll bar notification code, but sends different notification code sets. The slider control is sent only when you use the keyboard to interact with the slider control.Tb_bottom,Tb_linedown,Tb_lineupAndTb_topNotification code. The message is sent only when the user uses the mouse.Tb_thumbpositionAndTb_thumbtrackNotification message. Send in both casesTb_endtrack,Tb_pagedownAndTb_pageupNotification code.

The following table lists the slider control notification messages and events that result in notification sending (Virtual key code and mouse events ). (For a list of standard false key codes, see winuser. H .)

Notification Message Events that cause notification sending
Tb_bottom Vk_end
Tb_endtrack Wm_keyup(The user released the key for sending the related virtual key code)
Tb_linedown Vk_rightOrVk_down
Tb_lineup Vk_leftOrVk_up
Tb_pagedown Vk_next(The user clicks the Channel below the slider or on the right)
Tb_pageup Vk_prior(The user clicked the channel above the slider or on the left)
Tb_thumbposition Wm_lbuttonupInTb_thumbtrackAfter notification message
Tb_thumbtrack Slider Movement (the user dragged the slider)
Tb_top Vk_home

Sample Code: // control the vertical scroll bar to move hwnd = getdlgitem (idc_slider1)-> getsafehwnd ();
: Sendmessage (hwnd, wm_setfocus, 0, 0 );
: Sendmessage (hwnd, wm_keydown, vk_up, 1 );
: Sendmessage (hwnd, wm_vscroll, tb_lineup, 0 );

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.