[RESOLVED] why doesnt form_losefocus work for me?
I have this form, that responds to the up and down arrows..... i want it not to be able to be used when it is out of focus. i put this code...
Code:
Private Sub Form_GotFocus()
keysallowed = True
frmMainForm.Tag = 1
End Sub
Private Sub Form_LostFocus()
keysallowed = False
frmMainForm.Tag = 0
End Sub
but for some reason, when i click on another window, it still reponds! I even put it to where if the keysallwoed = true AND frmmainform.tag = 1 then respond to the keys.... why is it doing this?
Re: why doesnt form_losefocus work for me?
Did you put a marker/break point on a line in LostFocus event? Are you sure the event is firing at all?
Re: why doesnt form_losefocus work for me?
Okay.... Turns out, it isn't fireing at all..... =( I click on a different window, and it becomes gray......
Re: why doesnt form_losefocus work for me?
I think I needed something like you do earlier. I'm not sure but it was either using sublcassing or an API (maybe GetActiveWindow)... Try searching the forum for "form lost focus" or "window lost focus", I know I found a thread with a sample project attached, had a form that changed color and/or caption when it got or lost focus. Worked great.
EDIT: I think the LostFocus event fires only when the form loses focus to another form withing your project/application. The code I mentioned above works globally. I'll try to dig it up.
EDIT2: Found this, looks suspiciously like the code I mentioned: http://www.vbforums.com/showpost.php...3&postcount=10
Re: why doesnt form_losefocus work for me?
But, do u know why it would be that it doesnt fire the LostFocus when i move to another window?
Re: why doesnt form_losefocus work for me?
Quote:
Originally Posted by
Gamemaster1494
But, do u know why it would be that it doesnt fire the LostFocus when i move to another window?
Yep. Read my Edit for the reason and Edit2 for the solution. :)
Re: why doesnt form_losefocus work for me?
I think i found a post as well. http://www.vbforums.com/showthread.p...WM_ACTIVATEAPP =) thanks for ur help.
Re: [RESOLVED] why doesnt form_losefocus work for me?
I prefer using the WM_NCACTIVATE message since its sent when the program starts up and will call my sub and set variables as needed. In the example baja_yu linked to it uses WM_ACTIVATEAPP, notice the caption doesn't change when the program is first started.
Re: [RESOLVED] why doesnt form_losefocus work for me?
the one i found used the GotForegroundWindow thing.. so it has worked like i want it to. =)
Re: [RESOLVED] why doesnt form_losefocus work for me?
The link you posted has the same code (by szlamany) that I posted, but you opted for the Timer, probably because it's less code. However the subclassing, even though it's more code, is a better and 'cleaner' solution than a timer.
Re: [RESOLVED] why doesnt form_losefocus work for me?
Hmm....... Okay. i see what u mean. =)