WM_HSCROLL und verschiedene Trackbars
-
Hallo !
Kann mir mal bitte jemand sagen wie bei der Message "WM_HSCROLL" zwischen verschiedenen Trackbars unterscheiden kann. Ein wenig Code dazu wäre nicht schlecht.
Danke
-
lParam
If the message is sent by a scroll bar, then this parameter is the handle to the scroll bar control. If the message is not sent by a scroll bar, this parameter is NULL.Oder meintest du was anderes
-
Hallo,
eine Möglichkeit wäre die Abfrage des Messageparameters lParam
der Message WM_HSCROLL. Sie liefert Dir das Handle der Scrollbar,
die die Nachricht gesendet hat:#include <windows.h> LRESULT CALLBACK Main_WndProc ( HWND, UINT, WPARAM, LPARAM ); static void Register_All ( HINSTANCE ); int WINAPI WinMain ( HINSTANCE hInst, HINSTANCE hPrevInstance, PSTR lpszCmdLine, int nCmdShow ) { MSG msg; HWND hwnd_Main; if ( !hPrevInstance ) { Register_All ( hInst ); } hwnd_Main = CreateWindowEx ( 0L, "MAIN_WINDOW", "Scrollbars", WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN, CW_USEDEFAULT, CW_USEDEFAULT, 300, 200, NULL, NULL, hInst, NULL ); ShowWindow ( hwnd_Main, nCmdShow ); UpdateWindow ( hwnd_Main ); while (GetMessage ( &msg, NULL, 0, 0 )) { TranslateMessage ( &msg ); DispatchMessage ( &msg ); } return ( msg.wParam ); } LRESULT CALLBACK Main_WndProc ( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam ) { HDC hdc; PAINTSTRUCT ps; static HWND hwnd_sb_1, hwnd_sb_2; switch ( message ) { case WM_CREATE: // CHILD-FENSTER hwnd_sb_1 = CreateWindowEx ( 0L, "SCROLLBAR", NULL, SB_HORZ | WS_CHILD | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hwnd, (HMENU) 1, (HINSTANCE) GetWindowLong ( hwnd, GWL_HINSTANCE), NULL ); hwnd_sb_2 = CreateWindowEx ( 0L, "SCROLLBAR", NULL, SB_HORZ | WS_CHILD | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hwnd, (HMENU) 2, (HINSTANCE) GetWindowLong ( hwnd, GWL_HINSTANCE), NULL ); return ( 0 ); break; case ( WM_SIZE ): if ( (hwnd_sb_1 != (HWND) 0) && (hwnd_sb_2 != (HWND) 0) ) { MoveWindow ( hwnd_sb_1, 0, 0, LOWORD ( lParam), 20, TRUE ); MoveWindow ( hwnd_sb_2, 0, HIWORD ( lParam) - 20, LOWORD ( lParam), 20, TRUE ); } break; case ( WM_PAINT ): hdc = BeginPaint ( hwnd, &ps ); EndPaint ( hwnd, &ps ); return ( 0 ) ; break; case ( WM_HSCROLL ): switch ( LOWORD ( wParam ) ) { case ( SB_LINELEFT ): if ( hwnd_sb_1 == (HWND) lParam ) { MessageBox ( hwnd, "SB_LINELEFT", "Scrollbar 1",0 ); } else if ( hwnd_sb_2 == (HWND) lParam ) { MessageBox ( hwnd, "SB_LINELEFT", "Scrollbar 2",0 ); } break; case ( SB_LINERIGHT ): if ( hwnd_sb_1 == (HWND) lParam ) { MessageBox ( hwnd, "SB_LINERIGHT", "Scrollbar 1",0 ); } else if ( hwnd_sb_2 == (HWND) lParam ) { MessageBox ( hwnd, "SB_LINERIGHT", "Scrollbar 2",0 ); } break; } return ( 0 ); break; case WM_DESTROY: PostQuitMessage ( 0 ); return ( 0 ); break; } return ( DefWindowProc ( hwnd, message, wParam, lParam ) ); } static void Register_All ( HINSTANCE hInst ) { WNDCLASSEX win; ZeroMemory ( &win, sizeof ( win )); win.cbSize = sizeof ( win ); win.style = CS_HREDRAW | CS_VREDRAW; win.lpfnWndProc = Main_WndProc; win.cbClsExtra = 0; win.cbWndExtra = 0; win.hInstance = hInst; win.hCursor = LoadCursor ( NULL, IDC_ARROW ); win.hbrBackground = (HBRUSH) CreateSolidBrush ( RGB ( 192, 192, 192 ) ); win.lpszMenuName = NULL; win.lpszClassName = "MAIN_WINDOW"; RegisterClassEx ( &win ); }
Ist aber unschön, da die Variablen hwnd_sb_1, hwnd_sb_2 static
deklariert werden müssen.Gruss d_A
-
Er kann sich ja auch mit GetDlgCtrlID die ID holen
-
ist denn eine Track Bar überhaupt eine Scroll bar?
-
Nicht direkt, sollte aber trotzdem klappen:
MSDN-Library schrieb:
Trackbar Notification Messages
A trackbar notifies its parent window of user actions by sending the parent a WM_HSCROLL or WM_VSCROLL message. A trackbar with the TBS_HORZ style sends WM_HSCROLL messages. A trackbar with the TBS_VERT style sends WM_VSCROLL messages. The low-order word of the wParam parameter of WM_HSCROLL or WM_VSCROLL contains the notification code. [...] The lParam parameter is the handle to the trackbar.
-
???? schrieb:
ist denn eine Track Bar überhaupt eine Scroll bar?
nein, natürlich nicht ...
Ich hab nur WM_HSCROLL gelesen und dann damit sofort an eine Scrollbar
gedacht. Aber wie flenders schon bemerkt hat ist das Prinzip das Gleiche.Gruss d_A
-
Tag !
Danke für die vielen Antworten der Code von "der_anhalter" funktioniert einwandfrei !
-
Ich würde aber die Fenster-Handles nicht satic machen, sondern lieber in WM_HSCROLL ein
switch(GetDlgCtrlID((HWND)lParam)) { case ID_VON_TRACKBAR_1: //... break; case ID_VON_TRACKBAR_2: //... break; }
Finde ich zumindest eleganter und übersichtlicher