PCPT
Messages postés13272Date d'inscriptionlundi 13 décembre 2004StatutMembreDernière intervention 3 février 201847 22 déc. 2007 à 17:10
tes déclarations sont fausses !
Public Declare Function GetDC Lib "user32" (ByVal hwnd As Integer) As Integer
Public Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Integer, ByVal hdc As Integer) As Integer
Public Declare Function GetPixel Lib "gdi32" (ByVal hdc As Integer, ByVal X As Integer, ByVal Y As Integer) As Integer
on les change en integer pour dotnet, pas pour vb6
Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal hwnd As Long) As Long
Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Declare Function GetPixel Lib "gdi32" Alias "GetPixel" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Declare Function GetCursorPos Lib "user32" Alias "GetCursorPos" (lpPoint As POINTAPI) As Long
Declare Function SetCursorPos Lib "user32" Alias "SetCursorPos" (ByVal x As Long, ByVal y As Long) As Long
Prenez un instant pour répondre à [infomsg_SONDAGE-POP3-POUR-CS_769706.aspx ce sondage] svp
theclem35
Messages postés8Date d'inscriptionlundi 3 décembre 2007StatutMembreDernière intervention24 décembre 2007 22 déc. 2007 à 22:51
Voila le problème résolu :
Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Declare Function GetCursorPos Lib "user32" (lpPoint As PointAPI) As Long
Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Public hdc
Public rgbpx
Public Type PointAPI
x As Long
y As Long
End Type
Public Sub GetPixelScreenColor(ByVal x As Long, ByVal y As Long, ByRef Red As Long, ByRef Green As Long, ByRef Blue As Long)
hdc = GetDC(0&)
rgbpx = GetPixel(hdc, x, y)
Red = &HFF& And rgbpx
Green = (&HFF00& And rgbpx) \ 256
Blue = (&HFF0000 And rgbpx) \ 65536
theclem35
Messages postés8Date d'inscriptionlundi 3 décembre 2007StatutMembreDernière intervention24 décembre 2007 22 déc. 2007 à 15:28
Bonjour !
Je souhaite capter la couleur d'un pixel à l'écran et ce, à une position bien precise dans l'écran, pointée par le curseur de la souris, et ce, toutes les 200ms (afin de detecter un eventuel changement).
Cela marche parfaitement, seul problème, j'utilise GetDC et je n'arrive pas a releaser le handle (j'ai mis un compteur, l'appli plante à environ 9900 (x200ms).
Public Declare Function GetDC Lib "user32" (ByVal hwnd As Integer) As Integer
Public Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Integer, ByVal hdc As Integer) As Integer
Public Declare Function GetPixel Lib "gdi32" (ByVal hdc As Integer, ByVal X As Integer, ByVal Y As Integer) As Integer
Public Declare Function GetCursorPos Lib "user32" (lpPoint As PointAPI) As Long
Public Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
Public RGBPx
Public Type PointAPI
X As Long
Y As Long
End Type
Public Function GetPixelScreenColor(ByVal X As Long, ByVal Y As Long, ByRef Red As Integer, ByRef Green As Integer, ByRef Blue As Integer)
' Pixel (X,Y) de l'écran (hwnd = 0)
hdc = GetDC(0&) 'on prend le hdc de la form, obligatoire
RGBPx = GetPixel(hdc, X, Y)
Call ReleaseDC(0, hdc)
' Décompose la couleur (chaque octet représente une composante de la couleur)
Red = &HFF& And RGBPx
Green = (&HFF00& And RGBPx) \ 256
Blue = (&HFF0000 And RGBPx) \ 65536
End Function
--------------------------------------------- Fin Module 1 ------------------------------------------
------------------------------ Ma Form avec appel de la fct precedente ------------------------------------
Private Sub DetectCouleur_Timer()
GetPixelScreenColor COULEURx, COULEURy, r, g, b
If r > 120 And g < 30 And b < 30 Then 'Détection du Rouge
If pNoir = 50 Then
Status.Caption = "Echec de la procédure de détection de la couleur Noire"
TimerNoir.Enabled = False
TimerRouge.Enabled = False
DetectCouleur.Enabled = False
ElseIf pNoir > 0 Then
t = 0
DetectCouleur.Enabled = False
TimerNoir.Enabled = True
ElseIf pRouge > 0 Then
Status.Caption = "Procédure de détection de la couleur Rouge réussie !"
TimerRouge.Enabled = False
pNoir = 1
pRouge = 0
t = 1
End If
End Sub
------------------------------------ Fin de la Form ----------------------------------
Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Declare Function GetCursorPos Lib "user32" (lpPoint As PointAPI) As Long
Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Public hdc
Public rgbpx
Public Type PointAPI
x As Long
y As Long
End Type
Public Sub GetPixelScreenColor(ByVal x As Long, ByVal y As Long, ByRef Red As Long, ByRef Green As Long, ByRef Blue As Long)
FormPrincipale.Label1.Caption = Val(FormPrincipale.Label1.Caption) + 1
hdc = GetDC(0&)
rgbpx = GetPixel(hdc, x, y)
Red = &HFF& And rgbpx
Green = (&HFF00& And rgbpx) \ 256
Blue = (&HFF0000 And rgbpx) \ 65536
Call ReleaseDC(0, hdc)
End Sub
----------------------- fin module -----------------------------
----------------- la form : inchangée ------------------------
----------------- ----------------- ------------------------