Vectolist
Vectolist

Reputation: 13

C++ win32 Get ScrollBar contol size

example

To custom-draw a whole scrollbar, is there a way to get the rectangles of the scrollbar's parts (SB_LINEUP, SB_LINEDOWN, SB_THUMBTRACK, etc)?

mainHwnd = CreateWindowEx(NULL, wc.lpszClassName, WC_WINDOW,
        WS_POPUP | WS_VISIBLE | WS_VSCROLL, 600, 400, 700, 380, nullptr, 0, wc.hInstance, NULL);

Upvotes: 0

Views: 600

Answers (1)

Vectolist
Vectolist

Reputation: 13

Onpaint

    case WM_PAINT: {
    PAINTSTRUCT ps{};
    HDC dc = BeginPaint(hwnd, &ps);
    int count;
    int lineCount = 0;
    int startLine = GetScrollPos(hwnd, SB_VERT);
    int endLine = startLine + rows;
    int strLength = 0;
    CHAR buf[10];
    SetTextColor(dc, RGB(190, 190, 190));
    SetBkMode(dc, TRANSPARENT);
    for (count = startLine; count < endLine; count++) {
        strLength = sprintf(buf, "%d", count);
        TextOut(dc, 12, lineCount, buf, strLength);
        lineCount = lineCount + fontHeight;
    }
    SCROLLBARINFO info{};
    info.cbSize = sizeof(SCROLLBARINFO);
    GetScrollBarInfo(hwnd, OBJID_VSCROLL, &info);

    RECT rc = info.rcScrollBar;
    MapWindowPoints(HWND_DESKTOP, hwnd, (POINT*)&rc, 2);
    rc.left -= 50;
    FillRect(dc, &rc, br);

    EndPaint(hwnd, &ps);
}break;

@Remy Lebeau @beothunder

thx a lot:)

i gotta try avoid default paint :(

simple unittest VS2017

Upvotes: 1

Related Questions