|
-
Nov 25th, 2007, 03:41 PM
#1
Thread Starter
Junior Member
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?
-
Nov 25th, 2007, 04:40 PM
#2
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.
-
Nov 25th, 2007, 08:19 PM
#3
Re: Drawing on another application
 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?
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
-
Nov 25th, 2007, 08:40 PM
#4
Frenzied Member
Re: Drawing on another application
Ooooooh, I've needed this before. Maybe I can now finish that application.. Thanks Atheist!
Edit: Evil Post!!
-
Nov 27th, 2007, 06:23 PM
#5
Re: Drawing on another application
 Originally Posted by Atheist
Would that be me, by any chance?
Well, how did you know?
-
Dec 8th, 2007, 06:04 PM
#6
Thread Starter
Junior Member
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!
-
Dec 8th, 2007, 06:49 PM
#7
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.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Dec 8th, 2007, 11:57 PM
#8
Thread Starter
Junior Member
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.
-
Dec 9th, 2007, 02:20 AM
#9
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.
-
Dec 15th, 2007, 09:30 PM
#10
Frenzied Member
Re: Drawing on another application
 Originally Posted by Atheist
Would that be me, by any chance?
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.
-
Dec 15th, 2007, 09:33 PM
#11
Frenzied Member
Re: Drawing on another application
Put it on a timer... so that it repeatedly draws it...
-
Dec 15th, 2007, 09:43 PM
#12
Frenzied Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|