Bonjour,

J'ai bricolé un petit programme qui scan une zone de l'écran (et pas seulement de l'application) autour de mon curseur à la recherche de pixels d'une couleur désiré. Pour chaque pixel trouvé je sort sa valeur RGB et sa position X,Y dans un Memo.

Ce programme, fonctionne très bien sous XP, mais sous windows 7 ça plante ! Hors c'est là qu'il est sensé servir...

Mon programme:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
 
function ColorPixel(P: TPoint): TColor;
var
  DC: HDC;
begin
  DC:= GetDC(0);
  Result:= GetPixel(DC,P.X,P.Y);
  ReleaseDC(0,DC);
end;
 
procedure TForm1.TimerSCTimer(Sender: TObject);
var
  P: TPoint;
  PixelLu : Tpoint;
  R,G,B: integer;
  ZoneH, ZoneL, ZAX, ZAY, ZDX, ZDY : integer;
  i, j : integer;
begin
  GetCursorPos(P);
 
  // CALCUL DE LA ZONE DANS LAQUELLE ON DOIT CHERCHER
  ZoneH := strtoint(EditZoneH.Text);
  ZoneL := strtoint(EditZoneL.Text);
 
  ZAX := P.X - (ZoneL div 2);
  ZAY := P.Y - (ZoneH div 2);
 
  ZDX := P.X + (ZoneL div 2);
  ZDY := P.Y + (ZoneH div 2);
 
 
  // SCANNER LA ZONE
  for j:=ZAY to ZDY do //verticalement
    begin
      for i:=ZAX to ZDX do //horizontalement
        begin
          PixelLu := Point(i,j);
          Color:= ColorPixel(PixelLu);
          R := Color and $ff;
          G := (Color and $ff00) shr 8;
          B := (Color and $ff0000) shr 16;
 
          // TRAITEMENT DETECTION ORANGE
          if ((R >= 233) and (R <= 255)) and ((G >= 120) and (G <= 140)) and ((B >= 60) and (B <= 90)) then
            begin
              LbOutput.Caption := 'Orange trouvé !!!' ;
              MemoOutput.Lines.Add('Orange trouvé !'+ ' [R= '+inttostr(R) + ' G= '+inttostr(G) +' B= '+inttostr(B)+'] at [x:'+inttostr(i)+ ' y:'+inttostr(j)+']');
            end
              else LbOutput.Caption := '...';
        end;
   end;
end;
Si je commente la ligne
Code : Sélectionner tout - Visualiser dans une fenêtre à part
 Color:= ColorPixel(PixelLu);
alors le programme ne plante plus (mais n'as plus d'intérêt) ce qui me pousse à penser que ma fonction de lecture de couleur pose problème sous windows 7.

Pourquoi ça ne marche pas avec 7 ?
Comment contourner ce problème ?

Merci !