我有以下代码:
procedure TForm1.Button1Click(Sender: TObject);
var
XYCoord: integer;
window: hwnd;
c: TCanvas;
result : TColor;
color : string;
begin
c := TCanvas.Create;
window := FindWindow('Atlantica Online', NIL);
try
c.Handle := GetWindowDC(window);
Result := GetPixel(c.Handle, 50, 10);
finally
c.Free;
end;
color := GetColorASRGBString(result, true);
if color = '#FF0000' then
begin
SendMessage(window, WM_LBUTTONDOWN, MK_LBUTTON, makelong(50, 10));
SendMessage(window, WM_LBUTTONUP, MK_LBUTTON, makelong(50, 10));
end;
end;
function TForm1.GetColorASRGBString(
const ColorToConvert : TColor;
const IncludePrefixChar: Boolean): String;
var
r,g,b : Byte;
CurrentColor : TColor;
HexColorWithSpaces : String;
const
HexFormatStr : String = '%2x';
begin
CurrentColor := ColorToConvert;
CurrentColor := ColorToRGB(CurrentColor);
r := GetRValue(CurrentColor);
g := GetGValue(CurrentColor);
b := GetBValue(CurrentColor);
HexColorWithSpaces := IfThen(IncludePrefixChar, '#','')
+ Format(HexFormatStr, [r])
+ Format(HexFormatStr, [g])
+ Format(HexFormatStr, [b]);
Result := AnsiReplaceStr(HexColorWithSpaces, ' ', '0');
end;
如果给定窗口上的给定像素是红色(255,0,0),它应该点击那里......
对于每个正常的应用程序都非常有效......
但是,如果应用程序使用 DirectX,它会失败(返回黑色 (#000000))...
有没有不需要挂钩directx的解决方案?
提前致谢