CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2009
    Posts
    100

    VB6 Reload Application

    I am writing an application for (of all things) a character generator for an RPG that I am intimately familiar with. I can handle almost anything that is being thrown at me with this application, except this one tiny thing: reloading the application.

    I have an MDI form (frmMain), and several MDI child windows. Any or all of the child windows can be open at one time. frmMain has a menu, and one of the options is File->New. When this is clicked, the application needs to reload, or reset itself to the state it was in upon initial open. No big deal, right? Well, for me it is.

    Any or all of the child windows can be open at any given point, and when New is clicked all child windows need to be closed. Resetting of local and global variables within frmMain isn't an issue. The issue is closing the child windows that are open.

    I've seen 2 API functions out on the net that might hold the solution to this: GetActiveWindow and GetParent. However, I'm not that versed in API functions, so I'm a little stuck on this. So my questions are:

    1. Which of these API functions will work better for pulling this off?
    2. Does someone know of a tutorial regarding these API functions that they can point me to? (Note - I looked at allapi.mentalis.org, and I can't figure out what they are doing there with either of these.)
    3. Is there an easier way to reload the entire application?

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: VB6 Reload Application

    Assuming your MDI Parent form is named MDIForm1 you could use something like this to close open forms while leaving the parent open.

    Code:
    Dim frm As Form
    
    For Each frm In Forms
        If frm.Name <> "MDIForm1" Then
            Unload frm
        End If
    Next
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: VB6 Reload Application

    I'd use this, to finally close the master

    Code:
    Option Explicit
    
    Dim AllowUnload As Boolean
    
    Private Sub MDIForm_Load()
        Form1.Show
        Form2.Show
        Form3.Show
    End Sub
    
    Private Sub MDIForm_QueryUnload(Cancel As Integer, UnloadMode As Integer)
        If UnloadMode = vbFormControlMenu Then
            AllowUnload = True
        End If
    End Sub
    
    Private Sub MDIForm_Unload(Cancel As Integer)
        If AllowUnload Then
            Exit Sub
        End If
            Cancel = True
        AllowUnload = True
    End Sub
    
    Private Sub mnuClose_Click()
        AllowUnload = False
        Unload Me
    End Sub
    
    Private Sub mnuExit_Click()
        AllowUnload = True
        Unload Me
    End Sub
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

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

Featured