I am trying to position something w.r.t. a TJvTreeView, and I would like to know both the width and presence of the vertical scroll view. Does anyone know the canonical way to do that? Or failing that, any way that works?
Asked
Active
Viewed 209 times
1 Answers
2
Test for the presence of the WS_VSCROLL
window style:
HasVertScrollBar := (GetWindowLongPtr(hWnd, GWL_STYLE) and WS_VSCROLL) <> 0;
To find the width of system scroll bars, call SystemParametersInfo
passing SPI_GETNONCLIENTMETRICS
.
var
ncm: TNonClientMetrics;
....
ncm.cbSize := SizeOf(ncm);
Win32Check(
SystemParametersInfo(SPI_GETNONCLIENTMETRICS, ncm.cbSize, Pointer(@ncm), 0)
);
The scroll bar width can then be retrieved from ncm.iScrollWidth
.

David Heffernan
- 601,492
- 42
- 1,072
- 1,490
-
Thanks, that definitely solved the presence part of it. I am taking the width, by rough visual trial and error, to be 18, until I get a better way to work it out. – Mark Patterson Apr 04 '14 at 00:41
-
Oh. Didn't spot the width part. I'll get back to you on that. – David Heffernan Apr 04 '14 at 06:01
-
Thanks. That seems to right. I got it to work by scanning through the Delphi library code and ended up with this: procedure CalcVerticalScrollBarWidth; // Based on code in vcl.menus TMenuItem.MeasureItem var NonClientMetrics: TNonClientMetrics; begin NonClientMetrics.cbSize := NonClientMetrics.SizeOf; if SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, @NonClientMetrics, 0) then begin VerticalScrollBarWidth := NonClientMetrics.iScrollWidth; end; end; – Mark Patterson Apr 07 '14 at 07:24
-
My attempts to format that didn't work, then I ran out of editing time. I was hoping to add this at the start of that code: VerticalScrollBarWidth: integer = 17; – Mark Patterson Apr 07 '14 at 07:31