Drawing on another application
Hi.
I need to integrate my program into a different program created by someone else. Basically I need to draw a tiny image in the top left corner on the other application that shows some statistics from my application which will run in the background.
The target application is created in unmanaged c++. I've seen a video of this, so I know it's possible. I've tried a couple of things, one is to create a panel and simply set it's parents to the target application's window handle, however this has yielded undesired effects. I need to actually draw on the other application so that mouse events still reach the target application.
A managed solution is desirable, but I'm no stranger to platform invoke.
Any ideas?
Re: Drawing on another application
I've seen the trick used as well. From what I remember, it involved grabbing the hwnd ID of the target application and using that as a base for drawing instead of the current form. That's about all I can remember, but if I remember this thread when a friend of mine gets online, I'll point him here. He's done it before.
Re: Drawing on another application
Quote:
Originally Posted by timeshifter
.. but if I remember this thread when a friend of mine gets online, I'll point him here. He's done it before.
Would that be me, by any chance?:D
Heres an example. This'll let you draw in the client area of the process' main window.
VB.Net Code:
Dim p() As Process = Process.GetProcessesByName("notepad")
If p.Length > 0 Then
Dim graph As Graphics = Graphics.FromHwnd(p(0).MainWindowHandle)
graph.FillRectangle(Brushes.Brown, New Rectangle(0, 0, 100, 100))
graph.DrawString("Example!", Me.Font, Brushes.White, 0, 40)
graph.Dispose()
End If
Re: Drawing on another application
Ooooooh, I've needed this before. Maybe I can now finish that application.. Thanks Atheist!
Edit: Evil Post!! :eek2:
Re: Drawing on another application
Quote:
Originally Posted by Atheist
Would that be me, by any chance?:D
Well, how did you know? ;)
Re: Drawing on another application
How can I hook into the other applications paint event? Say I want to draw subtitles on a video, I'd need the paint event to draw my images after the other application has drawn theirs right? I don't want to draw subtitles on a video it's just an easy example.
Thanks for any help!
Re: Drawing on another application
Video may be different as it may not have a window handle. Just like how you cant take a screen shot of a dvd movie playing.
Re: Drawing on another application
It's not a video it was just easier to explain it that way =) I actually want to draw on top of a map that's constantly scrolling.
Re: Drawing on another application
I've played with BS Player before to get exactly that paint event but it needs more than simple thinkering.
Saitn, do you know the Spy++ tool? Maybe in your case there is a 'refresh giving away' message you can listen for and repaint your stuff after it.
Or you redraw your image at least 24x /second and that's it.
Re: Drawing on another application
Quote:
Originally Posted by Atheist
Would that be me, by any chance?:D
Heres an example. This'll let you draw in the client area of the process' main window.
VB.Net Code:
Dim p() As Process = Process.GetProcessesByName("notepad")
If p.Length > 0 Then
Dim graph As Graphics = Graphics.FromHwnd(p(0).MainWindowHandle)
graph.FillRectangle(Brushes.Brown, New Rectangle(0, 0, 100, 100))
graph.DrawString("Example!", Me.Font, Brushes.White, 0, 40)
graph.Dispose()
End If
Nevermind. You know that it disappears right after you switch to the window, right? I need it to stick, somehow.
Re: Drawing on another application
Put it on a timer... so that it repeatedly draws it...
Re: Drawing on another application
That's not going to work. I need it to actually be drawn on and not just be there visually shown to the user. For example, using that block of code to draw onto the canvas in Microsoft Paint and then being able to save it. Is such a thing possible? If not, I could possibly simulate mouse strokes to accomplish such, perhaps. But it would be less than ideal as there would be some color loss or it would just be plain black and white.