This sample offers a drop-in ready class that provides you easy access to the
STARTUPINFO structure offered by Windows through the GetStartupInfo API function. This allows you to size and position
your application's initial window exactly as the user, or the calling process,
desires. Amazing that these properties weren't built into VB in the first place,
but here they are ready for you to use.
The design decision to use a class module, CStartupInfo, allows me the
liberty of coercing the values to more VBish ones. For example, converting the
size and position values from pixels, as returned by the API, to twips, as VB
naturally prefers.
Using CStartupInfo couldn't be much easier, especially if you (correctly) use
Sub Main as the startup procedure for your application. Simply declare an
instance of the class, and start assigning its values to your main form:
Public Sub Main()
Dim si As CStartupInfo
Dim frm As FStartupDemo
Set si = New CStartupInfo
Set frm = New FStartupDemo
' Check for requested size/position.
If (si.Left <> 0) And (si.Top <> 0) Then
frm.Move si.Left, si.Top
End If
If (si.Width <> 0) And (si.Height <> 0) Then
frm.Move frm.Left, frm.Top, si.Width, si.Height
End If
' Set to requested WindowState and show.
frm.WindowState = si.WindowState
frm.Show
End Sub
Although this module is marked VBA-Ready, and I have no doubt that it would
"work" there, it's somewhat beyond me of what utility it may be in that
environment?