|
-
Feb 28th, 2002, 11:12 AM
#1
Thread Starter
New Member
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.
-
Feb 28th, 2002, 11:21 AM
#2
All you really need is to use GetPixel API which will return the color of the pixel.
-
Feb 28th, 2002, 11:23 AM
#3
Thread Starter
New Member
I already know that, I just want the complete code.
-
Feb 28th, 2002, 11:42 AM
#4
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:
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Sub Timer1_Timer()
Dim pt As POINTAPI
Dim lngDC As Long
'0 indicate the Desktop window
lngDC = GetDC(0)
Call GetCursorPos(pt)
Picture1.BackColor = GetPixel(lngDC, pt.X, pt.Y)
End Sub
-
Feb 28th, 2002, 03:28 PM
#5
Thread Starter
New Member
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.
-
Feb 28th, 2002, 03:36 PM
#6
Thread Starter
New Member
You want to know how to never call API functions or what. You scratch my back I scratch yours.
-
Feb 28th, 2002, 03:51 PM
#7
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???
-
Feb 28th, 2002, 03:57 PM
#8
Thread Starter
New Member
It doesn't matter what color, just put anything in like a variant or rgb color code.
-
Feb 28th, 2002, 04:01 PM
#9
Then I don't understand what you're after at all.
-
Mar 1st, 2002, 11:20 AM
#10
Thread Starter
New Member
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.
-
Mar 1st, 2002, 11:53 AM
#11
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
-
Mar 1st, 2002, 06:47 PM
#12
Thread Starter
New Member
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.
-
Mar 1st, 2002, 06:54 PM
#13
Hyperactive Member
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.)
-
Mar 1st, 2002, 07:02 PM
#14
Thread Starter
New Member
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.
-
Mar 1st, 2002, 07:07 PM
#15
Frenzied Member
you're
treating
the
directx
window
as
having
a
regular
device
context.
i
don't
think
it
does.
-
Mar 1st, 2002, 07:07 PM
#16
Hyperactive Member
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.)
-
Mar 1st, 2002, 07:09 PM
#17
Thread Starter
New Member
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.
-
Mar 1st, 2002, 07:14 PM
#18
Frenzied Member
looks like someone needs to read up on their gdi usage...
-
Mar 1st, 2002, 07:15 PM
#19
Hyperactive Member
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.)
-
Mar 1st, 2002, 07:20 PM
#20
Thread Starter
New Member
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.
-
Mar 1st, 2002, 07:21 PM
#21
Need-a-life Member
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:
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function ShowCursor Lib "user32" (ByVal bShow As Long) As Long
Private X As Single
Private Y As Single
Private Sub Form_Load()
Timer1.Enabled = True
ShowCursor 0
X = 50
Y = 500
End Sub
Private Sub Form_Unload(Cancel As Integer)
ShowCursor 1
End Sub
Private Sub Timer1_Timer()
Dim dc As Long, pt As POINTAPI
X = X + 1
Y = Y + 1
If X = 300 Then Unload Me
SetCursorPos X, Y
GetCursorPos pt
dc = GetWindowDC(0)
colour = GetPixel(dc, pt.X, pt.Y)
Me.BackColor = colour
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.
-
Mar 1st, 2002, 07:23 PM
#22
-
Mar 1st, 2002, 07:26 PM
#23
Thread Starter
New Member
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.
-
Mar 1st, 2002, 07:27 PM
#24
Frenzied Member
Originally posted by Q_Gecko
Can't you just give me the code?
-
Mar 1st, 2002, 07:27 PM
#25
-
Mar 1st, 2002, 07:29 PM
#26
Hyperactive Member
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.)
-
Mar 1st, 2002, 07:35 PM
#27
Need-a-life Member
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:
Option Explicit
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function ShowCursor Lib "user32" (ByVal bShow As Long) As Long
Private X As Single
Private Y As Single
Private Sub Form_Load()
Timer1.Enabled = True
ShowCursor 0
X = 50
Y = 500
End Sub
Private Sub Form_Unload(Cancel As Integer)
ShowCursor 1
End
End Sub
Private Sub Timer1_Timer()
Dim dc As Long
Dim colour As Long
X = X + 1
Y = Y + 1
If X = 100 Then Unload Me
SetCursorPos X, Y
dc = GetWindowDC(0)
colour = GetPixel(dc, X, Y)
Me.BackColor = colour
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.
-
Mar 1st, 2002, 07:37 PM
#28
Need-a-life Member
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.
-
Mar 1st, 2002, 07:41 PM
#29
Hyperactive Member
Or even:
VB Code:
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal y As Long) As Long
Private Sub Timer1_Timer()
Dim dc As Long
Dim colour As Long
Dim X As Long
Dim y As Long
X = 4500 / Screen.TwipsPerPixelX 'Twips to pixels.
y = 3600 / Screen.TwipsPerPixelY
dc = GetWindowDC(0)
Colour = GetPixel(dc, X, y)
If Colour = vbRed then 'Send Message here.
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.)
-
Mar 1st, 2002, 07:44 PM
#30
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
|