I'm currently trying to implement some scrollbars in a Win32 control but they just don't work when setting the WS_HSCROLL flag.
From what I've read on other sites, they should "in theory" work because the class takes the message and does not push it to the parent window (Also that is how Rich controls work).
To add a horizontal scroll bar, use the style WS_HSCROLL; to add a vertical scroll bar, use the style WS_VSCROLL. An edit control with scroll bars processes its own scroll bar messages. Source
But for some reason, the scroll thingy does not move and if you try to move it manually it just returns the square to the start without doing any movement.
Here is an example code:
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR pStr, int nCmd)
{
WNDCLASS wcx = { 0 };
wcx.lpfnWndProc = DefWindowProc;
wcx.hInstance = hInst;
wcx.hCursor = LoadCursor(0, IDC_ARROW);
wcx.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_BTNFACE + 1);
wcx.lpszClassName = L"SIMPLEWND";
RegisterClass(&wcx);
int desktopwidth = GetSystemMetrics(SM_CXSCREEN);
int desktopheight = GetSystemMetrics(SM_CYSCREEN);
HWND hwnd = CreateWindowEx(0, L"SIMPLEWND", L"Main Window", WS_OVERLAPPEDWINDOW,
desktopwidth / 4, desktopheight / 4, desktopwidth / 2, desktopheight / 2, 0, 0, hInst, 0);
CreateWindow(L"edit", L"placeholder", WS_CHILD | WS_VISIBLE | WS_BORDER
| WS_HSCROLL | ES_AUTOHSCROLL, 10, 10, 200, 90, hwnd, (HMENU)1, hInst, 0);
ShowWindow(hwnd, nCmd);
MSG msg;
while (GetMessage(&msg, 0, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
I've also tried removing the ES_AUTOHSCROLL because I read that the scrollbar stops working when that style is set but nothing changes (Just that you can no longer scroll past the control rectangle)
Fixed it! Seems like both scrollbars work only when ES_MULTILINE is defined.
The original documentation does not say anything about it but that seems to be the case. I solved it by trying out this example and then removing stuff until it broke.