Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to get the actual height of the taskbar? 1

Status
Not open for further replies.

Nifrabar

Programmer
Mar 16, 2003
1,343
NL
Hi!
I automaticly do resize forms according the methods as given in 1001 things. But it seems that I have to adjust the multiplier for the form's height with the taskbars' height. So, how to get the actual taskbar's height?
Sysmetric() does not give help for this.
-Bart
 

This will do it.
Code:
TaskBarHeight()
Function TaskBarHeight
Declare Integer GetWindowRect In user32;
	INTEGER HWnd, String lpRect
Declare Integer FindWindow In user32;
	STRING lpClassName,;
	STRING lpWindowName

Local cBuffer
cBuffer = Replicate(Chr(0), 16)
hWindow= FindWindow('Shell_TrayWnd', '')
cRect = GetWinRect(hWindow)
?	"The height of your taskbar is "+trans(buf2dword(Substr(cRect, 13,4))-buf2dword(Substr(cRect, 5,4)))
Function GetWinRect(hWindow)
Local cBuffer
cBuffer = Replicate(Chr(0), 16)
= GetWindowRect(hWindow, @cBuffer)
Return cBuffer
Function buf2dword(lcBuffer)
Return Asc(Substr(lcBuffer, 1,1)) + ;
	BitLShift(Asc(Substr(lcBuffer, 2,1)),  8) +;
	BitLShift(Asc(Substr(lcBuffer, 3,1)), 16) +;
	BitLShift(Asc(Substr(lcBuffer, 4,1)), 24)



Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
ReFox XI (www.mcrgsoftware.com)
 
Mike,

I implemeted your code in my frmresize method.
It does what I want but as the user also may have docked the taskbar to the left,right or top I do have to take that into account.
Is there a way to detect where the taskbar has been docked and what the actual width is once docked left or right?

-Bart
 
Bart,

Here is the taskbar position function. If you move the taskbar to the side of the screen, you will notice the values change.
Code:
TaskBarPosition()
Function TaskBarPosition
Declare Integer GetWindowRect In user32;
	INTEGER HWnd, String lpRect
Declare Integer FindWindow In user32;
	STRING lpClassName,;
	STRING lpWindowName

Local cBuffer
cBuffer = Replicate(Chr(0), 16)
hWindow= FindWindow('Shell_TrayWnd', '')
cRect = GetWinRect(hWindow)
? "Left position "+Transform(buf2dword(Substr(cRect, 1,4)) )
?  "Top position "+Transform(buf2dword(Substr(cRect, 5,4)) )
?	"Right position "+  Transform(   buf2dword(Substr(cRect, 9,4)) )
?	"Bottom position "+    Transform( buf2dword(Substr(cRect, 13,4)) )

Function GetWinRect(hWindow)
Local cBuffer
cBuffer = Replicate(Chr(0), 16)
= GetWindowRect(hWindow, @cBuffer)
Return cBuffer
Function buf2dword(lcBuffer)
Return Asc(Substr(lcBuffer, 1,1)) + ;
	BitLShift(Asc(Substr(lcBuffer, 2,1)),  8) +;
	BitLShift(Asc(Substr(lcBuffer, 3,1)), 16) +;
	BitLShift(Asc(Substr(lcBuffer, 4,1)), 24)

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
ReFox XI (www.mcrgsoftware.com)
 
Mike,
Thanks again.
1- Will these functions be available always? Or might an administrator block certain things?
2- Could I have found your solution from MSDN as well?
I 'm alway surprised about the many solutions you seem to have for almost every Q......
-Bart
 
Mike used standard WinApi functions, so they will always be available (as opposed to WMI, or Windows Script Host, which are often disabled)

- Bill

Get the best answers to your questions -- See FAQ481-4875.
 
1- Will these functions be available always? Or might an administrator block certain things?

They a API calls, so no, no blocking.

Could I have found your solution from MSDN as well?

Don't know I never looked there.







Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
ReFox XI (www.mcrgsoftware.com)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top