Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2009-08

How to query vertical scrollbar width?

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

Hi,

I'm working on some GUI code in the tiOPF project that currently works with VCL, LCL and fpGUI.

We are resizing the last column of a StringGrid so that we leave space for the vertical scrollbar - if it appears. Below is the Win32 API calls to query the scrollbar width for VCL.

Is there a cross-platfrom, LCL way to query the width of the current widgetset scrollbars? Defaults in Win2000 and WinXP seem to be 15px wide for the vertical scrollbar, but I am sure that with custom themes, that value might change. So we don't want to hard-code any values.

==================================
You can detect if the scrollbars are showing using the Win32 API like this:

if (GetWindowLong(StringGrid1.Handle, GWL_STYLE) and WS_VSCROLL) 0 then

     // Vertical scrollbar showing
   if (GetWindowLong(StringGrid1.Handle, GWL_STYLE) and WS_HSCROLL)  0

then

     // Horizontal scrollbar showing

You can get the size of the scrollbars using Win32 API function GetSystemMetrics().

GetSystemMetrics(SM_CYHSCROLL) // Height of horizontal scrollbar GetSystemMetrics(SM_CXVSCROLL) // Width of vertical scrollbar ==================================

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

Vincent Snijders
to Graeme Geldenhuys
Graeme Geldenhuys wrote 20 lines
Hi, I'm working on some GUI code in the tiOPF project that currently works with VCL, LCL and fpGUI. Is there a cross-platfrom, LCL way to query the width of the current widgetset scrollbars? Defaults in Win2000 and WinXP seem to be 15px wide for the vertical scrollbar, but I am sure that with custom themes, that value might change. So we don't want to hard-code any values. ================================== You can detect if the scrollbars are showing using the Win32 API like this: You can get the size of the scrollbars using Win32 API function GetSystemMetrics(). GetSystemMetrics(SM_CYHSCROLL) // Height of horizontal scrollbar GetSystemMetrics(SM_CXVSCROLL) // Width of vertical scrollbar ==================================

I would try:
http://lazarus-ccr.sourceforge.net/docs/lcl/lclintf/getsystemmetrics.html

Vincent

Reply by email

Graeme Geldenhuys
to Vincent Snijders
Vincent Snijders wrote

Thanks Vincent, that got me 80% there... :-)

Unfortunately my problems tend to me more difficult than normal. Under GTK (I don't know about other GUI toolkits or other themes), the scrollbar can sometimes be outside the component. See attached screenshot, where I am using the popular GTK ClearLooks theme.

The call: GetSystemMetrics(SM_CXVSCROLL); does indeed return the width of a Vertical Scrollbar - in my case it is 15 pixels. But what about the small gap between the StringGrid and the Vertical Scrollbar? How do I get that value?

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/ -------------- next part -------------- A non-text attachment was scrubbed... Name: system_metrics.png Type: image/png Size: 2058 bytes Desc: not available URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20090819/25633c1f/attachment.png>

Reply by email