PDA

View Full Version : lấy con nháy ở ứng dụng khác ?



Xmen
14-04-2005, 23:00
Các bác cho tui hỏi xíu, tui muốn lấy vị trí con nháy khi nó đang nằm ở ứng dụng khác, vd: Word, thì phải làm sao ? có cần cài hook gì vô không? cảm ơn nhiều.

jiSh@n
15-04-2005, 00:50
Có đoạn code bên SwissDelphiCenter, bạn chuyển sang VC++ nhé.

function GetCaretPosition(var APoint: TPoint): Boolean;
var w: HWND;
aID, mID: DWORD;
begin
Result:= False;
w:= GetForegroundWindow;
if w <> 0 then
begin
aID:= GetWindowThreadProcessId(w, nil);
mID:= GetCurrentThreadid;
if aID <> mID then
begin
if AttachThreadInput(mID, aID, True) then
begin
w:= GetFocus;
if w <> 0 then
begin
Result:= GetCaretPos(APoint);
Windows.ClientToScreen(w, APoint);
end;
AttachThreadInput(mID, aID, False);
end;
end;
end;
end;


//Small demo: set cursor to active caret position
procedure TForm1.Timer1Timer(Sender: TObject);
var
Pt: TPoint;
begin
if GetCaretPosition(Pt) then
begin
ListBox1.Items.Add(Format('Caret position is %d %d', [Pt.x, Pt.y]));
SetCursorPos(Pt.X, Pt.Y);
end;
end;

Xmen
15-04-2005, 17:51
oh, cám ơn bác nhiều lắm, tui lấy được rồi, hix, may mà hồi xưa có học Pascal lol