hi all, i'm trying to improve the hhlookup example in masm32, i just wanted to be able to bring the edit box to the front using a Hotkey so that i can make another search, something really simple.....

i can't figure out how to get keyboard focus, when i respond to WM_HOTKEY i call SetFocus which makes mi window active, however i don't get keyboard focus... it's kind of weird cause I see the cursor blinking in my editbox but when i type something it goes to the previous window.... I've tried BringWindowToTop, SetActiveWindow, SetForegroundWindow, sending WM_KILLFOCUS, etc.

i don?t understand why it's not working, can anybody help please?
Posted on 2002-02-22 10:25:56 by sombra
I updated hhlookup (C version, asm version was just for fun).
I use RegisterHotKey(hwnd, IDHOTKEY, MOD_CONTROL | MOD_ALT, 'S');
to register the hotkey. In my WM_HOTKEY handler, I simply do a
SetForegroundWindow(hwnd); - this works because a hotkey is
(logically enough) seen as keyboard input, and thus windows lets
the application go foreground.

SetFocus only sets the focus *within* your application, it cannot
bring your application ontop.
Posted on 2002-02-22 10:53:13 by f0dder
thx fodder, it works now for hotkeys, but i'm a little confused, i replaced your invoke hhsearch with

invoke ShellExecute, , addr action, addr prg, NULL, NULL, SW_NORMAL

action = "open"
prg = "explorer"

works ok, it loads explorer but i want my window to be active again, i invoke SetForegroundWindow rigth after ShellExecute but it doesn't seem to work.... i've tried using SW_SHOWNOACTIVATE
but i doesn't work either, any ideas?
Posted on 2002-02-22 11:27:22 by sombra
SetForegroundWindow will only work if you have received some
form of input... that's all I have to say right now.
Posted on 2002-02-22 11:29:00 by f0dder
invoke ShowWindow,hwin,SW_SHOWNORMAL
Posted on 2002-02-22 12:49:45 by smurf
I tried with ShowWindow but it doesn?t work.... al least after ShellExecute....

thx anyway smurf
Posted on 2002-02-22 13:48:56 by sombra
why do you use SW_NORMAL when you invoke ShellExecute? shouldnt this be something like SW_SHOWNOACTIVATE?
Posted on 2002-02-22 14:35:11 by smurf
as i said in one of my previous posts i've already tried with SW_SHOWNOACTIVATE, makes no difference.
Posted on 2002-02-22 14:54:19 by sombra
it fails even if I send a WM_HOTKEY message using SendMessage..... how come? i mean, it works when I press the hotkey....
Posted on 2002-02-22 15:20:53 by sombra

Just a couple of suggestions that may help, try using CreateProcess() to start explorer as you have more control over what is going on when you call it.

If nothing else works which can be the case at times when you call operating system components, try setting you calling app with SetWindowPos() to make it a topmost window, then remove the setting after it has the focus. It may be worth a try if nothing else works.


Posted on 2002-02-22 20:12:49 by hutch--

it fails even if I send a WM_HOTKEY message using
SendMessage..... how come? i mean, it works when I press the

Because sending WM_HOTKEY doesn't qualify as getting user input :).
Have you tried using SW_SHOWNOACTIVATE with ShellExecute
and SetForegroundWindow() (in response to WM_HOTKEY) at the
same time?

Might want to give hutches approach a try as well.
Posted on 2002-02-23 01:16:54 by f0dder
I'm not sure if this is correct, but as for "hotkeys" without handling the WM_HOTKEY message, I use the GetAsyncKeyState function to handle the keyboard events. Then again, I might be wrong ;)
Posted on 2002-02-23 01:29:35 by stryker
GetAsyncKeyState would have to be called in a polling loop, whereas
WM_HOTKEY follows the standard event-driven nature of windows.
Also, I don't think GetAsyncKeyState would qualify as receiving user
input, and thus a call like SetForegroundWindow would fail (not tested,
but I think it makes sense?)

Also, if you're dealing with application (ie, nonglobal) hotkeys,
GetAsyncKeyState is ugly... I hate when a keypress in another app
does stuff in another app ;).
Posted on 2002-02-23 01:34:34 by f0dder
I have a proggy here that does this GetAsyncKeyState. Since I will be very busy this weekend, I may not finish the game. This game is the one you'll find at the Games Programming Forum. If you press the up key button a message box will popup. Also, this one eliminates the problem what fodder said about

I hate when a keypress in another app
does stuff in another app

You can tweak this code in any way you want, I'll post the final result at the Games Programming Forum.

Sliver, if you're reading this post, this proggy is still incomplete.


Right Click -> Popup menu
Up Key -> popups a message box

Happy Coding!!!

remove gdActiveApp to get scoped or keyboard handle even if ur program is not in focus or even if it's minimized.
Posted on 2002-02-23 02:01:50 by stryker
well, it looks like there is no way to regain keyboard focus other than using the keyboard or mouse....

i tried all your suggestions, i tried setting up a Timer, i tried sendind the created window to the bottom, etc. No success.

anyway, it's not that bad, i intend to use the proggie to launch applications and some other things, people familiar with litestep will remember bang command modules, so besides when i start my computer i won't need to launch more than one application at the same time too often.... i can live with pressing hotkeys to bring my app to the front...

thank you all for your time :alright:
Posted on 2002-02-23 09:24:01 by sombra
If you want the edit box to receive focus, then you need to SetFocus on the edit box. You may also need to activate the window that contains the edit box.
Posted on 2002-02-23 19:18:43 by tenkey
Originally posted by umberg6007

Sliver, if you're reading this post, this proggy is still incomplete.

Can't wait to see the program when it's complete...

Posted on 2002-02-24 10:17:04 by Sliver