How to: Get the current Windows taskbar height

Just starting out? Need help? Post your questions and find answers here.
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

How to: Get the current Windows taskbar height

Post by charvista »

Every Windows system has a taskbar. The taskbar height can differ on each computer, even set to auto-hide...
I would like to use OpenWindow() with the height of the screen less the height of the taskbar, so that it is always visible and can be reached.
How can I get the current height setting?
Thanks.
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: How to: Get the current Windows taskbar height

Post by netmaestro »

The taskbar can also be in different positions, not necessarily on the bottom of the screen. The way to accomplish your goal is to use SystemParametersInfo_() with #SPI_GETWORKAREA. This will give you the position and size of the desktop excluding the taskbar and you can create your window according to the returned rectangle.
BERESHEIT
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: How to: Get the current Windows taskbar height

Post by charvista »

Many thanks Netmaestro. I could find it further on the forum by searching for SystemParametersInfo_.
The solution:

Code: Select all

         SystemParametersInfo_(#SPI_GETWORKAREA, 0, @DesktopRect.RECT, 0)
         DesktopX = DesktopRect\left
         DesktopY = DesktopRect\top
         DesktopWidth = DesktopRect\right - DesktopRect\left
         DesktopHeight = DesktopRect\bottom - DesktopRect\top
         Debug "OpenWindow("+Str(DesktopX)+", "+Str(DesktopY)+", "+Str(DesktopWidth)+", "+Str(DesktopHeight)+")"
Have a good day.
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: How to: Get the current Windows taskbar height

Post by netmaestro »

Almost. You have to take into account that a PB window opened to supplied width and height will have a client area with those dimensions. You'll have to subtract the caption and borders to get what you're looking for:

Code: Select all

SystemParametersInfo_(#SPI_GETWORKAREA, 0, @DesktopRect.RECT, 0)
DesktopX = DesktopRect\left
DesktopY = DesktopRect\top
DesktopWidth = DesktopRect\right - DesktopRect\left
DesktopHeight = DesktopRect\bottom - DesktopRect\top
DesktopWidth-GetSystemMetrics_(#SM_CXFIXEDFRAME)*2
DesktopHeight-(GetSystemMetrics_(#SM_CYCAPTION)+GetSystemMetrics_(#SM_CYFIXEDFRAME)*2)

OpenWindow(0,DesktopX,DesktopY,DesktopWidth,DesktopHeight,"",#PB_Window_SystemMenu)

Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
BERESHEIT
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: How to: Get the current Windows taskbar height

Post by charvista »

Indeed, this is more accurate.
I appreciate your help very much.
Richard
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: How to: Get the current Windows taskbar height

Post by Kwai chang caine »

Thanks NETMAESTRO
I use your tips immediately, for my new application 8)
ImageThe happiness is a road...
Not a destination
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: How to: Get the current Windows taskbar height

Post by srod »

Kwaï chang caïne wrote:Thanks NETMAESTRO
I use your tips immediately, for my new application 8)
Everyone is advised to take cover, KCC is working on a new application! Lock up your dll's, hide those tips and tricks, and for God's sake don't let him near the drinks cabinet!

:twisted:

(Sorry KCC, I couldn't resist!)
I may look like a mule, but I'm not a complete ass.
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: How to: Get the current Windows taskbar height

Post by charvista »

Haha, there we have the good old Kwaï chang caïne :lol:
I'm glad the code will be of use in your new application ! :twisted:
Hopely you will share it with us when finished :wink:
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: How to: Get the current Windows taskbar height

Post by Kwai chang caine »

My MASTER wrote:Everyone is advised to take cover, KCC is working on a new application! Lock up your dll's, hide those tips and tricks, and for God's sake don't let him near the drinks cabinet!
Oooohh, my master give to me the great honor to insult me :D
It's already a pleasure to read you :P
Even when you take your legs was shot, for go far of KCC 8)
It's a too long time, that i have not "blablabla" with you :?

My dream....you and me alone in a farmhouse :roll:

Image

Me i drunk you with all my question...you like my grandma.... always answer to me, and kind with your little KCC, and in the same time, you knit socks or scarf for KCC against the hard winter :roll:

I'm sure it's also your dream...i'm sure :mrgreen:

@CHARVISTA
Yes ....it's for my tiny "FlowChart" 8)
For be sure the windows is open a maximum
Thanks for your kind message :wink:
ImageThe happiness is a road...
Not a destination
Post Reply