Is My App Currently Active?

T

Thomas Weise

In order to find out, if my app is currently active, I'm using API function
GetForegroundWindow().
However, as soon as my app opens a dialog (specific window or even just a
message box), the handle of the dialog form is returned by
GetForegroundWindow(). In case of a message box, I don't even know the
handle and have no idea of how to retrieve it.
I have tried API function EnumChildWindows(), but that returns only the
rectangles the main form is composed of; apparently it does not return an
open message box.

Is there a feasible way of determining of my app is the active app?
Thanks in advance for you help!
Thomas
 
M

Mattias Sjögren

Is there a feasible way of determining of my app is the active app?

Well since you're already calling Win32 APIs, how about checking

uint fgProcessId;
GetWindowThreadProcessId(GetForegroundWindow(), out fgProcessId);
if (fgProcessId == GetCurrentProcessId()) ...


Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top