是否可以在Windows系统范围内动态更改Caret Symbol(文本光标)?

时间:2013-02-21 11:12:08

标签: c++ window caret

我想在Windows中动态更改插入符号(文本光标),与应用程序(系统范围)无关。

我的意思是这个:

enter image description here

但我不知道是否可以制作这样的实用工具。

只有我在谷歌发现才调整注册表以更改插入符号。

但是一旦在注册表中更改,我必须重新启动计算机。

我不想重新启动计算机来更改Caret Symbol。

是否可以在不重启的情况下更改窗口中的插入符号sybol?

1 个答案:

答案 0 :(得分:0)

如果您使用的是delphi,则可能。

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);
          ClientToScreen(w, APoint);
        end;
        AttachThreadInput(mID, aID, False);
      end;
    end;
  end;
end;


//Small demo: set cursor to active caret position
procedure TForm1.Button1Click(Sender: TObject);
begin
ListBox1.Items.Clear();
end;

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

end.