I am writing a simple GUI application in Visual C++/Windows API. I have a Trackbar control on the dialogbox defined in resources as:
CONTROL "",IDC_SLIDER1045,"msctls_trackbar32",0x50010000,23,52,141,16,0x00000000
I want to show the trackbar value on static text control, so I wrote:
case WM_NOTIFY:
if(lParam == TRBN_THUMBPOSCHANGING)
{
Pos1 = SendMessage(GetDlgItem(hwndDlg, 1045), TBM_GETPOS, 0, 0);
wsprintf(szPos1, "Change IP address every %d minutes", Pos1);
SetDlgItemText(hwndDlg, 1044, szPos1);
}
break;
I tried also:
case WM_NOTIFY:
Pos1 = SendMessage(GetDlgItem(hwndDlg, 1045), TBM_GETPOS, 0, 0);
wsprintf(szPos1, "Change IP address every %d minutes", Pos1);
SetDlgItemText(hwndDlg, 1044, szPos1);
break;
Both codes doesn't work. First gives no action, second hangs the application.
My question is: How to get Trackbar value and show it on static text control in real time?
Be sure to read the SDK documentation for Trackbar. The section titled "Trackbar Notification Messages" tells you how the control tells you about the position.
Note how it documents that you should listen for the WM_HSCROLL or WM_VSCROLL message.
What are 1045 and 1044 in your code? Possibly you mean IDC_SLIDER1045 and static control resource ID. If necessary, include resource.h to the source file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With