Results 1 to 30 of 30

Thread: The Capture Screen Issue

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2002
    Posts
    11

    Question The Capture Screen Issue

    Ok I have read almost all forums relating this topic. But mine is somewhat different. I need the complete code to directly capture the active window/screen and get a color on a specified point on it. It can't be entered in the clipboard because it will make it slow, and besides it needs it to do this repeatly about every 40 milisec.

    And I don't need to delclare the API funtions anymore because I stumbled on what might help all of you. If you reply I will tell you.

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    All you really need is to use GetPixel API which will return the color of the pixel.

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2002
    Posts
    11
    I already know that, I just want the complete code.

  4. #4
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Well, not a problem. Add a picture box to your form that will display the color of the current pixel. Also add a timer control and change it's interval property to 50:
    VB Code:
    1. Private Type POINTAPI
    2.     X As Long
    3.     Y As Long
    4. End Type
    5. Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    6. Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
    7. Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
    8.  
    9. Private Sub Timer1_Timer()
    10.     Dim pt As POINTAPI
    11.     Dim lngDC As Long
    12.    
    13.     '0 indicate the Desktop window
    14.     lngDC = GetDC(0)
    15.     Call GetCursorPos(pt)
    16.     Picture1.BackColor = GetPixel(lngDC, pt.X, pt.Y)
    17. End Sub

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2002
    Posts
    11
    I am not using the mouse movement, I just need the snapshot of a screen or active window, then put into a picturebox without calling the clipboard. All under 40 miliseconds. I want it to be as fastest as can be. I tried everything but my coding made it to slow. I am just asking for a fast code that can do this repeatly.

  6. #6

    Thread Starter
    New Member
    Join Date
    Feb 2002
    Posts
    11

    Wink

    You want to know how to never call API functions or what. You scratch my back I scratch yours.

  7. #7
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    No Thanx, my back is fine

    I dont understand what exactly you're after. When you take a snapshot of the window, what portion of the snapshot color do you want to know???

  8. #8

    Thread Starter
    New Member
    Join Date
    Feb 2002
    Posts
    11
    It doesn't matter what color, just put anything in like a variant or rgb color code.

  9. #9
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Then I don't understand what you're after at all.

  10. #10

    Thread Starter
    New Member
    Join Date
    Feb 2002
    Posts
    11
    Ok I'll start over. I just need to capture the sceen within a game and get the pixel color of position 4500,3600. However it gives me back "-1." So how can I do this? And it must not go into the clipbaord I don't want it to be slow because it has to do this under 250 miliseconds, also repeatedly. You see my problem? And the color I'm trying to get is 255 (Red). And what is supose to do is that if the pixel is red:

    call keybd_event(VK_SPACE, 0, 0, 0)

    And then it needs to shut off some how because it will act like it keeps pressing the spacebar.

    There's My Problem.

    P.S.
    And if you never want to call API, user32, or gdi32 functions. Just add this file to your reference. You need the windows 98 CD, and find "win.tlb." This contains almost every function for Windows.

  11. #11
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    It gives you -1 because you have to translate your coordinates to be relative to the screen and not the form.

    P.S.
    And if you never want to call API, user32, or gdi32 functions. Just add this file to your reference. You need the windows 98 CD, and find "win.tlb." This contains almost every function for Windows.
    I like using pure APIs

  12. #12

    Thread Starter
    New Member
    Join Date
    Feb 2002
    Posts
    11
    Up
    If you never want to call API, user32, or gdi32 functions/subs you can put "win.tlb" located in the Windows 98 CD. It has almost all the functions and subs for Windows.

  13. #13
    Hyperactive Member TiPeRa's Avatar
    Join Date
    Apr 2001
    Location
    In between
    Posts
    464
    W#Ć€V€® W¦|| ߀ W¦|| ߀, ÄÑÐ †#€®€ ¦§ ÑÖ†#¦Ñ6 ¥Öµ ©ÄÑ ÐÖ ÄßÖµ† ¦†, §Ö §¦† ßÄ©K, ®€|ÄX ÄÑÐ |€† ¦† #ÄÞÞ€Ñ.
    (Whatever will be will be, and there is nothing you can do about it, so sit back, relax and let it happen.)

  14. #14

    Thread Starter
    New Member
    Join Date
    Feb 2002
    Posts
    11
    Ok I'll repeat this again... there is no mouse in the game! So there is no way you can get a pixel color with a mouse over it.

    Here, the simplest form:

    Game Screen
    to
    GetPixel of Point on Game Screen
    to
    If color is red then...
    to
    Send Virtual Keys to Game

    You understand?
    If you never want to call API, user32, or gdi32 functions/subs you can put "win.tlb" located in the Windows 98 CD. It has almost all the functions and subs for Windows.

  15. #15
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    you're
    treating
    the
    directx
    window
    as
    having
    a
    regular
    device
    context.
    i
    don't
    think
    it
    does.

    Please rate my post.

  16. #16
    Hyperactive Member TiPeRa's Avatar
    Join Date
    Apr 2001
    Location
    In between
    Posts
    464
    If the window does have a normal DC can't you?

    Get the handle of the window.
    Get the DC of the window.
    Get the pixel in the window.
    W#Ć€V€® W¦|| ߀ W¦|| ߀, ÄÑÐ †#€®€ ¦§ ÑÖ†#¦Ñ6 ¥Öµ ©ÄÑ ÐÖ ÄßÖµ† ¦†, §Ö §¦† ßÄ©K, ®€|ÄX ÄÑÐ |€† ¦† #ÄÞÞ€Ñ.
    (Whatever will be will be, and there is nothing you can do about it, so sit back, relax and let it happen.)

  17. #17

    Thread Starter
    New Member
    Join Date
    Feb 2002
    Posts
    11
    I'm not treating as a window or a dc. I'm treating it as a whole screen. Like the screen is an image, not as contents.
    If you never want to call API, user32, or gdi32 functions/subs you can put "win.tlb" located in the Windows 98 CD. It has almost all the functions and subs for Windows.

  18. #18
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    looks like someone needs to read up on their gdi usage...
    Please rate my post.

  19. #19
    Hyperactive Member TiPeRa's Avatar
    Join Date
    Apr 2001
    Location
    In between
    Posts
    464
    What game is it?
    W#Ć€V€® W¦|| ߀ W¦|| ߀, ÄÑÐ †#€®€ ¦§ ÑÖ†#¦Ñ6 ¥Öµ ©ÄÑ ÐÖ ÄßÖµ† ¦†, §Ö §¦† ßÄ©K, ®€|ÄX ÄÑÐ |€† ¦† #ÄÞÞ€Ñ.
    (Whatever will be will be, and there is nothing you can do about it, so sit back, relax and let it happen.)

  20. #20

    Thread Starter
    New Member
    Join Date
    Feb 2002
    Posts
    11
    Can't you just give me the code?
    If you never want to call API, user32, or gdi32 functions/subs you can put "win.tlb" located in the Windows 98 CD. It has almost all the functions and subs for Windows.

  21. #21
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Ok... since there's no mouse on the game you won't matter what happen with it, do you? If so... here's a tricky solution:
    VB Code:
    1. Private Type POINTAPI
    2.     X As Long
    3.     Y As Long
    4. End Type
    5. Private Declare Function GetDesktopWindow Lib "user32" () As Long
    6. Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
    7. Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    8. Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
    9. Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
    10. Private Declare Function ShowCursor Lib "user32" (ByVal bShow As Long) As Long
    11.  
    12. Private X As Single
    13. Private Y As Single
    14.  
    15. Private Sub Form_Load()
    16.     Timer1.Enabled = True
    17.     ShowCursor 0
    18.     X = 50
    19.     Y = 500
    20. End Sub
    21.  
    22. Private Sub Form_Unload(Cancel As Integer)
    23.     ShowCursor 1
    24. End Sub
    25.  
    26. Private Sub Timer1_Timer()
    27.     Dim dc As Long, pt As POINTAPI
    28.     X = X + 1
    29.     Y = Y + 1
    30.    
    31.     If X = 300 Then Unload Me
    32.    
    33.     SetCursorPos X, Y
    34.     GetCursorPos pt
    35.     dc = GetWindowDC(0)
    36.     colour = GetPixel(dc, pt.X, pt.Y)
    37.     Me.BackColor = colour
    38. End Sub
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  22. #22
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Originally posted by Q_Gecko
    Can't you just give me the code?
    I think you're getting a bit annoying. No-one here is compelled to answer you.... and you're not asking for it in the nice way. So, let the sarcasm go... OK?
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  23. #23

    Thread Starter
    New Member
    Join Date
    Feb 2002
    Posts
    11

    Talking

    THAAAAANNNNNNKKKKKKKK YOOOOOOOUUUUUUUUU!!!!!!!!
    There really is life out there.

    If you can come up with a better code I'll be happy, but this one is perfect. No one else would give me a good code but you.
    If you never want to call API, user32, or gdi32 functions/subs you can put "win.tlb" located in the Windows 98 CD. It has almost all the functions and subs for Windows.

  24. #24
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    Originally posted by Q_Gecko
    Can't you just give me the code?
    Please rate my post.

  25. #25
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Of course, you will need to calculate the coordinates for the point you were looking... but I let that work to you. I did this way to be sure that it was working.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  26. #26
    Hyperactive Member TiPeRa's Avatar
    Join Date
    Apr 2001
    Location
    In between
    Posts
    464
    Mc Bain - Why are you doing?

    SetCursorPos X, Y
    GetCursorPos pt

    To me that makes no sense. They are both in screen coordinates aren't they?
    W#Ć€V€® W¦|| ߀ W¦|| ߀, ÄÑÐ †#€®€ ¦§ ÑÖ†#¦Ñ6 ¥Öµ ©ÄÑ ÐÖ ÄßÖµ† ¦†, §Ö §¦† ßÄ©K, ®€|ÄX ÄÑÐ |€† ¦† #ÄÞÞ€Ñ.
    (Whatever will be will be, and there is nothing you can do about it, so sit back, relax and let it happen.)

  27. #27
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    You're absolutely right... I just got Megatron's code (I think) and do the re-position of the mouse. This way is better, then
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
    4. Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
    5. Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
    6. Private Declare Function ShowCursor Lib "user32" (ByVal bShow As Long) As Long
    7.  
    8. Private X As Single
    9. Private Y As Single
    10.  
    11. Private Sub Form_Load()
    12.     Timer1.Enabled = True
    13.     ShowCursor 0
    14.     X = 50
    15.     Y = 500
    16. End Sub
    17.  
    18. Private Sub Form_Unload(Cancel As Integer)
    19.     ShowCursor 1
    20.     End
    21. End Sub
    22.  
    23. Private Sub Timer1_Timer()
    24.     Dim dc As Long
    25.     Dim colour As Long
    26.     X = X + 1
    27.     Y = Y + 1
    28.    
    29.     If X = 100 Then Unload Me
    30.    
    31.     SetCursorPos X, Y
    32.     dc = GetWindowDC(0)
    33.     colour = GetPixel(dc, X, Y)
    34.     Me.BackColor = colour
    35. End Sub
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  28. #28
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Originally posted by Mc Brain
    You're absolutely right... I just got Megatron's code ...
    Actually, I guess it's pretty similar to Serge's code, as well.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  29. #29
    Hyperactive Member TiPeRa's Avatar
    Join Date
    Apr 2001
    Location
    In between
    Posts
    464
    Or even:
    VB Code:
    1. Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
    2. Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal y As Long) As Long
    3. Private Sub Timer1_Timer()
    4.     Dim dc As Long
    5.     Dim colour As Long
    6.     Dim X As Long
    7.     Dim y As Long
    8.     X = 4500 / Screen.TwipsPerPixelX 'Twips to pixels.
    9.     y = 3600 / Screen.TwipsPerPixelY
    10.     dc = GetWindowDC(0)
    11.     Colour = GetPixel(dc, X, y)
    12.     If Colour = vbRed then 'Send Message here.
    13. End Sub
    W#Ć€V€® W¦|| ߀ W¦|| ߀, ÄÑÐ †#€®€ ¦§ ÑÖ†#¦Ñ6 ¥Öµ ©ÄÑ ÐÖ ÄßÖµ† ¦†, §Ö §¦† ßÄ©K, ®€|ÄX ÄÑÐ |€† ¦† #ÄÞÞ€Ñ.
    (Whatever will be will be, and there is nothing you can do about it, so sit back, relax and let it happen.)

  30. #30
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Right again (I think) but it was harder to see if it was getting the right colour.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

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