Home All Groups Group Topic Archive Search About
Author
20 Oct 2005 12:43 AM
Arpan
A VB6 Form has the following code:

Private Sub Form_LostFocus()
    MsgBox ("bye")
End Sub

But when I navigate to another window & in the process the Form loses
focus, the MsgBox doesn't show up! Why?

Please note that the MsgBox line is the only code in the above
sub-routine.

Thanks,

Arpan

Author
20 Oct 2005 12:58 AM
Karl E. Peterson
Arpan wrote:
> A VB6 Form has the following code:
>
> Private Sub Form_LostFocus()
>     MsgBox ("bye")
> End Sub
>
> But when I navigate to another window & in the process the Form loses
> focus, the MsgBox doesn't show up! Why?
>
> Please note that the MsgBox line is the only code in the above
> sub-routine.

Forms and focus really don't go together, per se.  I think the event you're looking
for is Deactivate.  Also, when troubleshooting focus issues of any sort, MsgBox
brings the Heisenburg Uncertainty principle into play -- don't do it.  Use
Debug.Print instead.  HTH!
--
Working Without a .NET?
http://classicvb.org/petition
Author
20 Oct 2005 1:04 AM
Bob Butler
"Arpan" <arpan***@hotmail.com> wrote in message
news:1129769015.460201.169320@g44g2000cwa.googlegroups.com
> A VB6 Form has the following code:
>
> Private Sub Form_LostFocus()
>     MsgBox ("bye")
> End Sub
>
> But when I navigate to another window & in the process the Form loses
> focus, the MsgBox doesn't show up! Why?

If the other window is in the same application then try the form_deactivate
event; the gotfocus and lostfocuse events would only be useful if no control
on the form could have focus and that's not usually the case.

if the other window is in another application then you'll need to subclass
the form in order to trap the application losing focus; either that or hack
it by checking the form's hwnd against GetForeGroundWindow every few
seconds.

--
Reply to the group so all can participate
VB.Net: "Fool me once..."
Author
20 Oct 2005 5:14 AM
Arpan
Thanks, Karl & Bob, for your suggestions!

I did try the Deactivate event but it doesn't work out! Actually the
VB6 application has 2 Forms. Deactivate gets fired only when I switch
from one Form to the other Form but I want the MsgBox when the user
navigates to some other already open application.

By "other application", I mean an altogether different application
(which could be some other VB6 application as well). While working, PC
users usually have more than 1 window/application open. For e.g. say, 1
IE browser, MS-Word etc. I want the MsgBox to pop up when the user
shifts to the browser window or the Word window.

Any other suggestions?

Thanks once again,

Regards,

Arpan
Author
20 Oct 2005 7:18 AM
Tom Esh
On 19 Oct 2005 22:14:03 -0700, "Arpan" <arpan***@hotmail.com> wrote:

>I did try the Deactivate event but it doesn't work out! Actually the
>VB6 application has 2 Forms. Deactivate gets fired only when I switch
>from one Form to the other Form but I want the MsgBox when the user
>navigates to some other already open application.

Unfortunately VB provides no event for that. As Bob noted, detecting
app activation will require some Api code.

For an example that uses subclassing to detect the WM_ACTIVATEAPP
message:
    http://vbnet.mvps.org/code/subclass/activation.htm


-Tom
MVP - Visual Basic
(please post replies to the newsgroup)
Author
20 Oct 2005 8:53 AM
J French
Show quote Hide quote
On 19 Oct 2005 22:14:03 -0700, "Arpan" <arpan***@hotmail.com> wrote:

>Thanks, Karl & Bob, for your suggestions!
>
>I did try the Deactivate event but it doesn't work out! Actually the
>VB6 application has 2 Forms. Deactivate gets fired only when I switch
>from one Form to the other Form but I want the MsgBox when the user
>navigates to some other already open application.
>
>By "other application", I mean an altogether different application
>(which could be some other VB6 application as well). While working, PC
>users usually have more than 1 window/application open. For e.g. say, 1
>IE browser, MS-Word etc. I want the MsgBox to pop up when the user
>shifts to the browser window or the Word window.

>Any other suggestions?

You need to subclass and watch for the WM_ACTIVATEAPP message

A cheats trick is to set up a Timer and use GetForegroundWindow then
keep checking the parent to see whether it belongs to your App
Author
20 Oct 2005 11:45 PM
RonW
On 19 Oct 2005 22:14:03 -0700, "Arpan" <arpan***@hotmail.com> wrote:

>...I want the MsgBox when the user
>navigates to some other already open application.
>
>By "other application", I mean an altogether different application
>(which could be some other VB6 application as well). While working, PC
>users usually have more than 1 window/application open. For e.g. say, 1
>IE browser, MS-Word etc. I want the MsgBox to pop up when the user
>shifts to the browser window or the Word window.
>
>Any other suggestions?

Just one: Don't do it.

Unless it's just a learning exercise. It's hard to imagine anything more
irritating than an application that pops up a message box every time I switch to
a different application. That would happen about twice before the app was
summarily deleted from my PC!

RW
Author
20 Oct 2005 11:52 AM
Phill. W
"Arpan" <arpan***@hotmail.com> wrote in message
news:1129769015.460201.169320@g44g2000cwa.googlegroups.com...

> But when I navigate to another window & in the process the Form
> loses focus, the MsgBox doesn't show up! Why?

A Form's LostFocus and Deactivate Events are only raised when
you move to another Form within the *same* application.

To detect Application switching, you have to trap the Windows
message, WM_ActivateApp.  Be warned; this kind of "subclassing"
can have some /very/ nasty effects when debugging your code!
(The IDE inexplicably disappearing being the commonest of them).


HTH,
    Phill  W.