|
-
Aug 16th, 2000, 07:34 AM
#1
I want to resize a VB forms width and height to the available Screen.
By available screen I mean the screen excluding the startbar and other toolbars.
I have managed to do this using an API:
Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" _
(ByVal uAction As Long, _
ByVal uParam As Long, _
lpvParam As Any, _
ByVal fuWinIni As Long) As Long
r = SystemParametersInfo(SPI_GETWORKAREA, 0&, rc, 0&)
AvailableLeft = rc.Left * Screen.TwipsPerPixelX
AvailableRight = rc.Right * Screen.TwipsPerPixelX
AvailableTop = rc.Top * Screen.TwipsPerPixelY
AvailableBottom = rc.Bottom * Screen.TwipsPerPixelY
Does any bright spark know how I can position the forms TOP and LEFT position to be within the available screen area?
So for example if I move my start bar to the top of the screen the form will be resized to the free space at the bottom of the screen and will be positioned below the start bar?
-
Aug 16th, 2000, 07:49 AM
#2
Junior Member
Form sizing
If you run a form specified as maximized then it will always take up all the screen except those areas taken up by the Start Menu and other special toolbars that Windows may be running (Office etc).
Furthermore, if you move the Windows Start Menu then it should accomodate you.
-
Aug 16th, 2000, 08:15 AM
#3
_______
<?>
Are you talking running at max and filling screens with different resolutions?
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Aug 16th, 2000, 08:27 AM
#4
I am just finishing a ActiveX control to dynamically resize all controls on the form.
As part of the routine I want to maximize the screen at any resolution and resize all the controls so that they look the same.
I have two routines.
(1) Form Resize.
(2) Control Resize.
The control resize is working very well. The problem I have is that I cannot easily use form.windowstate=maximized
(for complexity reasons that I won't go into) to resize the form before I resize the controls.
So I need to set the form to be in the correct position and of the correct width and height (yes I know its a nighmare!) but I am so close to getting the control done!
-
Aug 16th, 2000, 08:30 AM
#5
_______
<?>
I didn't write this but perhaps you can find what you are after in it.
Code:
'resize as per secreen resolution
'general declaration of form
'==================================================================
'create a class module and put this code into it
'set the name property of the object as clsElasticForms
'save as clsElastic
Option Explicit
' Title: Elastic Forms
' Author: Leigh Bowers
' Email: [email protected]
' WWW: http://www.esheep.freeserve.co.uk/compulsion
' Version: 1.01
' Date: 19th June 1999
' Requires: N/A
' License: Freely Distributable (non-commercial use)
Private fForm As Form
Private lOriginalWidth As Long
Private lOriginalHeight As Long
Private lMinWidth As Long
Private lMinHeight As Long
Private Type udtControl
lLeft As Long
lTop As Long
lWidth As Long
lHeight As Long
End Type
Private aControls() As udtControl
Public Property Let Form(ByVal fPassForm As Form)
Dim iCount As Integer
Dim cControl As Control
Set fForm = fPassForm
' Store form's original Width & Height
lOriginalWidth = fForm.Width
lOriginalHeight = fForm.Height
' Use error trapping to ignore components that don't
' support certain properties being read at run-time
On Error Resume Next
' Store the form's component's properties
iCount = 0
ReDim aControls(fForm.Controls.Count)
For Each cControl In fForm.Controls
iCount = iCount + 1
With aControls(iCount)
If TypeOf cControl Is Line Then
.lLeft = cControl.X1
.lTop = cControl.Y1
.lWidth = cControl.X2
.lHeight = cControl.Y2
Else
.lLeft = cControl.Left
.lTop = cControl.Top
.lWidth = cControl.Width
.lHeight = cControl.Height
End If
End With
Next ' Each
End Property
Public Sub FormResize()
' v1.01 (19/06/1999)
'
' bDisableResize:
' Used to avoid unnecessary *recursive* resizing
'
' lPreviousWidth/Height:
' Used to avoid unnecessary resizing
' Resize the form's controls
Dim iCount As Integer
Dim cControl As Control
Dim iTaskBarHeight As Integer
Dim sOriginalWidthUnit As Single
Dim sOriginalHeightUnit As Single
Static bDisableResize As Boolean
Static lPreviousWidth As Long
Static lPreviousHeight As Long
If fForm Is Nothing Or bDisableResize Then Exit Sub
' Don't process minimized forms
If fForm.WindowState = vbMinimized Then Exit Sub
' Check form size against minimums
bDisableResize = True
If fForm.Width < lMinWidth Then fForm.Width = lMinWidth
If fForm.Height < lMinHeight Then fForm.Height = lMinHeight
bDisableResize = False
' Ensure form size has changed
If lPreviousWidth = fForm.Width And lPreviousHeight = fForm.Height Then Exit Sub
lPreviousWidth = fForm.Width
lPreviousHeight = fForm.Height
' Perform calculations in advance (speed increase)
iTaskBarHeight = 28 * Screen.TwipsPerPixelY ' Standard height
sOriginalWidthUnit = lOriginalWidth / fForm.Width
sOriginalHeightUnit = (lOriginalHeight - iTaskBarHeight) / (fForm.Height - iTaskBarHeight)
' Use error trapping to ignore components that don't
' support certain properties being set at run-time
On Error Resume Next
' Do the resize...
iCount = 0
For Each cControl In fForm.Controls
iCount = iCount + 1
With cControl
If TypeOf cControl Is Line Then
.X1 = Int(aControls(iCount).lLeft / sOriginalWidthUnit)
.Y1 = Int(aControls(iCount).lTop / sOriginalHeightUnit)
.X2 = Int(aControls(iCount).lWidth / sOriginalWidthUnit)
.Y2 = Int(aControls(iCount).lHeight / sOriginalHeightUnit)
Else
.Left = Int(aControls(iCount).lLeft / sOriginalWidthUnit)
.Top = Int(aControls(iCount).lTop / sOriginalHeightUnit)
.Width = Int(aControls(iCount).lWidth / sOriginalWidthUnit)
.Height = Int(aControls(iCount).lHeight / sOriginalHeightUnit)
End If
End With
Next ' Each
End Sub
Private Sub Class_Terminate()
Set fForm = Nothing
End Sub
Public Property Let MinWidth(ByVal lPassMinWidth As Long)
lMinWidth = lPassMinWidth
End Property
Public Property Let MinHeight(ByVal lPassMinHeight As Long)
lMinHeight = lPassMinHeight
End Property
'====================================================================
' in the general declarations of each form in your application
Option Explicit
Private clsElastic As clsElasticForms
'====================================================================
'this goes in the form load event of each form in app
Set clsElastic = New clsElasticForms
clsElastic.Form = Me
clsElastic.MinHeight = 1950
clsElastic.MinWidth = 6960
'====================================================================
'this goes in the form resize event of each form in app
'resize as per secreen resolution
clsElastic.FormResize
'====================================================================
'this goes in the Form_Unload(Cancel As Integer) of each form
'in the app
'resize as per secreen resolution
Set clsElastic = Nothing
'====================================================================
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Aug 16th, 2000, 08:37 AM
#6
Thankyou for the suggested code.
I don't think it will help me as I already have a fully working control resize routine.
I just need to know about the available screen area.
All thoughts are welcome ;-)
-
Aug 16th, 2000, 08:43 AM
#7
_______
<?>
Sorry it was of no help.
PS
...if you are making this freeware I would like a copy when you get it finished.
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Aug 16th, 2000, 08:48 AM
#8
_______
<?>
an after thought...I have played with this but don't fully
understand the full of it but I used it in a project to set
the position of notepad...you would need to know the coordinates where you want it placed so if you can tell where your bar is located and calculate it's bottom postion, etc...
Code:
'specify the screen position of a window
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type WINDOWPLACEMENT
Length As Long
flags As Long
showCmd As Long
ptMinPosition As POINTAPI
ptMaxPosition As POINTAPI
rcNormalPosition As RECT
End Type
Private Declare Function SetWindowPlacement _
Lib "user32" (ByVal hwnd As Long, _
lpwndpl As WINDOWPLACEMENT) As Long
Private Declare Function GetWindowPlacement _
Lib "user32" (ByVal hwnd As Long, lpwndpl As _
WINDOWPLACEMENT) As Long
Private Declare Function FindWindow Lib _
"user32" Alias "FindWindowA" (ByVal lpClassName _
As String, ByVal lpWindowName As String) As Long
Private Declare Function SetRect Lib "user32" _
(lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, _
ByVal X2 As Long, ByVal Y2 As Long) As Long
'==========================================
Private Sub Command1_Click()
Dim WndPlace As WINDOWPLACEMENT
Dim h As Long
Dim RetVal
RetVal = Shell("C:\WINDOWS\notepad.exe C:\A VB Tips\alpha only.txt", 1)
'Shell "Notepad", vbHide
h = FindWindow("Notepad", vbNullString)
If h <> 0 Then
WndPlace.Length = Len(WndPlace)
Call GetWindowPlacement(h, WndPlace)
Call SetRect(WndPlace.rcNormalPosition, 0, 3700, WndPlace.rcNormalPosition.Right, 4000)
Call SetWindowPlacement(h, WndPlace)
End If
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Aug 16th, 2000, 08:55 AM
#9
Thankyou I think that API will do the job. I've used it before but had forgotten about it!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|