Click here to Skip to main content
14,330,218 members
Rate this:
Please Sign up or sign in to vote.
c# visual studio

Is it possible to capture a window title through an e.location and how?
Richard MacCutchan 1-Mar-15 13:24pm
No, you need the Window's handle.
Rate this:
Please Sign up or sign in to vote.

Solution 2

In addition to Solution 1, which will hardly be enough:

You can do the following:
  1. Get HWND of the desktop window:
  2. Iterate through all desktop children:
  3. For each child window, get its bounding rectangle:
  4. For each child window iterated window, determine if the point is screen coordinates lies inside the rectangle.
  5. Now, remember that windows can overlap, so the iteration steps described in two previous items may give you more that one window. Choose one of them ( :-)). For this purpose, you may need to consider Z-order of those windows. Instead of iteration explained above, you can take to top window on the desktop and then create a ordered list of all children on Z-order. Please see:,
  6. Finally, do what Solution 1 suggested:
  7. PROFIT!

Yes, you need P/Invoke, but all the P/Invoke declarations are already created for you. Just Google on each function name. For example, for first function, it will be

Remember: if you do all that to uniquely identify some external window or a process, you cannot really rely on window's title. Anyone can give you some application with some stupid window title like "Notepad" or "Explorer". If you explain your ultimate goals, chances are, we can help you better.

Maciej Los 27-Mar-15 9:48am
What can i say, Maestro? You quote my answer twice, but i do not see any benefits of this... ;(
Thank you, Sergey, i'm fine. Last days i've been bit busy, but i like it! I hope to meet you on Skype this weekend...
Sergey Alexandrovich Kryukov 27-Mar-15 11:23am
Thank you, Maciej.
Yes, let's try to meet; probably I'll have to ask a couple of questions.
Rate this:
Please Sign up or sign in to vote.

Solution 1

As Richard MacCutchan mentioned, you have to get window's handle.

Have a look here:[^]. Link to MSDN documentation: GetWindowText function[^]
Sergey Alexandrovich Kryukov 26-Mar-15 15:41pm
Well, not bad, but sorry, you explained no more then some 14% of what's involved. The most missing item is the canonical #7 :-) — please see my answer.
Anyway, your solution is credited.
How are you doing?
Maciej Los 27-Mar-15 9:51am
Is it possible to measure/count how much worth is my answer? :laugh:
Only 14%? I think that only 14% is missing to 100.
Sergey Alexandrovich Kryukov 27-Mar-15 11:28am
I just counted the number of items. How cares what are they? :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100