Jump to content
  • Advertisement
Sign in to follow this  
bakibaki

Trackbar control in Visual C++

This topic is 2561 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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:



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.

Share this post


Link to post
Share on other sites
Advertisement
Your WM_HSCROLL switch is faulty:

http://msdn.microsoft.com/en-us/library/bb760149.aspx#tkb_notifications
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!