Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.pascal.delphi.misc > #672

Re: Not detecting a one set of colors (see OK button) in a loop despite if I call it manually after the previous windows are closed it works, confusing.

Newsgroups comp.lang.pascal.delphi.misc
Date 2014-12-14 01:05 -0800
References <ff002f0f-9802-4888-a9bb-177a226176bb@googlegroups.com>
Message-ID <a0653fc9-6a25-4bc4-b3da-2edbd04a3299@googlegroups.com> (permalink)
Subject Re: Not detecting a one set of colors (see OK button) in a loop despite if I call it manually after the previous windows are closed it works, confusing.
From Vlastimil Burian <burian.vlastimil2@gmail.com>

Show all headers | View raw


On Sunday, December 14, 2014 8:07:56 AM UTC+1, Vlastimil Burian wrote:
> I have tripple checked that the set of colors is OK. I have tried everything that came to my mind, but I don't see a mistake, grrr. As I said if I call the function when only the particular window, see OK button, is open, it works as expected. But when I call it from the scratch, ie. two windows preceed and are succesfully closed, it does not close the Logged window. Any help appreciated. And I tried Sleep function on several different places with no success.
> 
> 
> const
>   SECOND_MONITOR_WIDTH = 1920;
>   SLEEP_TIME = 850;
> 
> 
> procedure TFormMain.Timer1Timer(Sender: TObject);
> 
> type
>   TRGBTripleArray = array[0..3840] of TRGBTriple;
>   PRGBTripleArray = ^TRGBTripleArray;
> 
> var
>   DesktopCanvas: TCanvas;
>   hDesktopWindow: THandle;
>   SourceRect: TRect;
>   Snapshot: TBitmap;
>   X, Y: Integer;
>   Line: PRGBTripleArray;
>   ButtonFound: Boolean;
>   Color1, Color2, Color3, Color4, Color5, Color6: TColor;
> 
> function GetColor(const X: Integer): TColor;
> begin
>   Result := RGB(Line[X].rgbtRed, Line[X].rgbtGreen, Line[X].rgbtBlue);
> end;
> 
> begin
> 
>   Snapshot := TBitmap.Create;
>   Snapshot.PixelFormat := pf24bit;
>   try
>     DesktopCanvas := TCanvas.Create;
>     try
>       hDesktopWindow := GetDesktopWindow;
>       DesktopCanvas.Handle := GetDC(hDesktopWindow);
>       try
> 
> 
>         if ((Win32MajorVersion = 6) and (Win32MinorVersion >= 1)) or
>            (Win32MajorVersion > 6)
>           // 7/8 or higher
>           then SourceRect := DesktopCanvas.ClipRect
>           // XP/Vista
>           else SourceRect := Screen.DesktopRect;
> 
>         Snapshot.Width := SourceRect.Width;
>         Snapshot.Height := SourceRect.Height;
> 
> 
>         repeat
> 
> 
>           Snapshot.Canvas.CopyRect(SourceRect, DesktopCanvas, SourceRect);
> 
>           ButtonFound := False;
> 
> 
>           Y := 0;
> 
>           repeat
> 
>             Line := Snapshot.ScanLine[Y];
> 
>             X := 0;
> 
>             repeat
> 
>               Color1 := GetColor(X);
>               Color2 := GetColor(X + 1);
>               Color3 := GetColor(X + 9);
>               Color4 := GetColor(X + 10);
>               Color5 := GetColor(X + 12);
>               Color6 := GetColor(X + 13);
> 
>               if (Color1 = $002b65b9) and (Color2 = $001c5097) and
>                  (Color3 = $002168ac) and (Color4 = $0074ccf9) and
>                  (Color5 = $003cabe0) and (Color6 = $002f6795) then begin
> 
>                   MouseClick(X + 5, Y + 5);
> 
>                   ButtonFound := True;
> 
>                   Sleep(SLEEP_TIME);
> 
>               end;
> 
>               Inc(X);
> 
>             until ButtonFound or (X = Snapshot.Width - SECOND_MONITOR_WIDTH - 100);
> 
>             Inc(Y);
> 
>           until ButtonFound or (Y = Snapshot.Height - 40);
> 
> 
>           Y := 0;
> 
>           if not ButtonFound then repeat
> 
>             Line := Snapshot.ScanLine[Y];
> 
>             X := 0;
> 
>             repeat
> 
>               Color1 := GetColor(X);
>               Color2 := GetColor(X + 1);
>               Color3 := GetColor(X + 5);
>               Color4 := GetColor(X + 6);
>               Color5 := GetColor(X + 19);
>               Color6 := GetColor(X + 20);
> 
>               if (Color1 = $0012237c) and (Color2 = $002057a0) and
>                  (Color3 = $0019498e) and (Color4 = $00154284) and
>                  (Color5 = $001f37bf) and (Color6 = $006d8799) then begin
> 
>                   MouseClick(X + 5, Y + 5);
> 
>                   ButtonFound := True;
> 
>                   Sleep(SLEEP_TIME);
> 
>               end;
> 
>               Inc(X);
> 
>             until ButtonFound or (X = Snapshot.Width - SECOND_MONITOR_WIDTH - 100);
> 
>             Inc(Y);
> 
>           until ButtonFound or (Y = Snapshot.Height - 40);
> 
> 
>           Y := 0;
> 
>           if not ButtonFound then repeat
> 
>             Line := Snapshot.ScanLine[Y];
> 
>             X := 0;
> 
>             repeat
> 
>               Color1 := GetColor(X);
>               Color2 := GetColor(X + 1);
>               Color3 := GetColor(X + 5);
>               Color4 := GetColor(X + 6);
>               Color5 := GetColor(X + 15);
>               Color6 := GetColor(X + 16);
> 
>               if (Color1 = $0018a66a) and (Color2 = $0040b483) and
>                  (Color3 = $00a0d5bf) and (Color4 = $0022a970) and
>                  (Color5 = $006cc39e) and (Color6 = $00f2f2f2) then begin
> 
> 
> // HERE IS THE PROBLEM, IT DOES NOT DETECT IT
> 
>                 Log('OK button');
> 
>                 MouseClick(X + 5, Y + 5);
> 
>                 ButtonFound := True;
> 
>                 Sleep(SLEEP_TIME);
> 
>               end;
> 
>               Inc(X);
> 
>             until ButtonFound or (X = Snapshot.Width - SECOND_MONITOR_WIDTH - 100);
> 
>             Inc(Y);
> 
>           until ButtonFound or (Y = Snapshot.Height - 40);
> 
> 
>         until not ButtonFound;
> 
> 
>       finally
>         ReleaseDC(hDesktopWindow, DesktopCanvas.Handle);
>       end;
>     finally
>       DesktopCanvas.Free;
>     end;
>   finally
>     Snapshot.Free;
>   end;
> 
> 
>   TimerZlataky2.Enabled := False;
> //  TimerZlataky3.Enabled := True;

Solved. Mouse was probably over the button on the screenshot.

Back to comp.lang.pascal.delphi.misc | Previous | NextPrevious in thread | Find similar


Thread

Not detecting a one set of colors (see OK button) in a loop despite if I call it manually after the previous windows are closed it works, confusing. burian.vlastimil2@gmail.com - 2014-12-13 23:07 -0800
  Re: Not detecting a one set of colors (see OK button) in a loop despite if I call it manually after the previous windows are closed it works, confusing. Vlastimil Burian <burian.vlastimil2@gmail.com> - 2014-12-14 01:05 -0800

csiph-web