Hi,

I was trying to code a little application that will bring my desktop window to the foreground via a hotkey but I've encountered a problem. If I'm running a command prompt full screen, it remains in the foreground. When I hit my Start Menu button on the keyboard it switches me out of the command prompt and displays the start menu... how would I get my application to switch me out of the command prompt? I've tried GetForegroundWindow/SetForegroundWindow/ShowWindow combinations but nothing worked. Any help would be appreciated. :)

Thanks,
bl00dbath
Posted on 2002-11-10 22:53:36 by bl00dbath
What? I had some trouble with that 3 days ago. I almost smashed
my computer because of it :grin:. But hey you don't wanna know my
lifestory or something 'funny' like that :alright:.

After alot of testing with just about every api function I could get my
hands on. This is the only solution I found that should work 99.9%.
The code will give focus to the next window in the Z-order(cycling through
the whole z-order.)

Z-Order:
Toplevel, child, and pop-up windows recieve a position in the
Z-order according to their appearance on your screen.
Ex. When you set a window to be topmost, that window is the first
window in the Z-order.


    invoke keybd_event, 18, 0, 0, 0   ;\\ Press 'ALT' Key

invoke keybd_event, 27, 0, 0, 0 ;\\ Press 'ESC' Key
invoke keybd_event, 27, 0, 2, 0 ;\\ Release 'ESC' Key
invoke keybd_event, 18, 0, 2, 0 ;\\ Release 'ALT' Key
Posted on 2002-11-11 00:54:50 by natas
Haha thanks for the reply Natas, I'll give it a try :)

Regards,
bl00dbath
Posted on 2002-11-11 01:09:14 by bl00dbath
You can try using the windows system wide hotkey 'windows key + m' to minimize all open windows. I'm not sure if that's exactly what you're trying to do but it will minimize all windows and bring up your desktop. It also minimizes full-screen dos windows. Another side note, 'alt+tab' will maximize/restore dos windows.

edit: Just look in windows.inc for the equates for the windows key and the m key. When you setup the hotkey in your app, sendmessage a wm_keydown or wm_char or whatever with that equate combo. I don't have the win api help file open but that should give you a start.


cheers,
will
Posted on 2002-11-11 11:13:44 by Will
Thanks Will, that seems to work pretty well. :)

Regards,
bl00dbath
Posted on 2002-11-11 16:05:44 by bl00dbath
Window + D works too... You can try it too.
Posted on 2002-11-12 06:04:28 by roticv
ShellExecute() + Desktop.scf ?

It maybe won't work on all windows versions...
Posted on 2002-11-12 06:59:13 by JCP
Thanks for all of the replys guys. :)

I have a problem though. When in a command prompt, if I hit Windows Key + M or D, I'm switched back to desktop no problems. But when my app is activated (I'm using a keyboard hook) and I try my hotkey from the command prompt, it doesn't work. It does work in all of the other normal windows though. Would it work better if I just setup a hotkey with say RegisterHotkey instead of using the keyboard hook?

Thanks,
bl00dbath
Posted on 2002-11-13 07:44:53 by bl00dbath