After happily using open source software for many years I've figured it's time to give back. And since documentation is usually a weak point for many projects, plus my C# skills are not exactly in high demand in my corner of FLOSS land, I've figured I'll start with tutorials, etc.
After the second tutorial for a burning tool, I already got annoyed with the routine of
- take screenshot
- highlight any important part
- annotate it
- add to website
- repeat
and figured I could automate that.
I guess what I'm looking for is a program that would take a screenshot of the currently open window, paint e.g. a yellow bar around the focused control (a button maybe) then pop up a little textbox for me to enter a description for the picture and finally add it all to a website/database/list/etc.
Now for my actual question: Unless anybody knows a tool that already does that, I need some starters on how to access size and position of controls on 'foreign' windows so that I can calculate where to paint those highlighting bars around important controls. I remember those password-unmasking tools for Windows that could reveal the content of any ******
-protected textbox, but I can't find any open examples on that.. WinAPI stuff I guess, WindowFromPoint + GetDlgItem or something like that. No idea if it's any easier in Linux, either one will be fine though. No preference on programming language either.
To my knowledge, what you want to do requires some P/Invoke, since .NET does not feature any API for accessing the windows of other applications.
You could probably start by using GetForegroundWindow to get the current Window (you would need to fire that code using a global hotkey or a timer, because if you switch windows to take the screenshot, you will get your own window returned from GetForegroundWindow).
Edit
I got inspired by your question to do a little Sunday afternoon coding. I found out, that GetForegroundWindow will get you the foreground Window, but not a Control level. But there is another useful function, GetGUIThreadInfo, that will get you the currently focused control and some other info. We can use GetWindowInfo to get the information about the Window (which might be a control contained in a top-level window).
Putting these things together, we can make a Window class that abstracts away all the gritty P/Invoke calls:
Then we can make a sample program using it:
This will make a screenshot of the current foreground window with a red box highlighting the currently focused control. Please be aware that this is sample code and features minimal error-checking :-) When you run it, Alt-Tab to the window of interest and stay there until the program finishes.
There are some limitations though. The most important one i discovered is that this approach won't work in a WPF application - simply because the individual controls is not Windows, as they are in other Windows programs.