Scrollbar zu einem bestehenden Formular hinzufügen
-
Hallo!
Ich komme aus der Mac-Programmierung und habe ein Problem mit der Erzeugung von Scrollbars unter Windows. Ich möchte on-fly zu einem bestehenden Formular einen vertikalen Scrollbar hinzufügen. Ich experimentiere mit CreateWindow und CreateWindowEx, aber egal was ich mache, es wird jedes mal ein neues Fenster aufgemacht:
projPtr->vscrollbarWIN=CreateWindowEx( 0, // no extended styles "SCROLLBAR", // scroll bar control class (LPSTR) NULL, // text for window title bar SBS_VERT, // scroll bar styles projPtr->vscrollbarrect.left, // horizontal position projPtr->vscrollbarrect.top, // vertical position 15, // width of the scroll bar 100, // default height (HWND) hwnd, // handle to main window (HMENU) 0, // no menu for a scroll bar (HINSTANCE) GetModuleHandle(0), // instance owning this window (LPVOID) 0 // pointer not needed ); ShowWindow(projPtr->vscrollbarWIN,true);Irgendeine Idee?
-
projPtr->vscrollbarWIN=CreateWindowEx( 0, // no extended styles "SCROLLBAR", // scroll bar control class (LPSTR) NULL, // text for window title bar SBS_VERT [b]| WS_CHILD[/b], // scroll bar styles projPtr->vscrollbarrect.left, // horizontal position projPtr->vscrollbarrect.top, // vertical position 15, // width of the scroll bar 100, // default height (HWND) hwnd, // handle to main window (HMENU) 0, // no menu for a scroll bar (HINSTANCE) GetModuleHandle(0), // instance owning this window (LPVOID) 0 // pointer not needed );
-
Nein, das war es nicht. Wenn ich das so übernehme wird nichts erstellt. Die Prozedur CreateWindowEx gibt 0 zurück.
-
Hast du schon in der MSDN nachgeschaut?
-
Ja klar. Das ist ja immer meine erste Anlaufstelle. Nur das hilft mir nicht weiter. Funktionieren tut es nicht.
-
Was meint denn GetLastError?
-
Ja, GetLastError gibt 1406 zurück:
ERROR_TLW_WITH_WSCHILD
1406 Cannot create a top-level child window.Aber warum???
-
Versuchs mal damit:
GetClientRect( hWnd, &rc ); hScrollBar = CreateWindowEx( 0, "SCROLLBAR", NULL, SBS_RIGHTALIGN | SBS_VERT | WS_CHILD | WS_VISIBLE, rc.left, rc.top, rc.right, rc.bottom, hWnd, (HMENU) 0, hInstance, NULL );
-
Mhhh. Das gleiche. Da bekomme ich auch Fehler 1406. Was kann das nur sein?
-
bei mir funktionierts.
Ansonsten kannst Du dem Hauptfenster beim erstellen die Styles WS_VSCROLL und/oder WS_HSCROLL übergeben, damit bekommst Du auch Scrollbars...