Results 1 to 5 of 5

Thread: Displaying multiple VB forms at start-up

  1. #1

    Thread Starter
    Frenzied Member mlewis's Avatar
    Join Date
    Sep 2000
    Posts
    1,226
    Ok for the first question:

    Add a Module
    In the module, add this code:

    VB Code:
    1. Public Sub Main()
    2.  Load frm1
    3.  Load frm2
    4.  ' etc.
    5. End Sub

    Now rightclick the project name in the file list and select Properties, then change Startup Object to SubMain



    For the screen size, you can use the SysInfo control (Project, Components...scroll thru list, find Microsoft System info, check the box by it, and hit OK)
    M. Lewis
    Pi-Q Software
    How many mouse clicks does it take to cook breakfast?

    Blargh! I am dead!

  2. #2
    Megatron
    Guest
    Actually, you don't event need a module. You can just load the 2nd Form from the first Form's load event. Also, frm Load only calls the Form's load event. You need to use the Show method to display it on the screen (unless you already have the code to do this in your 2nd Form)
    Code:
    Form2.Show
    For the screen size, and relative positioning, use the Screen object. It contains a Width, ScaleWidth, Height, and ScaleHeight property.

  3. #3

    Thread Starter
    Frenzied Member mlewis's Avatar
    Join Date
    Sep 2000
    Posts
    1,226
    OK I'll concede the Show thing but loading from Sub Main is better, because if you reload the form later it will try to reload the other form, and if the other form is still open -- poof, you have a crash.

    Also, loading from SubMain is better coding practice because its easier to follow.
    M. Lewis
    Pi-Q Software
    How many mouse clicks does it take to cook breakfast?

    Blargh! I am dead!

  4. #4
    Member
    Join Date
    Oct 2001
    Location
    Oklahoma
    Posts
    36
    To MLewis,
    Thank you ! Thank you! Thank you! The Microsoft Sysinfo control did the trick. Here's the code that the I was able to put up in the Module's Sub Main():


    Public lngHeight as Long ' variable to hold the screen's workarea height


    Public Sub Main()
    lngHeight = MDIForm1.SysInfo1.WorkAreaHeight
    frmLibrary.Move 0, 0, Screen.Width / 5, lngHeight
    MDIForm1.Move Screen.Width / 5, 0, (Screen.Width * 4) / 5, lngHeight
    frmLibrary.Show
    MDIForm1.Show
    End Sub




    Thank you again!!!!!

  5. #5
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    If you don't want to use a control for getting the workarea, you can use the SystemsParameterInfo API function.
    The comments are in Dutch, sorry.

    Put the following code in a standard module (.bas)
    Code:
    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
    
    Public Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
    End Type
    
    Private Const SPI_GETWORKAREA = 48
    
    Public Sub GetWorkArea(ByRef udtRect As RECT)
    ' deze functie haalt de afmetingen van de workarea van de desktop op
    ' de taskbar, en application bars blijven hierdoor zichtbaar
    Dim lngRet As Long
        ' haal de workarea op (functie retourneert afmetingen in pixels)
        lngRet = SystemParametersInfo(SPI_GETWORKAREA, 0, udtRect, 0)
        ' omrekenen naar twips
        With udtRect
            .Left = .Left * Screen.TwipsPerPixelX
            .Top = .Top * Screen.TwipsPerPixelY
            .Right = .Right * Screen.TwipsPerPixelX
            .Bottom = .Bottom * Screen.TwipsPerPixelY
        End With
    End Sub

    You can use the function like this:
    In a form
    Code:
    Private Sub MDIForm_Load()
    Dim udtRect As RECT
        ' haal de maximum afmetingen op van de desktop
        Call GetWorkArea(udtRect)
        ' resize naar de maximale afmetingen
        Me.Move udtRect.Left, udtRect.Top, udtRect.Right - udtRect.Left, udtRect.Bottom - udtRect.Top

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width