Sign in to follow this  
Fromethius

[C# 2.0] Drawing on another application

Recommended Posts

My question is similar to this thread: http://vbforums.com/showthread.php?t=498183 Actually, my question for this thread was asked as the last post of that thread, but no one really answered it and it's best to not hijack a thread, I guess. As of right now, I wrote an application that will automatically redraw the image given pixel by pixel, but is way too slow and takes large images many, many images which is unacceptable. You can see the code I have written here: http://rafb.net/p/Kti1P079.html Anyways, I was hoping to think of a more "hacking" solution into doing this. Could I simply just not draw onto the canvas? Well, of course I can, but it is not actually drawn on. It is just visually there and right when I click away or move the window, it disappears. My question for this thread: Is there a way to possibly "hook" into the WM_PAINT message handler and actually have the program draw the image as if it was drawn onto the screen using the mouse. Would such a thing be possible? I got stimulating mouse clicks to redraw the image working properly but it is just too slow. I need a way of just pasting the image onto the canvas and having the program think it was actually drawn on there using a mouse or something of the sort and have it stick. Any ideas? Thanks :)

Share this post


Link to post
Share on other sites
As you've discovered, the technique of drawing directly onto the screen or another application is very fragile. There's no general way to let other applications know that you've drawn there, so they'll happily and arbitrarily draw on top of whatever you've drawn. Furthermore, drawing to the screen in Vista is very slow, and the DWM itself will draw over your stuff.

Layered windows will give you the effect of drawing on top of another window without the hackery of hooking WM_PAINT or Direct3D. Basically you render the content you want to the layered window that you create yourself, and position that window at the appropriate place. Because the window is owned by you, you have full control over what is drawn and don't have to worry about it disappearing. Windows will also correctly draw your window with other windows (and on top if necessary).

This technique is used by UISpy to draw rectangles on the screen. I've also used it in my own apps.

Share this post


Link to post
Share on other sites
Quote:
Original post by Fromethius
But will that image being drawn be saved along with the rest of the image if the user pressed save?
Sorry, I overlooked the snippet about drawing into another app and having that app save the drawing. The only possible way to do that is by simulating user input. What's your overall goal? It almost sounds like you can perform the image editing within your app and not reach into other apps.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this