Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Serbia and Montenegro (Yugoslavia)
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Detect if Form is open (VB6)

    Can anyone help me with a method to detect if a VB form is currently displayed?

    I have an MDI form that I am displaying child forms in, and I have a menu bar to switch between the child forms. I want to hide or unload one form before the other displays.

  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Detect if Form is open (VB6)

    You can use an API call: either GetWindow if it'sa child window of another open window (form) or FindWindow if it's a top level window.
    If the return value is zero, you know the window is NOT open.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  3. #3
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Detect if Form is open (VB6)

    Why not just hide all of them before any load?
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  4. #4
    2 Star Lounger
    Join Date
    Nov 2001
    Location
    London, UK, England
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Detect if Form is open (VB6)

    This is a function I use to detect if a form is loaded, but you could change the syntax to test for various things...eg if it is the MDIForm.Activeform or if it is visible etc

    ' // ************************************************** ****************************
    ' // FUNCTION
    ' // IsFormLoaded(frm As Form) as Boolean
    ' //
    ' // PARAMETERS
    ' // fForm - The form to check to see if it is loaded
    '
    ' // RETURN VALUE
    ' // <TRUE> if the form is loaded
    ' //
    ' // COMPONENTS USED
    ' // None
    ' //
    ' // NOTES
    ' // Returns true if the passed form is loaded in the forms collection
    ' // ************************************************** ****************************

    Public Function IsFormLoaded(fForm As Form) As Boolean
    On Error GoTo Err_Proc

    Dim x As Integer

    For x = 0 To Forms.Count - 1
    If (Forms(x) Is fForm) Then
    IsFormLoaded = True
    Exit Function
    End If
    Next x

    IsFormLoaded = False

    Exit_Proc:
    Exit Function

    Err_Proc:
    Msgbox Err.Description
    Resume Exit_Proc

    End Function

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Detect if Form is open (VB6)

    Mike,

    Is it too simple-minded to use something like

    Dim frm As Form

    Set frm = Form1
    If frm.Visible = True Then
    frm.Hide
    End If

    That doesn't load Form1 if it isn't loaded already but it will hide it if it is visible.
    Charlotte

Posting Permissions

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