Re: VB6 App QueryUnload event problem when app minimized

Tech-Archive recommends: Fix windows errors by optimizing your registry




"William Hildebrand" <wahilde@xxxxxxxxxxxx> wrote in message
news:11arpabo5vevbb4@xxxxxxxxxxxxxxxxxxxxx
> Hello,
>
> I have a VB6 app that checks in the QueryUnload event if the user has
> finished doing certain things in the app before we let them close the
> form.
> If it's OK for them to close the form (which is the whole application)
> then
> the form closes OK whether or not it's displayed or minimized. If it's
> NOT
> OK for them to close the form, then we show a modal form (from within the
> QueryUnload event) giving them a message that they must complete certain
> things before they can close the application and we set the cancel flag so
> that the form won't unload. This works fine when the main form is
> displayed
> on the screen, but if the user tries to close the application when the
> main
> form is minimized on the task bar then they get the modal form all
> greyed-out and the whole application is frozen. If we use the regular VB
> message box for the message to the user then it works OK, but it doesn't
> give us the flexibility of showing a modal form that we have designed.
>
> I have created a tiny VB6 project that demonstrates the problem. I can't
> debug it because it works OK if you run it VB debug mode. It only freezes
> up when you run the EXE. The newsgroup won't let me attach the tiny
> zipped
> VB6 project I wrote, so email me and I'll send it to you if you want to
> look
> at it. Also, since that's the case, I guess I'll put the code here below.
> There are just two standard forms for this project. That's it.
>
> Here's the code for the main form (Form1):


Well, I encountered the "problem" even within the IDE (VB6 SP5 under WinXP
SP2). One solution is fairly simple, though. Check the WindowState of the
main window before showing the modal form. If it's minimized, restore the
main window first and then show the modal form.

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

If bUnload = False Then
If WindowState = vbMinimized Then
WindowState = vbNormal
DoEvents
End If
Form2.Show vbModal, Me
Cancel = 1
Exit Sub
End If

' This line's not really necessary
' Cancel = 0

End Sub

I'm not sure if I'd consider this a bug or not. IMO, it'd be "proper" to
restore the main form anyway.

--
Mike
Microsoft MVP Visual Basic



.