It's not difficult to get the device context of an unowned window and draw to it, but the problem lies in persistence. You can't read the message queue of a window not owned by your process and so you won't know when a repaint is necessary. As soon as a window is moved over it or it is moved partly offscreen and back again your drawing will disappear, replaced by painting done in its WM_REPAINT event. So - you would have to solve this somehow. One way would be to put the drawing in a loop, possibly in a thread, so that it repeats the drawing every 15 ms or so. If you timed it to match the screen refresh rate it might not flicker. Another way would be to draw to a regioned or layered window that is invisible except for the drawn part and keep that window centered over the target window by means of a callback. Either way, it's some fiddling and before I dive into it I'd like to know the purpose. What is your reason for wanting this?
There are a few of ways I know of, neither of which are to be considered newbie friendly.
#1 involves using a hook to monitor messages form the external app. You'll need this in order to do your own redraws as needed.
#2 involves using StickyWindow with #PB_Window_Borderless and then keeping track of the position of the external app so you can move your window as needed.
#3 involves using #2 coupled with window regions.
#2 will be the easiest when lines or rectangles are concerned.
***Edit Well I see netmaestro chimed in as I was pecking away at this message. I'll let him do the dirty work from this point on.
@Sparkie, I didn't believe a hook would do because of this:
msdn wrote:Windows NT 4.0 and later: The system calls this function before calling the window procedure to process a message sent to the thread.
Because the repaint would happen after we received notification, any drawing we did would be instantly wiped out. But, I just realized that a delay might work, say 15 ms or so, the assumption being that the repaint would have happened by then. If this works, it would be a cleaner choice than the other alternatives imho. What do you think?
I was just thinking out loud when I mentioned the hook. I assume you are referring to the WH_CALLWNDPROC/CallWndProc hook. Surely one of the other WH_* hooks will do the trick. The clock is ticking my friend
Can't be any uglier than mine at this point. Switching back and forth between the watching the Olympics as well as the Indians/Rangers game with one eye and coding with the other.
Thinks for your answers.
I only want to do a placemark through a viewfinder like this:
I'm using GetPixel_ to get the color pixel of my point on the window, but i want to be sure that is the good point. It's just to verify the location of my pixel.
PS: I hope you will understand because my english is quiet bad.
Last edited by gildev on Sun Aug 24, 2008 12:47 pm, edited 1 time in total.