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:
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);
}
Any idea on what I'm doing wrong? Thanks.