|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Form Lost Focus!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 Arpan wrote:
> A VB6 Form has the following code: Forms and focus really don't go together, per se. I think the event you're looking> > 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. 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! "Arpan" <arpan***@hotmail.com> wrote in message If the other window is in the same application then try the form_deactivatenews: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? 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..." 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 On 19 Oct 2005 22:14:03 -0700, "Arpan" <arpan***@hotmail.com> wrote: Unfortunately VB provides no event for that. As Bob noted, detecting>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. 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)
Show quote
Hide quote
On 19 Oct 2005 22:14:03 -0700, "Arpan" <arpan***@hotmail.com> wrote: You need to subclass and watch for the WM_ACTIVATEAPP message>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? 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 On 19 Oct 2005 22:14:03 -0700, "Arpan" <arpan***@hotmail.com> wrote: Just one: Don't do it.>...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? 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 "Arpan" <arpan***@hotmail.com> wrote in message A Form's LostFocus and Deactivate Events are only raised whennews: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? 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.
CommandButton!
Using shell command to map drive can't get redirect result to file Modal form stops code in another form SCC API implementation INSERT INTO how to split numeric part from letters in string Shrink Wrap Iterative GetObject get list of file names in a directory Is any device connected to COM1 port |
|||||||||||||||||||||||