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:

Color-coded with vbMarkUp - try it today!
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
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?


This sample, or the one from which it originally derived, was published (or at least peripherally mentioned) in the following article(s):

APIs Usage

This sample uses the following API calls:

Module Library Function
CStartupInfo.cls kernel32

FStartupDemo.frm user32 SendMessage
MStartupLaunch.bas kernel32 CreateProcess

Don't see what you're looking for? Here's a complete API cross-reference.


Download   Please, enjoy and learn from this sample. Include its code within your own projects, if you wish. But, in order to insure only the most recent code is available to all, I ask that you don't share the sample by any form of mass distribution.

Download, 15Kb, Last Updated: Monday, April 26, 2010

See Also

The following resources may also be of interest: