Scrollbars... ich krieg die Motten!
-
Hi,
ich habe mit CreateWindow eine Vertikale Scrollbar erstellt, klappt auch wunderbar! Aber das handling vorne und hinten nicht

#define STRICT #include <windows.h> LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); const char szAppName[] = "bla"; HWND bla = NULL; int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { const int iWindowWidth = 400; const int iWindowHeight = 300; MSG msg; HWND hWnd; WNDCLASS wc; wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wc.lpszMenuName = 0; wc.lpszClassName = szAppName; RegisterClass(&wc); hWnd = CreateWindow( szAppName, szAppName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, iWindowWidth, iWindowHeight, NULL, NULL, hInstance, NULL); bla = CreateWindow ("scrollbar", "", SBS_VERT | WS_CHILD | WS_VISIBLE | BS_FLAT, 10, 10, 17, 100, hWnd, NULL, hInstance, NULL); ShowWindow(hWnd, iCmdShow); UpdateWindow(hWnd); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { static const int iRand = 20; static const int iZeichenhoehe = 16; static RECT rect; switch (message) { case WM_CREATE: { SCROLLINFO siScrollInfo; siScrollInfo.cbSize = sizeof(siScrollInfo); siScrollInfo.fMask = SIF_RANGE | SIF_PAGE; siScrollInfo.nMin = 0; siScrollInfo.nMax = 1200; siScrollInfo.nPage = 64; SetScrollInfo(bla, SB_VERT, &siScrollInfo, TRUE); siScrollInfo.fMask = SIF_POS; GetScrollInfo(bla, SB_VERT, &siScrollInfo); return 0; } case WM_VSCROLL: { SCROLLINFO siScrollInfo; int iPosition; siScrollInfo.cbSize = sizeof(siScrollInfo); siScrollInfo.fMask = SIF_ALL; GetScrollInfo(bla, SB_VERT, &siScrollInfo); iPosition = siScrollInfo.nPos; switch (LOWORD(wParam)) { case SB_TOP: siScrollInfo.nPos = siScrollInfo.nMin; break; case SB_BOTTOM: siScrollInfo.nPos = siScrollInfo.nMax; break; case SB_LINEUP: siScrollInfo.nPos -= 32; break; case SB_LINEDOWN: siScrollInfo.nPos += 32; break; case SB_PAGEUP: siScrollInfo.nPos -= siScrollInfo.nPage; break; case SB_PAGEDOWN: siScrollInfo.nPos += siScrollInfo.nPage; break; case SB_THUMBTRACK: siScrollInfo.nPos = siScrollInfo.nTrackPos; break; default: return 0; } siScrollInfo.fMask = SIF_POS; SetScrollInfo(bla, SB_VERT, &siScrollInfo, TRUE); return 0; } case WM_DESTROY: { PostQuitMessage(0); return 0; } } return DefWindowProc(hWnd, message, wParam, lParam); }Egal ob ich nun auf einen der beiden Buttons der scrollbar klicke, es bewegt sich der schieber der scrollbar keinen milimeter

Was mach ich falsch=?
-
Je nachdem was du machen willst, sind entweder deine SetScrollInfo aufrufe falsch oder das erstellen der Scrollbar. In den SetScollInfo Aufrufen gibst du die Standard-Vertikale-Scollleiste eines Fensters an, aber oben erstellst du sie explizit als eigenes Control.
Also entweder gibst du WS_VSCROLL beim erstellen deines Hauptfensters an, dann hat dieses an der Seite eine Standardscolleiste oder du gibst beim SetScollInfo-Aufruf als ersten Parameter das Handle der Scrollleiste und als zweiten SB_CTL an.
-
Wat? Hab ich doch?
und nein ich nehme kein WM_VSCROLL
-
In WM_CREATE ist bla == NULL !!!

-
WebFritzi schrieb:
In WM_CREATE ist bla == NULL !!!

Wenn ichs so mach passiert auch nix

#define STRICT #include <windows.h> LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); const char szAppName[] = "bla"; HWND bla = NULL; HINSTANCE inst; int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { const int iWindowWidth = 400; const int iWindowHeight = 300; inst = hInstance; MSG msg; HWND hWnd; WNDCLASS wc; wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wc.lpszMenuName = 0; wc.lpszClassName = szAppName; RegisterClass(&wc); hWnd = CreateWindow( szAppName, szAppName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, iWindowWidth, iWindowHeight, NULL, NULL, hInstance, NULL); ShowWindow(hWnd, iCmdShow); UpdateWindow(hWnd); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { static const int iRand = 20; static const int iZeichenhoehe = 16; static RECT rect; switch (message) { case WM_CREATE: { bla = CreateWindow ("scrollbar", "", SBS_VERT | WS_CHILD | WS_VISIBLE | BS_FLAT, 10, 10, 17, 100, hWnd, NULL, inst, NULL); SCROLLINFO siScrollInfo; siScrollInfo.cbSize = sizeof(siScrollInfo); siScrollInfo.fMask = SIF_RANGE | SIF_PAGE; siScrollInfo.nMin = 0; siScrollInfo.nMax = 1200; siScrollInfo.nPage = 64; SetScrollInfo(bla, SB_VERT, &siScrollInfo, TRUE); siScrollInfo.fMask = SIF_POS; GetScrollInfo(bla, SB_VERT, &siScrollInfo); return 0; } case WM_VSCROLL: { SCROLLINFO siScrollInfo; int iPosition; siScrollInfo.cbSize = sizeof(siScrollInfo); siScrollInfo.fMask = SIF_ALL; GetScrollInfo(bla, SB_VERT, &siScrollInfo); iPosition = siScrollInfo.nPos; switch (LOWORD(wParam)) { case SB_TOP: siScrollInfo.nPos = siScrollInfo.nMin; break; case SB_BOTTOM: siScrollInfo.nPos = siScrollInfo.nMax; break; case SB_LINEUP: siScrollInfo.nPos -= 32; break; case SB_LINEDOWN: siScrollInfo.nPos += 32; break; case SB_PAGEUP: siScrollInfo.nPos -= siScrollInfo.nPage; break; case SB_PAGEDOWN: siScrollInfo.nPos += siScrollInfo.nPage; break; case SB_THUMBTRACK: siScrollInfo.nPos = siScrollInfo.nTrackPos; break; default: return 0; } siScrollInfo.fMask = SIF_POS; SetScrollInfo(bla, SB_VERT, &siScrollInfo, TRUE); return 0; } case WM_DESTROY: { PostQuitMessage(0); return 0; } } return DefWindowProc(hWnd, message, wParam, lParam); }
-
D@niel $chumann schrieb:
du gibst beim SetScollInfo-Aufruf als ersten Parameter das Handle der Scrollleiste und als zweiten SB_CTL an.
-
Ich würd sagen du mußt den Bereich der ScrollBar noch neuzeichnen lassen. Du kannst ja mal ausprobieren, wenn du einige Male den Pfeil nach unten drückst und dann die Größe des Fensters veränderst, dürfte die aktuelle Position angezeigt werden, da du bei WindowStyle HREDRAW und VREDRAW gesetzt hast. Und natürlich den Rat von WebFritzi befolgen.
-
Der Pate Teil IV schrieb:
SB_VERT
Du meinst wohl SB_CTL!!
