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

Screen height/width relative to taskbar... 1

Status
Not open for further replies.

CubeE101

Programmer
Nov 19, 2002
1,492
US
How do you get the Relative Height and/or Width of the Screen Object relative to the Task Bar...?

In Other words...

I have A form I would like to show on the right half of the screen, maximized Vertically, but when you say:
Code:
  Width = 11700
  [b]Height = Screen.Height[/b]
  Left = Screen.Width - Width
  Top = 0

The taskbar (positioned at the bottom of the screen) covers up the bottom part of the window...

I would like to be able to say something like...
Code:
  Width = 11700
  [b]Height = Screen.Height - [i]TaskBar.Height[/i][/b]
  Left = Screen.Width - Width
  Top = 0

But then You always have the possibility of the TaskBar being docked on another edge (left, top, or right) of the screen...

SO...

How would you get the RECT (Left, Top, Width, Height) of the TaskBar...

I'm guessing I'll have to use FindWindow API to get the hWnd, then the API to get it's RECT structure... (forgot the name, off the top of my head , I have it somewhere... ;-))

Is there an easier, more standardized, way of doing this?


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
I have had this problem before. Try the Sysinfo ocx control (Microsoft SysInfo Control 6.0)

This exposes 4 properties:-

SysInfo1.WorkAreaHeight
SysInfo1.WorkAreaLeft
SysInfo1.WorkAreaTop
SysInfo1.WorkAreaWidth

The WorkArea I think is the desktop. It is a while since I used it and had fairly good results with it but then again my memory is not what it used to be.

Worth a try?
 
Nice...

Code:
  Width = 11700
  Height = SI1.WorkAreaHeight
  Left = SI1.WorkAreaWidth - Width
  Top = SI1.WorkAreaTop

Works great!!!
Have a star ;-)


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
And here is the API method using the SystemParametersInfo function.
___
[tt]
Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByRef lpvParam As Any, ByVal fuWinIni As Long) As Long
Private Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long
Const SPI_GETWORKAREA = 48
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Sub Form_Load()
Dim rc As RECT
SystemParametersInfo SPI_GETWORKAREA, 0, rc, 0
MoveWindow hwnd, (rc.Left + rc.Right) \ 2, rc.Top, _
(rc.Right - rc.Left) \ 2, (rc.Bottom - rc.Top), 0
End Sub[/tt]
 
Cube,

Following on from Hypetia, here is a little sub which moves a form so that it is completely visible on the desktop if any of its borders are initially beyond it.

Sub FrmLegalPos(Fm As Form)

Dim ApiRect As RECT
' SPI_GETWORKAREA = 48
SystemParametersInfo 48, vbNull, ApiRect, 0

With ApiRect
.bottom = .bottom * Screen.TwipsPerPixelY
.Top = .Top * Screen.TwipsPerPixelY
.Left = .Left * Screen.TwipsPerPixelX
.right = .right * Screen.TwipsPerPixelX
End With

With Fm
If .WindowState = vbNormal Then
If .Left < ApiRect.Left Then .Left = ApiRect.Left
If .Left + .Width > ApiRect.right Then .Left = ApiRect.right - .Width
If .Top < ApiRect.Top Then .Top = ApiRect.Top
If .Top + .Height > ApiRect.bottom Then .Top = ApiRect.bottom - .Height
End If
End With

End Sub

regards Hugh
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top