wm_activate - why is hwndPrevious null?

Posted on 2000-02-17
Last Modified: 2013-12-03
i need to get the handle of the window that is taking focus from my window... wm_activate is what i should use but hwndPrevious is always null..
docs say that 'This handle can be NULL' which doesnt tell me a whole lot :)
what do i do to get the hwnd?
Question by:Vickio
  • 2
  • 2

Expert Comment

ID: 2533930
This is a quess. It's null, when window of an another process is acticated and not null when window of the same process is activated.

You could try GetActiveWindow in WM_ACTIVATE.


Author Comment

ID: 2534154
hmm, yeah your right, the window being activated must be of the same process....
calling GetActiveWindow doesnt work though cause WM_ACTIVATE is called before the window loses focus...

anyone else have an idea on how i can do this? if not i'll give JMu the points.


Accepted Solution

JMu earned 350 total points
ID: 2534215
Oops, GetActiveWindow() is thread specific function. If calling thread does not have active window, it returns NULL.

Looks like you have to call GetForegroundWindow() in WM_ACTIVATE.

Does this work?


Author Comment

ID: 2534239
cool, GetForegroundWindow works perfect :)

Expert Comment

ID: 2534256
GetFocus() maybe of assistance - the return value is the handle to the window with the keyboard focus. If the calling thread's message queue does not have an associated window with the keyboard focus, the return value is NULL.

Even if GetFocus returns NULL, another thread's queue may be associated with a window that has the keyboard focus.

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.

Let me know how you go


Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now