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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detecting Windows Status Bar attributes 2

Status
Not open for further replies.

SnyAc

Programmer
Jul 25, 2001
272
US
I'd like to be able to determine if the Windows Status bar is on Auto-Hide, and if not what it's height is.

Any suggestions?

Andy Snyder
SnyAc Software Services
 
If you're talking about the task bar, then the height of the bar is constant regardless of whether it's on auto-hide or not. When it's on auto-hide, the top of bar is moved below the bottom of the screen when hidden.

The task bar is nothing more than a window, so get it's height, you need to first get its handle.

Code:
DECLARE Long FindWindow IN user32 AS API_FindWindow String@, String@

lLng_TaskHWnd = API_FindWindow("Shell_TrayWnd", 0)

Once you have the handle, then get the rectangle which describes the size and position of the window.

Code:
DECLARE Long GetWindowRect IN user32 As API_GetWindowRect Integer, String@

lStr_WindowRect = SPACE(16)
lLng_RetVal = API_GetWindowRect (lLng_TaskHWnd, @lStr_WindowRect)
lLng_TaskLeft = ConvertStringToInteger (lStr_WindowRect, 1)
lLng_TaskTop = ConvertStringToInteger (lStr_WindowRect, 5)
lLng_TaskRight = ConvertStringToInteger (lStr_WindowRect, 9)
lLng_TaskBottom = ConvertStringToInteger (lStr_WindowRect, 13)

I use my own ConvertStringToInteger function to exact the actual values from the 16-byte rectangle structure.

Code:
FUNCTION ConvertStringToInteger (vStr_FullString, vInt_Offset) As Integer

   LOCAL lInt_RetVal			As Integer

   lInt_RetVal = 0

   IF (vInt_Offset + 3 <= LEN(vStr_FullString))
      lInt_RetVal = ASC(SUBSTR(vStr_FullString, vInt_Offset + 3, 1)) * 16777216 + ;
                    ASC(SUBSTR(vStr_FullString, vInt_Offset + 2, 1)) *    65536 + ;
                    ASC(SUBSTR(vStr_FullString, vInt_Offset + 1, 1)) *      256 + ;
                    ASC(SUBSTR(vStr_FullString, vInt_Offset + 0, 1))
   ENDIF

   IF (lInt_RetVal > 2147483648)
      lInt_RetVal = lInt_RetVal - 4294967295 - 1
   ENDIF
	
   RETURN lInt_RetVal

ENDFUNC


--------------
Good Luck
To get the most from your Tek-Tips experience, please read
FAQ181-2886
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Andy,

The way I do this is to get the physical height of the screen, and subtract the physical screen's "client area" (not sure if that's the correct term, but it relates to the screen minus the taskbar).

The physical screen is given by SYSMETRIC(2). That will return 768 if the resolution is set to 1024 x 768, for instance.

The client area is given by the SystemParametersInfo() API function:

Code:
* Returns the height of the physical screen, taking
* account of the taskbar, if visible.

LOCAL lcBuffer, lcDWord

lcBuffer = SPACE(16)
SystemParametersInfo(48, 0, @lcBuffer, 0)

lcDWord = SUBSTR(lcBuffer, 13, 4)
  && or take bytes 9-12 for the screen width

RETURN ASC(SUBSTR(lcDWord, 1,1)) + ;
  BITLSHIFT(ASC(SUBSTR(lcDWord, 2,1)),  8) +;
  BITLSHIFT(ASC(SUBSTR(lcDWord, 3,1)), 16) +;
  BITLSHIFT(ASC(SUBSTR(lcDWord, 4,1)), 24)

If the taskbar is hidden, the two functions should give the same result. If they don't, the difference is the height of the taskbar.

Keep in mind that the taskbar might be at the left or right edge of the screen, rather than the bottom (or top). To do it properly, you also need to use SYSMETRIC(1) to find the physical width, and the relevant bytes from the SystemParametersInfo() buffer, as indicated by the comment in the above code.

I hope this answers your question.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top