Delen via


Schuifbalken maken

Wanneer u een overlappend, pop-upvenster of onderliggend venster maakt, kunt u standaard schuifbalken toevoegen met behulp van de functie CreateWindowEx en het opgeven van WS_HSCROLL, WS_VSCROLL of beide stijlen.

Wat u moet weten

Technologieën

Voorwaarden

  • C/C++
  • Programmeren van Windows-gebruikersinterface

Aanwijzingen

Een schuifbalk maken

In het volgende voorbeeld wordt een venster gemaakt met standaard horizontale en verticale schuifbalken.

    hwnd = CreateWindowEx( 
        0,                     // no extended styles 
        g_szWindowClass,       // global string containing name of window class
        g_szTitle,             // global string containing title bar text 
        WS_OVERLAPPEDWINDOW |  
            WS_HSCROLL | WS_VSCROLL, // window styles 
        CW_USEDEFAULT,         // default horizontal position 
        CW_USEDEFAULT,         // default vertical position 
        CW_USEDEFAULT,         // default width 
        CW_USEDEFAULT,         // default height 
        (HWND) NULL,           // no parent for overlapped windows 
        (HMENU) NULL,          // use the window class menu 
        g_hInst,               // global instance handle  
        (PVOID) NULL           // pointer not needed 
    ); 

Als u schuifbalkberichten voor deze schuifbalken wilt verwerken, moet u de juiste code opnemen in de procedure van het hoofdvenster.

U kunt de functie CreateWindowEx gebruiken om een schuifbalk te maken door de vensterklasse SCROLLBAR op te geven. Hiermee maakt u een horizontale of verticale schuifbalk, afhankelijk van of SBS_HORZ of SBS_VERT is opgegeven als de stijl van het venster. De grootte van de schuifbalk en de positie ten opzichte van het bovenliggende venster kunnen ook worden opgegeven.

In het volgende voorbeeld wordt een horizontale schuifbalk gemaakt die langs de onderkant van het clientgebied van het bovenliggende venster wordt geplaatst.

// Description:
//   Creates a horizontal scroll bar along the bottom of the parent 
//   window's area.
// Parameters:
//   hwndParent - handle to the parent window.
//   sbHeight - height, in pixels, of the scroll bar.
// Returns:
//   The handle to the scroll bar.
HWND CreateAHorizontalScrollBar(HWND hwndParent, int sbHeight)
{
    RECT rect;

    // Get the dimensions of the parent window's client area;
    if (!GetClientRect(hwndParent, &rect))
        return NULL;

    // Create the scroll bar.
    return (CreateWindowEx( 
            0,                      // no extended styles 
            L"SCROLLBAR",           // scroll bar control class 
            (PTSTR) NULL,           // no window text 
            WS_CHILD | WS_VISIBLE   // window styles  
                | SBS_HORZ,         // horizontal scroll bar style 
            rect.left,              // horizontal position 
            rect.bottom - sbHeight, // vertical position 
            rect.right,             // width of the scroll bar 
            sbHeight,               // height of the scroll bar
            hwndParent,             // handle to main window 
            (HMENU) NULL,           // no menu 
            g_hInst,                // instance owning this window 
            (PVOID) NULL            // pointer not needed 
        )); 
}

Schuifbalken gebruiken

demo van algemene besturingselementen van Windows (CppWindowsCommonControls)