Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Home » Tip Bank » C++
Language: C++
Expertise: Beginner
May 2, 1999

Getting the active window

Question:
I am using VC++ 5.0 to develop applications based on Windows 95. I want to get the HWND of the active window, which is receiving the keyboard or mouse input and is a child window of the foreground window. I used ::getactivewindow(), but it can get only the window associated with my thread. What can I do?

Answer:
It used to be that you'd use GetFocus() to get the handle to the window that is taking user input. But this function has also been changed under Win32 to work only for windows attached to the same thread.

Here's how to globally find the window that has the input focus, according to the Microsoft Platform SDK documentation:

"Use the GetForegroundWindow function to retrieve the handle to the window with which the user is currently working. You can associate your thread's message queue with the windows owned by another thread by using the AttachThreadInput function."

DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date