Archived

This topic is now archived and is closed to further replies.

monkeyman

How can I set the window focus remotely?

Recommended Posts

monkeyman    253
Hey- I''m writing an application that searches for an open window by title bar, gets a handle to it, and sets that window to be active.. Unfortunately, the SetActiveWindow and SetFocus methods only work if the calling thread actually created the window, which in this case I didn''t, I just got a handle to it..the docs state that this is to prevent applications from screwing with each(which basically means I can steal the focus from some other app any time I feel like it, but I can''t set the focus to anything else that I didn''t create).. I''ve tried sending WM_SETFOCUS messages, etc., but the window doesn''t respond(I''m doing this with Notepad)..I can send other messages that it responds to, such as SW_MAXIMIZED, etc., so I know that I''ve got the correct handle, and the messaging is working, but I just can''t seem to get this window in the foreground.. I essentially want my app to disappear into the background, and set all focus to the Notepad window so the user can edit a text file(in the event that it''s not already open I can spawn Notepad, in which case the focus is set correctly)..this is only a problem when Notepad is already open, which is(of course) going to be the majority of the time(I assume).. Anyone? "Like all good things, it starts with a monkey.."

Share this post


Link to post
Share on other sites
monkeyman    253
I just did, and it does the same thing..

I checked the return on it, it was TRUE, so I''m assuming that there is no error(although this might indicate failure, I couldn''t verify either way, see attached rant below)..

I''m still able to maximize it, etc., and the BringWindowToTop didn''t fail, so my HWND is good and things are "working", but apparently MS and I have different definitions about what "bringing a window to the top" means..

//seperate but related msdn rant//
my msdn states that there are 2 versions of this function, one with a void(a member of the CWnd class) and one with a bool return(a member of the CWindow class), and no listing for the regular C win32 function that actually gets called(they do suggest "See BringWindowToTop in the Win32 SDK.", but "The topic does not exist", and is not supposed to as far as I can tell, after reinstalling of the latest cd''s).
//end rant//

"Like all good things, it starts with a monkey.."

Share this post


Link to post
Share on other sites