Trackbar resets

I got this problem with a trackbar in winapi, as soon as I click off the trackbar, it resets back to 0. Here's my WM_HSCROLL message code. What am I doing wrong?

1
2
3
4
5
6
7
8
case WM_HSCROLL:
 {
             DWORD pos = HIWORD(wParam);
	     camera_step = pos * 0.01f;
             SetDlgItemText(handle, ID_STXT, std::wstring(L"Camera speed set to: "+
				       std::to_wstring(pos)).c_str());
 }
break;


Thanks in advance.
Last edited on
How did you set up your TrackBar?
Have a look at this tutorial: http://zetcode.com/gui/winapi/controlsII/
I made this function and used it to instantiate the trackbar:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
HWND CreateTrackBar(HWND * parent, UINT const & min, UINT const & max, 
	                UINT const & minS, UINT const & maxS, HINSTANCE hInst,
	                int const & rcID)
{
	HWND handle=CreateWindowEx(0, TRACKBAR_CLASS,
		                       L"Scrolling Speed",
	                              WS_CHILD | WS_VISIBLE |
		                       TBS_AUTOTICKS | TBS_ENABLESELRANGE,
		                       20, 20, 300, 30, *parent, 
		                       HMENU(rcID), hInst, NULL);

	SendMessage(handle, TBM_SETRANGE, (WPARAM)TRUE,
		(LPARAM) MAKELONG(min, max));

	SendMessage(handle, TBM_SETPAGESIZE, 0, (LPARAM) 4);
	SendMessage(handle, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) minS);

	SetFocus(handle);
	return handle;
}


Also, here's the resource script I wrote for the dialog, but afaik it shouldn't affect the trackbar.

IDD_SCR DIALOGEX DISCARDABLE 50, 50, 210, 70
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Set Camera Scroll Speed"
FONT 10, "Arial"
BEGIN
   CTEXT "Slow", -1, -5,  1, 100, 15
   CTEXT "Fast", -1, 110, 1, 100, 15
   PUSHBUTTON "RESET", ID_RESET, 15, 45, 60, 20
   PUSHBUTTON "DONE", ID_DONE, 85, 45, 60, 20
   CTEXT  "Default Camera Speed 3.0", ID_STXT, 10, 28, 100, 15
END
Last edited on
Topic archived. No new replies allowed.