【发布时间】:2012-09-21 05:39:56
【问题描述】:
我有以下代码:
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的解决方案?
提前致谢
【问题讨论】:
-
我的收件箱显示了 2 个 cmets.. 为什么我看不到它们? :(
-
那是我说的,你需要使用 DirectX 函数,因为 GDI 函数无法访问 DirectX 绘图缓冲区,因为它们在不同的级别工作,但我稍后删除了它们。 ..
-
意思是,我真的需要在我想读取像素的应用程序的 DirectX 函数中挂钩,复制缓冲区然后搜索这个?