VB and VBA Users Source Code: Fit a form to the desktops workarea
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Fit a form to the desktops workarea
By:
rosquist
Email (spam proof):
Email the originator of this post
Date:
Monday, November 13, 2000
Hits:
561
Category:
Windows API
Article:
In Windows 2000 the SystemParametersInfo doesn't take the taskbar into account. If you want to maximize the form to cover the screen and not the taskbar you can do this: In a module: Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Public Const SPI_GETWORKAREA = 48 Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" _ (ByVal uAction As Long, ByVal uParam As Long, lpvParam As Any, ByVal fuWinIni As Long) As Long Type APPBARDATA cbSize As Long hwnd As Long uCallbackMessage As Long uEdge As Long rc As RECT lParam As Long ' message specific End Type Public Declare Function SHAppBarMessage Lib "shell32.dll" _ (ByVal dwMessage As Long, pData As APPBARDATA) As Long Public Const ABS_ALWAYSONTOP = &H2 Public Const ABS_AUTOHIDE = &H1 Public Const ABS_BOTH = &H3 Public Const ABM_GETSTATE = &H4 Public Const ABM_GETTASKBARPOS = &H5 Public Const ABE_BOTTOM = 3 Public Const ABE_LEFT = 0 Public Const ABE_RIGHT = 2 Public Const ABE_TOP = 1 In the form: 'Add a texbox and a commandbutton Private Sub Command_Click() Dim rc As RECT Dim X As Long X = SystemParametersInfo(SPI_GETWORKAREA, vbNull, rc, 0) Dim TBarData As APPBARDATA Dim ret As Long ret = SHAppBarMessage(ABM_GETTASKBARPOS, TBarData) Select Case TBarData.uEdge Case ABE_BOTTOM Text1.Text = "Taskbar is to the bottom" Me.Move rc.Left * Screen.TwipsPerPixelX, _ rc.Top * Screen.TwipsPerPixelY, _ rc.Right * Screen.TwipsPerPixelX, _ (rc.Bottom + TBarData.rc.Top - TBarData.rc.Bottom + 2) * Screen.TwipsPerPixelY Case ABE_LEFT Text1.Text = "Taskbar is to the left" Me.Move (rc.Left + TBarData.rc.Right + 2) * Screen.TwipsPerPixelX, _ rc.Top * Screen.TwipsPerPixelY, _ (rc.Right - TBarData.rc.Right) * Screen.TwipsPerPixelX, _ rc.Bottom * Screen.TwipsPerPixelY Case ABE_RIGHT Text1.Text = "Taskbar is to the right" Me.Move rc.Left * Screen.TwipsPerPixelX, _ rc.Top * Screen.TwipsPerPixelY, _ (rc.Right + TBarData.rc.Left - TBarData.rc.Right + 2) * Screen.TwipsPerPixelX, _ rc.Bottom * Screen.TwipsPerPixelY Case ABE_TOP Text1.Text = "Taskbar is to the top" Me.Move rc.Left * Screen.TwipsPerPixelX, _ (rc.Top + TBarData.rc.Bottom) * Screen.TwipsPerPixelY, _ rc.Right * Screen.TwipsPerPixelX, _ (rc.Bottom - TBarData.rc.Bottom) * Screen.TwipsPerPixelY End Select End Sub
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder