[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.vb.general.discussion

How to show popup when modal window is displayed

sredmyer

12/20/2010 2:06:00 PM

I have a VB6 app that is used in my company by call floor
representatives. They use this app continuously throughout the day.
Embedded in this app is a third party dll which is tied into the phone
system and is used to display caller ID information and track call
flow. That caller ID information is provided by capturing the events
of the dll (just wrappers around TAPI) and presented to the user via a
popup window (simple non-sizable form). This form is laoded (though
not visible) when the application starts. Then whenever a call is
"offering" it is populated with information about the call and the
caller then made visible. The user can eaither close it (which
actually only hides it) him/herself or the form will auto close after
30 seconds.

The problem I have is that when that popup form is displayed can be
anytime...and anything might be going on in the application. If a
modal window is loaded when an attempt is made to load the popup, an
error occurs since the popup window (for obvious reasons) is not a
modal window. To avoid this error condition I just have "On Error
Resume Next" before the call to show the form. This works to prevent
the erorr from crashing the app but obviously the popup is not shown.

So the question I have is this...Is there any way given the situation
described to create a window that I can display (non-modally) even
when a modal window is up?

Thanks,
Steve
18 Answers

DaveO

12/20/2010 2:38:00 PM

0

The 2 easiest solutions are:
1) Don't keep the form loaded - load when needed, unload afterwards.
2) Show a new form with all the data from the hidden form copied onto it.

Normally the first option would be best, but if there is a lot of processing
going on on the form then the second may be preferable. To the best of my
knowledge, there's no easy (or at least easier than those 2 suggestions) to
show an existing hidden form over a modal form and to allow that form to
interact.

A third possiblity would be to have the popup as a seperate executable
controlled by the main program. This is more complicated and hinges upon a
reliable method of communicating between the 2 processes. A multitude of
possiblities present themselves for the communication method, a few might
be: doing it properly with Windows messages, using a database table and a
timer to poll it, winsock, using sendmessage to directly populate the form,
any other method that works.

DaveO.

"sredmyer" <sredmyer@sndirect.com> wrote in message
news:78ee5c0d-6c22-49b2-994d-6f575597ae9c@l8g2000yqh.googlegroups.com...
>I have a VB6 app that is used in my company by call floor
> representatives. They use this app continuously throughout the day.
> Embedded in this app is a third party dll which is tied into the phone
> system and is used to display caller ID information and track call
> flow. That caller ID information is provided by capturing the events
> of the dll (just wrappers around TAPI) and presented to the user via a
> popup window (simple non-sizable form). This form is laoded (though
> not visible) when the application starts. Then whenever a call is
> "offering" it is populated with information about the call and the
> caller then made visible. The user can eaither close it (which
> actually only hides it) him/herself or the form will auto close after
> 30 seconds.
>
> The problem I have is that when that popup form is displayed can be
> anytime...and anything might be going on in the application. If a
> modal window is loaded when an attempt is made to load the popup, an
> error occurs since the popup window (for obvious reasons) is not a
> modal window. To avoid this error condition I just have "On Error
> Resume Next" before the call to show the form. This works to prevent
> the erorr from crashing the app but obviously the popup is not shown.
>
> So the question I have is this...Is there any way given the situation
> described to create a window that I can display (non-modally) even
> when a modal window is up?
>
> Thanks,
> Steve


sredmyer

12/20/2010 3:53:00 PM

0

On Dec 20, 9:37 am, "DaveO" <d...@dial.pipex.com> wrote:
> The 2 easiest solutions are:
> 1) Don't keep the form loaded - load when needed, unload afterwards.
> 2) Show a new form with all the data from the hidden form copied onto it.
>
> Normally the first option would be best, but if there is a lot of processing
> going on on the form then the second may be preferable. To the best of my
> knowledge, there's no easy (or at least easier than those 2 suggestions) to
> show an existing hidden form over a modal form and to allow that form to
> interact.
>
> A third possiblity would be to have the popup as a seperate executable
> controlled by the main program. This is more complicated and hinges upon a
> reliable method of communicating between the 2 processes. A multitude of
> possiblities present themselves for the communication method, a few might
> be: doing it properly with Windows messages, using a database table and a
> timer to poll it, winsock, using sendmessage to directly populate the form,
> any other method that works.
>
> DaveO.
>
> "sredmyer" <sredm...@sndirect.com> wrote in message
>
> news:78ee5c0d-6c22-49b2-994d-6f575597ae9c@l8g2000yqh.googlegroups.com...
>
>
I am affraid I do not understand how either of your first two
suggestions would be any different than what I have now.

Wouldn't there still be an issue of not being able to load a non-modal
window while a modal window is displayed? The problem is that I must
be able to display the info whenever a call is offering (this can be
litteraly anytime). The display of this information must, itself not
stop processing (can not be modal). So the problem is how to display
(in process) a information popup window that can be made top most but
non-modal even when a modal window is displayed.

As for you third option, I had considered this but due to the way this
application is deployed (long story) adding another executable to the
mix would result in many support calls when new releases are deployed
because of this new executable being forgotten.

Thanks,
Steve

DaveO

12/20/2010 4:14:00 PM

0

>Wouldn't there still be an issue of not being able to load a non-modal
>window while a modal window is displayed?

As far as I know there is no way to show a non-modal window while a modal
one is active.

An alternative would be to make the currently modal form as a non-modal
form - Does this form need to be modal? Could you not get a similar effect
by hiding or locking its parent while the daughter form is shown?

If you can get rid of the modal nature then all the other problems will
disappear.



DaveO.


sredmyer

12/20/2010 4:29:00 PM

0

On Dec 20, 11:14 am, "DaveO" <d...@dial.pipex.com> wrote:
> >Wouldn't there still be an issue of not being able to load a non-modal
> >window while a modal window is displayed?
>
> As far as I know there is no way to show a non-modal window while a modal
> one is active.
>
> An alternative would be to make the currently modal form as a non-modal
> form - Does this form need to be modal? Could you not get a similar effect
> by hiding or locking its parent while the daughter form is shown?
>
> If you can get rid of the modal nature then all the other problems will
> disappear.
>
> DaveO.

The modality of the existing forms is intgral to the functioning of
the application. While it may be possible to refactor so that these
forms need not be modal...it would be a monumental under taking...this
app is huge.

I do realize that I can not display any standard VB form non-maodally
while a modal one is displayed. What I was hoping for was some crafty
API solution that might allow me to create some type of window that
did not adhere to VB's modality rules.

Thanks,
Steve

DaveO

12/20/2010 4:44:00 PM

0

>The modality of the existing forms is intgral to the functioning of
>the application. While it may be possible to refactor so that these
>forms need not be modal...it would be a monumental under taking...this
>app is huge.

Are you sure? Presumably at some point there is some code a bit like this



Do Something

frmWhatever.Show vbModal, me

Do more stuff



All that you need to do is split the routine into 2 routines, the first does
everything up to and including the Show, the second routine has everything
after the Show and is called when the new form is unloaded. You'll need to
either lock or disable every control on the parent form which is a lot
easier than it may at first sound, or make the parent invisible while the
daughter is shown.



DaveO.


Mayayana

12/20/2010 5:31:00 PM

0

| The modality of the existing forms is intgral
| to the functioning of the application.

I find that hard to believe. I don't think I've
ever seen a necessary modal form; only forms
that lock the order of access, like Windows
control Panel applets or Properties -> Details ->
Message Source with Outlook Express messages.
And that's just because Microsofties are too lazy
to deal with the complexity of making those
windows flexible. (There's no excuse for the fact
that I can't hold the source code of one email
open while doing other things in OE.)

If you're set on a modal form then why not
just use a zordered frame as a message window --
like webpages do?


mbyerley

12/20/2010 6:19:00 PM

0


"Mayayana" <mayayana@invalid.nospam> wrote in message
news:ieo3p6$7e0$1@news.eternal-september.org...
>| The modality of the existing forms is intgral
> | to the functioning of the application.
>
> I find that hard to believe. I don't think I've
> ever seen a necessary modal form; only forms
> that lock the order of access, like Windows
> control Panel applets or Properties -> Details ->
> Message Source with Outlook Express messages.
> And that's just because Microsofties are too lazy
> to deal with the complexity of making those
> windows flexible. (There's no excuse for the fact
> that I can't hold the source code of one email
> open while doing other things in OE.)

That annoyance is what led me to keep notepad on the quick launch so I
could copy/paste to notepad and close the modal box in OE.. : (

>
> If you're set on a modal form then why not
> just use a zordered frame as a message window --
> like webpages do?
>
>


(nobody)

12/20/2010 8:06:00 PM

0

This function tells you if the active form is modal, and if so, show your
form modally. I am not sure if it's perfect, it relies on the fact that the
parent or owner form is disabled when the form is modal.


Private Const GW_OWNER = 4
Private Declare Function GetWindow Lib "user32" (ByVal hWnd As Long, _
ByVal wCmd As Long) As Long
Private Declare Function GetParent Lib "user32" ( _
ByVal hWnd As Long) As Long
Private Declare Function IsWindowEnabled Lib "user32" ( _
ByVal hWnd As Long) As Long


Private Function IsActiveFormModal() As Boolean
Dim hWndActiveForm As Long
Dim h As Long

hWndActiveForm = Screen.ActiveForm.hWnd
If hWndActiveForm <> 0 Then
' Get the parent or owner
h = GetParent(hWndActiveForm)
If h = 0 Then
' No parent, get the owner
h = GetWindow(hWndActiveForm, GW_OWNER)
End If
If h <> 0 Then
If IsWindowEnabled(h) <> 0 Then
IsActiveFormModal = False
Else
IsActiveFormModal = True
End If
End If
End If
End Function


Dee Earley

12/21/2010 10:56:00 AM

0

On 20/12/2010 14:05, sredmyer wrote:
> So the question I have is this...Is there any way given the situation
> described to create a window that I can display (non-modally) even
> when a modal window is up?

Not natively in VB, but...
SetWindowPos Me.hWnd, -2, 0, 0, 0, 0, &H53 ' Pops up at back of
ZOrder. Does not steal focus

And (IIRC) works when a modal window is visible.

This is for a background process status window so almost exactly the
same situation.
I can't remember if they'll be able to interact with it though.


--
Dee Earley (dee.earley@icode.co.uk)
i-Catcher Development Team

iCode Systems

(Replies direct to my email address will be ignored.
Please reply to the group.)

Norm Cook

12/21/2010 1:56:00 PM

0


"sredmyer" <sredmyer@sndirect.com> wrote in message
news:78ee5c0d-6c22-49b2-994d-6f575597ae9c@l8g2000yqh.googlegroups.com...
>I have a VB6 app that is used in my company by call floor
> representatives. They use this app continuously throughout the day.
> Embedded in this app is a third party dll which is tied into the phone
> system and is used to display caller ID information and track call
> flow. That caller ID information is provided by capturing the events
> of the dll (just wrappers around TAPI) and presented to the user via a
> popup window (simple non-sizable form). This form is laoded (though
> not visible) when the application starts. Then whenever a call is
> "offering" it is populated with information about the call and the
> caller then made visible. The user can eaither close it (which
> actually only hides it) him/herself or the form will auto close after
> 30 seconds.
>
> The problem I have is that when that popup form is displayed can be
> anytime...and anything might be going on in the application. If a
> modal window is loaded when an attempt is made to load the popup, an
> error occurs since the popup window (for obvious reasons) is not a
> modal window. To avoid this error condition I just have "On Error
> Resume Next" before the call to show the form. This works to prevent
> the erorr from crashing the app but obviously the popup is not shown.
>
> So the question I have is this...Is there any way given the situation
> described to create a window that I can display (non-modally) even
> when a modal window is up?
>
> Thanks,
> Steve

Not my code & can't remember its source but I think this does what you
want. New Std Exe with 3 forms, Form1 is the startup object.
Form1 has 2 buttons, Form2 has 2 buttons.

Form1 Code-----------------------------------
Option Explicit
Private WithEvents PSModal As Form2
Private Sub Form_Load()
Command1.Caption = "Show QuasiModal Form"
'shows can't be clicked while Form2 loaded
Command2.Caption = "Click Me"
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim Frm As Form 'in case the popup not closed
For Each Frm In Forms
If Frm.Name <> "Form1" Then
Unload Frm
End If
Next
End Sub

Private Sub Command1_Click()
'Old Code:
'Form2.Show vbModal, Me
'MsgBox "Do stuff here when modal form closes"
'Exit Sub
Set PSModal = New Form2
Call PSModal.PseudoModal(Me)
'See PSModal_PseudoModalClosed for next step
End Sub

Private Sub Command2_Click()
'Try clicking this when the "Pseudo Modal" form's on screen
MsgBox "Click Here"
End Sub

Private Sub PSModal_PseudoModalClosed()
MsgBox "Do stuff here when pseudo-modal form closes"
Set PSModal = Nothing
Me.SetFocus
End Sub
'End of Form1 code-----------------

Form2 Code------------------------------------
Option Explicit
Private mbIsModal As Boolean
Private mobjOwner As Form
Public Event PseudoModalClosed()
Public Sub PseudoModal(Owner As Form)
mbIsModal = True
Set mobjOwner = Owner
Me.Show vbModeless, mobjOwner
Command1.Caption = "Exit"
Command2.Caption = "Show Modeless Popup"
End Sub

Private Sub Command1_Click()
mbIsModal = False
Unload Me
End Sub

Private Sub Command2_Click()
Form3.Show
'it shows at the back of the zorder
' may need some OnTop code
End Sub

Private Sub Form_Deactivate()
If mbIsModal Then
Me.Show vbModeless, mobjOwner
End If
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
RaiseEvent PseudoModalClosed
End Sub
End of Form2 Code----------------------------------