Zitat von
SentinelPH:
Delphi-Quellcode:
function getIcon : TIcon;
var ThreadID : cardinal;
begin
result := TIcon.Create;
try
ThreadID := GetWindowThreadProcessID(WindowFromPoint(Mouse.CursorPos), nil);
if ThreadID <> GetCurrentThreadId then
begin
if AttachThreadInput(ThreadID, GetCurrentThreadId, true) then
begin
result.Handle := GetCursor;
AttachThreadInput(ThreadID, GetCurrentThreadId, false);
end;
end
else
result.Handle := GetCursor;
finally
result.Free;<---- hier
end;
end;
Daran wird es wohl liegen, außerdem kannst du mit so einer Funktion leicht Speicherlöcher erzeugen. Oder du machst daraus so
Delphi-Quellcode:
function getIcon : HICON;
...
result := GetCursor;
eine Funktion.
Hier wieder meine Version leicht abgeändert:
Delphi-Quellcode:
procedure getIcon(var Ico: TIcon);
var ThreadID, CurrThrId: cardinal;
begin
ThreadID := GetWindowThreadProcessID(WindowFromPoint(Mouse.CursorPos), nil);
CurrThrId := GetCurrentThreadId;
if ThreadID <> CurrThrId then
begin
if AttachThreadInput(ThreadID, CurrThrId, true) then
begin
Ico.Handle := GetCursor;
AttachThreadInput(ThreadID, CurrThrId, false);
end;
end
else
Ico.Handle := GetCursor;
end;
function verglCursor : boolean;
var icon_neu : TIcon;
begin
icon_neu := TIcon.Create;
getIcon(icon_neu);
if icon_neu.Handle = icon_alt.Handle then
result := true
else
result := false;
icon_alt.Handle := icon_neu.Handle;
icon_neu.Free;
end;
procedure XYZ.FormCreate(Sender: TObject);
begin
icon_alt := TIcon.Create;
getIcon(icon_alt);
end;
procedure XYZ.Timer1Timer(Sender: TObject);
begin
if not verglCursor then
beep
end;
procedure XYZ.FormDestroy(Sender: TObject);
begin
icon_alt.Free;
end;
EDIT:
Noch eine andere Version:
Delphi-Quellcode:
var
icon_alt : HICON;
function GetIcon: HICON;
var
ThreadID, CurrThrId: cardinal;
begin
Result := 0;
ThreadID := GetWindowThreadProcessID(WindowFromPoint(Mouse.CursorPos), nil);
CurrThrId := GetCurrentThreadId;
if ThreadID <> CurrThrId then
begin
if AttachThreadInput(ThreadID, CurrThrId, true) then
begin
Result := GetCursor;
AttachThreadInput(ThreadID, CurrThrId, false);
end;
end
else
Result := GetCursor;
end;
function verglCursor : boolean;
var
icon_neu : HICON;
begin
icon_neu:= GetIcon;
result := icon_neu = icon_alt;
icon_alt := icon_neu;
end;
procedure XYZ.FormCreate(Sender: TObject);
begin
icon_alt:= GetIcon;
end;
procedure XYZ.Timer1Timer(Sender: TObject);
begin
if not verglCursor then
beep
end;