Loading and Displaying a non-modal status form from a modally displayed form?

Loading and Displaying a non-modal status form from a modally displayed form?

Post by John Lew » Thu, 11 Sep 2003 06:04:03


Hey Everyone,

This problem has plagued me for the 10 years I have been programming with
vb. I have displayed a form modally:

form1.show vbModal

and then within a command button click event like:

command1_Click()

I run some code that performs a lengthy task, and I want to show the user
the status of that task. If I try to display a non-modal form and update a
label on that form with the status that I want to display, VB 6.0 will give
me an error saying that I cannot display a non-modal form when a modal form
is being displayed. I understand the reason for this error.

Now, of course I could just put a label on this modal form to display the
result, however my code is more modular and I simply want to be able to
display a form that displays a task's progress status regardless of whether
or not a modal window is being displayed.

This cannot be done in just vb. Does anyone know how I can accomplish this?

John Lewe
Orlando, FL
 
 
 

Loading and Displaying a non-modal status form from a modally displayed form?

Post by alpin » Thu, 11 Sep 2003 06:31:43

On Tue, 9 Sep 2003 17:04:03 -0400, "John Lewe"




Have a look at the following....

[ http://www.yqcomputer.com/ %404ax.com&rnum=6]


HTH,
Bryan
____________________________________________________________
New Vision Software "When the going gets weird,"
Bryan Stafford "the weird turn pro."
alpine_don' XXXX@XXXXX.COM Hunter S. Thompson -
Microsoft MVP-Visual Basic Fear and Loathing in LasVegas

 
 
 

Loading and Displaying a non-modal status form from a modally displayed form?

Post by Michael Cu » Thu, 11 Sep 2003 09:54:32

If the app is busy performing a long task wouldn't it be preferrable to show a modal form?
 
 
 

Loading and Displaying a non-modal status form from a modally displayed form?

Post by John Lew » Fri, 12 Sep 2003 05:36:01

The problem is that when you launch a modal form in code, your code stops
executing until that modal form is unloaded.

John




show a modal form?


with
user
a
give
form
the
whether
this?
 
 
 

Loading and Displaying a non-modal status form from a modally displayed form?

Post by John Lew » Fri, 12 Sep 2003 05:38:19

Bryan,

I figured out a way:

CenterForm frmTaskProgress
ShowWindow frmTaskProgress.hWnd, SW_SHOWNORMAL
AlwaysOnTop frmTaskProgress, True

ShowWindow is a windows api.

You need to center the form because when you use ShowWindow to show the
form, it does not use the window positioning properties you set for the form
in VB.

The AlwaysOnTop makes sure that it stays on top.

Declares:

Public Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal
nCmdShow As Long) As Long

Sub AlwaysOnTop(ByRef frmIn As Form, ByVal bOnTop As Boolean)

Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
Const SWP_NOMOVE = &H2
Const SWP_NOSIZE = &H1

If bOnTop Then
SetWindowPos frmIn.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or
SWP_NOMOVE
Else
SetWindowPos frmIn.hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or
SWP_NOMOVE
End If

End Sub

Sub CenterForm(x As Form)

Screen.MousePointer = 11
x.top = (Screen.Height * 0.85) / 2 - x.Height / 2
x.left = Screen.Width / 2 - x.Width / 2
Screen.MousePointer = 0

End Sub
 
 
 

Loading and Displaying a non-modal status form from a modally displayed form?

Post by alpin » Fri, 12 Sep 2003 06:28:17

If that is the effect you are looking for....

However, what happens if the user wants to use another application
while you are displaying your "always on top" form?

HTH,
Bryan
____________________________________________________________
New Vision Software "When the going gets weird,"
Bryan Stafford "the weird turn pro."
alpine_don' XXXX@XXXXX.COM Hunter S. Thompson -
Microsoft MVP-Visual Basic Fear and Loathing in LasVegas


On Wed, 10 Sep 2003 16:38:19 -0400, "John Lewe"
 
 
 

Loading and Displaying a non-modal status form from a modally displayed form?

Post by Michael Cu » Fri, 12 Sep 2003 06:35:53


The method I use is to show the modal form, have the modal form raise an event and run the long process in this event. I've tried
using the API method to show the form non-modally and found that it doesn't work very well, especially if you want to make it
generic.
 
 
 

Loading and Displaying a non-modal status form from a modally displayed form?

Post by Michael Cu » Fri, 12 Sep 2003 06:37:37

Also, it's possible for the user to still interact with the app.