Discussion:
[C++][Win32] Trackbar slider
(too old to reply)
Willy
2008-12-18 09:06:45 UTC
Permalink
Hi,
I can't find a simple example for use a trackbar slider.

I would do a simple dialog with two slider control and two edit control.
When I move the cursor in the edit control I would show the actual position.
When I write a value in the Edit control I would automactly set the cursor
position.

I think the biggest problem is hook the right WM_NOTIFY from the sliders.

Someone can hel me,
Thanks

Willy
Snorik
2008-12-18 09:43:13 UTC
Permalink
Post by Willy
Hi,
I can't find a simple example for use a trackbar slider.
I would do a simple dialog with two slider control and two edit control.
When I move the cursor in the edit control I would show the actual position.
When I write a value in the Edit control I would automactly set the cursor
position.
Why not use an UpDown? It has the possibility to update another
control kind of built in.
cathy
2008-12-18 10:37:56 UTC
Permalink
Post by Willy
Hi,
Hi
Post by Willy
I can't find a simple example for use a trackbar slider.
First you got to initiate with "InitCommonControls();", link
"comctl32.lib" and include "commctrl.h"
Then you set the range with the "TBM_SETRANGE" message.
Post by Willy
I would do a simple dialog with two slider control and two edit control.
When I move the cursor in the edit control I would show the actual position.
I guess you mean "When I move the cursor in the slide it displays the
value in the edit box".
Intercept the slider message "WM_HSCROLL" or "WM_VSCROLL" (according
your slider orientation). There get the position of your slide with the
"TBM_GETPOS", convert it with "_itow_s" (or "_itoa_s") and then
"SetDlgItemText" of your Edit Box.
Post by Willy
When I write a value in the Edit control I would automactly set the cursor
position.
The opposite so: Intercept the message "EN_CHANGE" of your edit box,
there convert the value with "_wtoi" (or "atoi") and use the
"TBM_SETPOS" message to change your slider position with this value.

Hope this help
Cathy
Christian ASTOR
2008-12-18 11:00:15 UTC
Permalink
Post by Willy
I can't find a simple example for use a trackbar slider.
http://msdn.microsoft.com/en-us/library/cc656639(VS.85).aspx
+ N. CLUTS samples (slider.c, ...)
and as Cathy said for Trackbar thumb position
Willy
2008-12-19 07:29:10 UTC
Permalink
Post by Willy
Hi,
I can't find a simple example for use a trackbar slider.
Thanks to all. :)

Willy
r***@gmail.com
2008-12-23 17:47:21 UTC
Permalink
This is What I do:

case WM_INITDIALOG:
SetSliderRange(GetDlgItem(hDlg, IDC_GAINSLIDER), gainmin, gainmax,
gain);
...
case WM_HSCROLL:
{
HWND hwndScrollBar = (HWND) lParam;
int iPos = (short int)HIWORD(wParam);
if (GetDlgItem(hDlg, IDC_GAINSLIDER)==hwndScrollBar ) {
iPos = (int)SendMessage(hwndScrollBar, TBM_GETPOS, 0, 0);

gain = iPos;
sprintf_s(edtext, EDLEN, "Gain:%d", gain);
SetDlgItemText(hDlg, IDC_GAIN, (LPCSTR)edtext);
if (LOWORD(wParam)==SB_THUMBPOSITION) { // thumb has been released
// Set the gain value now
Beep(500,200);
}
}
}
...

A helper function:
int SetSliderRange(HWND hwndTrack, int iMin, int iMax, int iPos) {
SendMessage(hwndTrack, TBM_SETRANGE,
(WPARAM) TRUE, // redraw flag
(LPARAM) MAKELONG(iMin, iMax)); // min. & max. positions
SendMessage(hwndTrack, TBM_SETSEL,
(WPARAM) FALSE, // redraw flag
(LPARAM) MAKELONG(iMin, iMax));
SendMessage(hwndTrack, TBM_SETPAGESIZE,
0, (LPARAM) (iMax-iMin)/10); // new page
size
SendMessage(hwndTrack, TBM_SETPOS,
(WPARAM) TRUE, // redraw flag
(LPARAM) iPos);

SetFocus(hwndTrack);
return 1;
}
Post by Willy
Post by Willy
Hi,
I can't find a simple example for use a trackbar slider.
Thanks to all. :)
Willy
Loading...