Results 1 to 12 of 12

Thread: Drawing on another application

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2005
    Posts
    20

    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?

  2. #2
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    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.

  3. #3
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    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?

    Heres an example. This'll let you draw in the client area of the process' main window.
    VB.Net Code:
    1. Dim p() As Process = Process.GetProcessesByName("notepad")
    2.         If p.Length > 0 Then
    3.             Dim graph As Graphics = Graphics.FromHwnd(p(0).MainWindowHandle)
    4.             graph.FillRectangle(Brushes.Brown, New Rectangle(0, 0, 100, 100))
    5.             graph.DrawString("Example!", Me.Font, Brushes.White, 0, 40)
    6.             graph.Dispose()
    7.         End If
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  4. #4
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    Re: Drawing on another application

    Ooooooh, I've needed this before. Maybe I can now finish that application.. Thanks Atheist!




    Edit: Evil Post!!

  5. #5
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    Re: Drawing on another application

    Quote Originally Posted by Atheist
    Would that be me, by any chance?
    Well, how did you know?

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Jan 2005
    Posts
    20

    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!

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Jan 2005
    Posts
    20

    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.

  9. #9
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Sector 001
    Posts
    1,577

    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.
    VB 2005, Win Xp Pro sp2

  10. #10
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    Re: Drawing on another application

    Quote 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:
    1. Dim p() As Process = Process.GetProcessesByName("notepad")
    2.         If p.Length > 0 Then
    3.             Dim graph As Graphics = Graphics.FromHwnd(p(0).MainWindowHandle)
    4.             graph.FillRectangle(Brushes.Brown, New Rectangle(0, 0, 100, 100))
    5.             graph.DrawString("Example!", Me.Font, Brushes.White, 0, 40)
    6.             graph.Dispose()
    7.         End If
    Nevermind. You know that it disappears right after you switch to the window, right? I need it to stick, somehow.

  11. #11
    Frenzied Member Icyculyr's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    1,934

    Re: Drawing on another application

    Put it on a timer... so that it repeatedly draws it...

  12. #12
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    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
  •  



Click Here to Expand Forum to Full Width