-
August 3rd, 2011, 03:03 PM
#1
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?
-
August 3rd, 2011, 06:19 PM
#2
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.
-
August 3rd, 2011, 10:11 PM
#3
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|