|
-
Jun 8th, 2010, 06:28 PM
#1
Thread Starter
Fanatic Member
[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?
-
Jun 8th, 2010, 07:12 PM
#2
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?
-
Jun 8th, 2010, 07:15 PM
#3
Thread Starter
Fanatic Member
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......
-
Jun 8th, 2010, 07:27 PM
#4
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
Last edited by baja_yu; Jun 8th, 2010 at 07:33 PM.
-
Jun 8th, 2010, 07:31 PM
#5
Thread Starter
Fanatic Member
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?
-
Jun 8th, 2010, 07:35 PM
#6
Re: why doesnt form_losefocus work for me?
 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.
-
Jun 8th, 2010, 07:47 PM
#7
Thread Starter
Fanatic Member
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.
-
Jun 8th, 2010, 07:53 PM
#8
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.
-
Jun 8th, 2010, 08:05 PM
#9
Thread Starter
Fanatic Member
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. =)
-
Jun 8th, 2010, 09:09 PM
#10
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.
Last edited by baja_yu; Jun 8th, 2010 at 09:32 PM.
Reason: typo
-
Jun 8th, 2010, 09:22 PM
#11
Thread Starter
Fanatic Member
Re: [RESOLVED] why doesnt form_losefocus work for me?
Hmm....... Okay. i see what u mean. =)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|