[RESOLVED] Drawing on an external window...

Just starting out? Need help? Post your questions and find answers here.
gildev
User
User
Posts: 10
Joined: Sat Aug 23, 2008 12:58 am
Location: Picardie (France)

[RESOLVED] Drawing on an external window...

Post 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:

Image

But i don't find. :cry:

PS: I'm sorry i'm french and i don't speak english very well. :oops:
Last edited by gildev on Sun Aug 24, 2008 2:35 pm, edited 1 time in total.
gildev
User
User
Posts: 10
Joined: Sat Aug 23, 2008 12:58 am
Location: Picardie (France)

Post by gildev »

Nobody know? :cry:
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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?
BERESHEIT
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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. :wink:
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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?
BERESHEIT
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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 :P
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

netmaestro, #WH_CALLWNDPROCRET seems to be working with limited testing.
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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.
BERESHEIT
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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. :P
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
gildev
User
User
Posts: 10
Joined: Sat Aug 23, 2008 12:58 am
Location: Picardie (France)

Post by gildev »

Hi all!

Thinks for your answers.
I only want to do a placemark through a viewfinder like this:
Image

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. :oops:
Last edited by gildev on Sun Aug 24, 2008 12:47 pm, edited 1 time in total.
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Post by djes »

If you're doing something to point an element, why don't you simply use the mouse cursor?
gildev
User
User
Posts: 10
Joined: Sat Aug 23, 2008 12:58 am
Location: Picardie (France)

Post 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.
gildev
User
User
Posts: 10
Joined: Sat Aug 23, 2008 12:58 am
Location: Picardie (France)

Post 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?
gildev
User
User
Posts: 10
Joined: Sat Aug 23, 2008 12:58 am
Location: Picardie (France)

Post by gildev »

Yes!!!! I tried SetPixel_ and it works very well! Thinks all.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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?
BERESHEIT
Post Reply