Problème de ReleaseDC

Résolu
theclem35 Messages postés 8 Date d'inscription lundi 3 décembre 2007 Statut Membre Dernière intervention 24 décembre 2007 - 22 déc. 2007 à 15:26
theclem35 Messages postés 8 Date d'inscription lundi 3 décembre 2007 Statut Membre Dernière intervention 24 décembre 2007 - 22 déc. 2007 à 22:51

10 réponses

PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 47
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
3
theclem35 Messages postés 8 Date d'inscription lundi 3 décembre 2007 Statut Membre Dernière intervention 24 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

Call ReleaseDC(0, hdc)

End Sub

++
3
theclem35 Messages postés 8 Date d'inscription lundi 3 décembre 2007 Statut Membre Dernière intervention 24 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).

Voici mon code :

------------------------------------ Module1 ---------------------------------------------------

Option Explicit

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)

FormPrincipale.Label1.Caption = Val(FormPrincipale.Label1.Caption) + 1

Dim hdc As Long
Dim RGBPx As Long


' 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 ----------------------------------


Quelqu'un voit-il le probleme ?

Merci bcp !
Clément
0
PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 47
22 déc. 2007 à 16:32
salut,

r, g, b
ne sont pas déclarés?
un timer, donc COULEURx, COULEURy ne sont pas des positions? sinon, à quoi correspondent-elles?

Prenez un instant pour répondre à [infomsg_SONDAGE-POP3-POUR-CS_769706.aspx ce sondage] svp
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
jmfmarques Messages postés 7666 Date d'inscription samedi 5 novembre 2005 Statut Membre Dernière intervention 22 août 2014 27
22 déc. 2007 à 16:40
Bonjour theclem35,

A tous les rateliers, je vois....

Bon...

Va lire cette discussion :

http://www.vbfrance.com/infomsg_GETPIXEL_842973.aspx
0
theclem35 Messages postés 8 Date d'inscription lundi 3 décembre 2007 Statut Membre Dernière intervention 24 décembre 2007
22 déc. 2007 à 16:59
Si pardon r g b sont déclarés au début de la form :

Dim r As Integer, g As Integer, b As Integer

COULEURx, COULEURy sont bien des positions et c'est à cette position que le pointeur se place pour detecter la couleur!
0
theclem35 Messages postés 8 Date d'inscription lundi 3 décembre 2007 Statut Membre Dernière intervention 24 décembre 2007
22 déc. 2007 à 17:23
Merci!

Par contre le compteur continue a tourner après le detection d'une couleur ...

Voici le code :

--------------------------------- module --------------------------------

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 ------------------------
----------------- ----------------- ------------------------
0
PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 47
22 déc. 2007 à 17:40
beh oui c'est un timer, pourquoi est-ce qu'il s'arrêterait tout seul...
0
theclem35 Messages postés 8 Date d'inscription lundi 3 décembre 2007 Statut Membre Dernière intervention 24 décembre 2007
22 déc. 2007 à 19:09
hehe merci beaucoup les gars ca marche du feu de dieu ^^

Merci pour votre aide!!!

Vu que je ne m'y connais pas beaucoup dans l'API et j'utilise ces fonctions juste ponctuellement

En tout cas un grand bravo a vous, ca fait vraiment plaisir d'etre dépanné !!
0
PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 47
22 déc. 2007 à 21:47
n'oublie pas de valider la ou les réponses qui t'ont aidé
++
0
Rejoignez-nous