Results 1 to 14 of 14

Thread: [2005] Drawing on a process(and erase)?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,547

    [2005] Drawing on a process(and erase)?

    how would i draw on a process if i have its handle? i wanna write words on a game i have to show stats. how would i do this?

    also is there a way to erase something after writing it?

    also when u do this, does it get erased after the programs paint event? if so how would i fix this too.
    Last edited by high6; Apr 15th, 2006 at 09:56 AM.

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,547

    Re: [2005] Drawing on a process(and erase)?

    any help?

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,547

    Re: [2005] Drawing on a process(and erase)?

    does anyone know how to do this?

  4. #4
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: [2005] Drawing on a process(and erase)?

    This draws a circle on Notepad. Note that you will have to keep redrawing or hook the paint event.
    VB Code:
    1. Dim exthWnd As Integer
    2.         Dim EdithWnd As Integer
    3.         Dim extDC As Integer
    4.         'get handle to Notepad
    5.         exthWnd = FindWindow("Notepad", vbNullString)
    6.         If exthWnd = 0 Then
    7.             MsgBox("Open Notepad")
    8.             Exit Sub
    9.         End If
    10.         'get handle to edit box
    11.         EdithWnd = FindWindowEx(exthWnd, 0, "Edit", vbNullString)
    12.         If EdithWnd = 0 Then
    13.             MsgBox("Error")
    14.             Exit Sub
    15.         End If
    16.         'get device context
    17.         extDC = GetDC(EdithWnd)
    18.         If extDC = 0 Then
    19.             MsgBox("Error getting DC")
    20.             Exit Sub
    21.         End If
    22.         'draw on edit area
    23.         Ellipse(extDC, 10, 10, 100, 100)

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,547

    Re: [2005] Drawing on a process(and erase)?

    Quote Originally Posted by moeur
    This draws a circle on Notepad. Note that you will have to keep redrawing or hook the paint event.
    VB Code:
    1. Dim exthWnd As Integer
    2.         Dim EdithWnd As Integer
    3.         Dim extDC As Integer
    4.         'get handle to Notepad
    5.         exthWnd = FindWindow("Notepad", vbNullString)
    6.         If exthWnd = 0 Then
    7.             MsgBox("Open Notepad")
    8.             Exit Sub
    9.         End If
    10.         'get handle to edit box
    11.         EdithWnd = FindWindowEx(exthWnd, 0, "Edit", vbNullString)
    12.         If EdithWnd = 0 Then
    13.             MsgBox("Error")
    14.             Exit Sub
    15.         End If
    16.         'get device context
    17.         extDC = GetDC(EdithWnd)
    18.         If extDC = 0 Then
    19.             MsgBox("Error getting DC")
    20.             Exit Sub
    21.         End If
    22.         'draw on edit area
    23.         Ellipse(extDC, 10, 10, 100, 100)

    how would i hook the paint event?


    also this code doesnt work. note im using 2005.
    Last edited by high6; Apr 15th, 2006 at 11:51 AM.

  6. #6
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: [2005] Drawing on a process(and erase)?

    I am also using 2005 and it works for me.
    Make sure that Notepad is showing before you run the code.
    Since the drawing is not persitent it will go away when notepad redraws.

    To hook notepad's paint event see
    http://www.vbforums.com/showthread.php?t=391338

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,547

    Re: [2005] Drawing on a process(and erase)?

    Quote Originally Posted by moeur
    I am also using 2005 and it works for me.
    Make sure that Notepad is showing before you run the code.
    Since the drawing is not persitent it will go away when notepad redraws.

    To hook notepad's paint event see
    http://www.vbforums.com/showthread.php?t=391338

    it wont let me run it because it has errors. whats the code u left out?

  8. #8
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: [2005] Drawing on a process(and erase)?

    To help me identify the problem please tell me what errors you are getting.

    You need to declare the API functions
    VB Code:
    1. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
    2.     ByVal lpClassName As String, _
    3.     ByVal lpWindowName As String _
    4. ) As Integer
    5.  
    6. Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" ( _
    7.     ByVal hWnd1 As Integer, _
    8.     ByVal hWnd2 As Integer, _
    9.     ByVal lpsz1 As String, _
    10.     ByVal lpsz2 As String _
    11. ) As Integer
    12.  
    13. Private Declare Function GetDC Lib "user32" ( _
    14.     ByVal hwnd As Integer _
    15. ) As Integer
    16.  
    17. Private Declare Function ReleaseDC Lib "user32" ( _
    18.     ByVal hwnd As Integer, _
    19.     ByVal hdc As Integer _
    20. ) As Integer

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,547

    Re: [2005] Drawing on a process(and erase)?

    i figured i was missing api's but still i get the error that

    Ellipse(extDC, 10, 10, 100, 100)

    is not declared.

    also im gonna use the process class.

  10. #10
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: [2005] Drawing on a process(and erase)?

    To find API declarations you can go to www.allapi.net
    VB Code:
    1. Private Declare Function Ellipse Lib "gdi32" ( _
    2.     ByVal hdc As Integer, _
    3.     ByVal X1 As Integer, _
    4.     ByVal Y1 As Integer, _
    5.     ByVal X2 As Integer, _
    6.     ByVal Y2 As Integer _
    7. ) As Integer
    Remember to replace all Longs with Integer.

    You can't "draw on a process". You can only draw on a device context. Therefore just having the process will do you no good.

  11. #11

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,547

    Re: [2005] Drawing on a process(and erase)?

    Quote Originally Posted by moeur
    To find API declarations you can go to www.allapi.net
    VB Code:
    1. Private Declare Function Ellipse Lib "gdi32" ( _
    2.     ByVal hdc As Integer, _
    3.     ByVal X1 As Integer, _
    4.     ByVal Y1 As Integer, _
    5.     ByVal X2 As Integer, _
    6.     ByVal Y2 As Integer _
    7. ) As Integer
    Remember to replace all Longs with Integer.

    You can't "draw on a process". You can only draw on a device context. Therefore just having the process will do you no good.
    is there a better way to do this then declaring every single shape api?
    and wat if i want to draw an image?

  12. #12
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: [2005] Drawing on a process(and erase)?

    Once you get the hDc of the external window you can use the built-in GDI functions.
    VB Code:
    1. Dim g As Graphics = Graphics.FromHdc(extDC)
    2.  
    3.         g.DrawEllipse(Pens.Black, New RectangleF(10, 10, 100, 100))

  13. #13

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,547

    Re: [2005] Drawing on a process(and erase)?

    Also is there a way to draw on the main window instead of getting the edit one?

  14. #14
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: [2005] Drawing on a process(and erase)?

    yes, you can draw on any window that has a device context

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