Page 1 of 2
[RESOLVED] Drawing on an external window...
Posted: Sat Aug 23, 2008 1:05 am
by gildev
Hello!
I have a big problem. I wish to draw a dot, a line or a retangle on an external window (CALC.EXE for example) like this screenshot on B:
But i don't find.
PS: I'm sorry i'm french and i don't speak english very well.

Posted: Sun Aug 24, 2008 1:08 am
by gildev
Nobody know?

Posted: Sun Aug 24, 2008 1:31 am
by netmaestro
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?
Posted: Sun Aug 24, 2008 1:46 am
by Sparkie
Welcome gildev
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.

Posted: Sun Aug 24, 2008 2:07 am
by netmaestro
@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?
Posted: Sun Aug 24, 2008 2:18 am
by Sparkie
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

Posted: Sun Aug 24, 2008 3:40 am
by Sparkie
netmaestro, #WH_CALLWNDPROCRET seems to be working with limited testing.
Posted: Sun Aug 24, 2008 3:42 am
by netmaestro
Here as well. Looks like the way to go. I'll be posting mine in 1/2 hr or so when my show is over if you want to peruse my miserable efforts.
Posted: Sun Aug 24, 2008 3:46 am
by Sparkie
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.

Posted: Sun Aug 24, 2008 11:54 am
by gildev
Hi all!
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.

Posted: Sun Aug 24, 2008 11:57 am
by djes
If you're doing something to point an element, why don't you simply use the mouse cursor?
Posted: Sun Aug 24, 2008 12:21 pm
by gildev
I don't want to use the mouse because i have listed the points on a table and i want to pick the colors of the points automatically.
Posted: Sun Aug 24, 2008 12:25 pm
by gildev
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
I think
netmaestro is right. I can do a loop, but how to paint?
Posted: Sun Aug 24, 2008 2:34 pm
by gildev
Yes!!!! I tried SetPixel_ and it works very well! Thinks all.
Posted: Sun Aug 24, 2008 2:35 pm
by netmaestro
I don't want to use the mouse because i have listed the points on a table and i want to pick the colors of the points automatically.
How are you stepping through the table? Press a button to go to the next point or what?