Sign in to follow this  
bakibaki

Trackbar control in Visual C++

Recommended Posts

bakibaki    100
Hi, I am trying to get the logical value for the thumbtrack position, but the value won't update.
I've looked at win32 api tutorials on it and some other threads with similar problems, but the value just doesn't seem to update (ie. stays at 0).
This is what I've tried so far:

[code]

HWND xSlider = NULL;
HWND xSliderVal = NULL;

double xSliderVal;

std::string to_string(double value) {
std::stringstream sstr;
sstr<<value;
std::string s = sstr.str();
return s;
}

LRESULT WndProc (HWND hWnd, UNIT uMsg, WPARAM wParam, LPARAM lParam)
{

switch (uMsg)
{
case WM_HSCROLL:
switch(wParam)
{
case TB_THUMBTRACK:
xSlideVal = SendMessage(xSlider, TBM_GETPOS, 0,0);
SetWindowText(GetDlgItem(hWnd, IDC_X_SLIDER_VAL), to_string(xSlideVal).c_str());
}
break;

default:
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
}

void CreateControls(HWND hWnd, HINSTANCE hInstance)
{
if((xSliderVal = CreateWindow ( WC_STATIC,
"0",
WS_CHILD|WS_VISIBLE|WS_TABSTOP,
400,400,70,23,
hWnd,(HMENU)IDC_X_SLIDER_VAL,
hInstance, NULL))==NULL)
{
throw std::exception("Failed to create controls");
}
if((xSlider = CreateWindow ( TRACKBAR_CLASS,
"",
WS_CHILD|WS_VISIBLE|TBS_HORZ,
40,400,350,23,
hWnd,(HMENU)IDC_X_SLIDER,
hInstance, NULL))==NULL)
{
throw std::exception("Failed to create controls");
}
SendMessage(xSlider,TBM_SETRANGEMAX,true, 1000);
SendMessage(xSlider,TBM_SETRANGEMIN,true, -1000);
}
[/code]

Any idea on what I'm doing wrong? Thanks.

Share this post


Link to post
Share on other sites
adeyblue    549
Your WM_HSCROLL switch is faulty:
[quote]
[i]http://msdn.microsoft.com/en-us/library/bb760149.aspx#tkb_notifications[/i]
The low-order word of the wParam parameter of WM_HSCROLL or WM_VSCROLL contains the notification code. For the TB_THUMBPOSITION and TB_THUMBTRACK notification codes, the high-order word of the wParam parameter specifies the position of the slider.
[/quote]
You want to be switching on LOWORD(wParam) instead.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this