Hi all,
I was wondering...
How can you give the desktop or taskbar the keyboard focus?
Hi all,
I was wondering...
How can you give the desktop or taskbar the keyboard focus?
Last edited by Aidman; 01-05-2003 at 10:27 PM.
We haven't inherited Earth from our parents; instead we have borrowed her from our children - old Indian saying.
I know there is an SetFocus function but that only works for a window in your own app.
We haven't inherited Earth from our parents; instead we have borrowed her from our children - old Indian saying.
you can try...
That would be my first try.Code:SendMessage( GetDesktopWindow(),WM_SETFOCUS,(WPARAM)hwnd_of_your_window_thats_losing_focus,0);
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
the SendMessage didn't work, the focus didn't change.
The return value is zero and acording to MSDN that should
mean that the message was successfully completed...
Does any one know how to give the desktop the keyboard focus?
I know there is an SetFocus function but that only works on windows in you own app. But accordning to MSDN you could also
use the AttachThreadInput function and attach your calling thread to the desktop thread but I don't exactly understand how to do it and wonder if anyone could demonstrate it in code or explain another alternetive...
We haven't inherited Earth from our parents; instead we have borrowed her from our children - old Indian saying.
maybe setfocus was the wrong message. Try WM_ACTIVATE. You will need to check what to pack into wparam and lparam. Im not sure how to do this never having tried. You could alternatively try some of the window functions using the window handle you get from GetDesktopWindow() or if you are lucky someone else here may know how to do it. Ken Fitlike,AdrianXW and Fordy would be the people to ask.
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
I dont see what you are trying to do......if you give keyboard focus to either of these, there's very little you can do as a user.....Originally posted by Aidman
Hi all,
I was wondering...
How can you give the desktop or taskbar the keyboard focus?
Say whay you are really trying to achive and someone might give a better answer.....
Also, you may find that simulating windows messages like WM_SETFOCUS etc....might work better if you call SetForegroundWindow(GetDesktopWindow()) as the window thread wont have the thread priority to work with the keyboard when it doesnt sit at the top of the Z order....even better, minimise all active windows and then the desktop will be able to recieve input by default....
Still dont understand what you are trying to do though....Code:#include <windows.h> BOOL CALLBACK Minimise(HWND hWnd,LPARAM){ static WINDOWPLACEMENT wp; if(GetWindowLong(hWnd,GWL_STYLE) & WS_VISIBLE && GetWindowPlacement(hWnd,&wp) && wp.showCmd != SW_SHOWMINIMIZED) ShowWindow(hWnd,SW_SHOWMINIMIZED); return 1; } int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int){ EnumWindows(Minimise,0); return 0; }
I am making a program that hasn't a window but uses GetAsyncKeyState to get inputs. The reason for not using a window with normal VM_KEYUP/KEYDOWN is becouse the keyboard input must the in a global state. Now in a specific state in the program I don't want the other programs to get keyboard input becouse they might write it in there active textbox or do some of there shortcut key commands. And don't wanna use hotkeys becouse I need to refer to all keys that are pressed.
If you click on your desktop with your cursor then the desktop gets the keyboard focus even if it isn't the top window. I need to set the keyboard focus to a either the desktop where it would do less key commands or the taskbar. Please help me find I way with out minimizing all windows...
We haven't inherited Earth from our parents; instead we have borrowed her from our children - old Indian saying.
Right...I think I see what you are doing, but I dont think you are going about it in the most practical way...Originally posted by Aidman
I am making a program that hasn't a window but uses GetAsyncKeyState to get inputs. The reason for not using a window with normal VM_KEYUP/KEYDOWN is becouse the keyboard input must the in a global state. Now in a specific state in the program I don't want the other programs to get keyboard input becouse they might write it in there active textbox or do some of there shortcut key commands. And don't wanna use hotkeys becouse I need to refer to all keys that are pressed.
If you click on your desktop with your cursor then the desktop gets the keyboard focus even if it isn't the top window. I need to set the keyboard focus to a either the desktop where it would do less key commands or the taskbar. Please help me find I way with out minimizing all windows...
Better to create a dll to activate a system wide Keyboard hook.....this hook procedure will then get any keypress message before the window it belongs to.....you can then alter, store, divert or discard the message as you wish.......you can also open a method of IPC (Inter Process Communication) to relay these messages yo your app (Named pipe is good....I prefer a mailslot)....
Try look up keyloggers and the SetWindowsHook API
Hey thanks this is really great! thanks Fordy!
I think this might really help and if so then WOPPY!!!
We haven't inherited Earth from our parents; instead we have borrowed her from our children - old Indian saying.