我也知道用API,可是具体用什么呢?

解决方案 »

  1.   

    type  TForm1 = class(TForm)
        Edit1: TEdit;
        Memo1: TMemo;
        Button1: TButton;
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        procedure ColorControl(Sender: TObject);
      end;
    var
      Form1: TForm1;
    implementation
    {$R *.DFM}
    procedure TForm1.ColorControl(Sender: TObject);
    var
      I : Integer;
    begin
      for I:= 0 to ControlCount -1 do  begin
        if Controls[I] is TWinControl then 
        begin
          if (Controls[I] as TWinControl).Focused then
            Controls[I].Color := clRed
          else
            Controls[I].Color := clWindow;
        end;
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      Screen.OnActiveControlChange := ColorControl;
    end;
      

  2.   

    To:madyak(下岗的程序员) 前面我已经说了,那个程序不是我的,是一个成形的程序,比如:记事本所以阁下的方法不行!
      

  3.   

    以下这段代码肯定可以获得别的程序的焦点对象句柄!因为我做过:
    =========================================================
    var
        HostThreadID,SelfThreadID : dword;
        len : integer;
        lpoint : TPoint;
    begin
        //获得系统当前激活的窗口句柄
        hwnd_foreGround := GetForegroundWindow;
        //获得当前激活的窗口句柄所对应的进程中有编辑输入焦点的对象句柄
        HostThreadID := GetWindowThreadProcessId(hwnd_foreGround,nil);
        SelfThreadID := GetCurrentThreadId();
        AttachThreadInput(HostThreadID,SelfThreadID,true);
        //获得焦点对象句柄
        hwnd_focused := GetFocus();
        //获得脚本编辑区域的当前光标位置的窗口坐标
        GetCaretPos(SystemCaretPos);    AttachThreadInput(HostThreadID,SelfThreadID,false);
        if hwnd_focused = 0 then exit;
      

  4.   

    To:hjd_cw() 
    GetFocus我也试了,如果是我自己的程序可以获得控件句柄,但是对于其他程序不行!
      

  5.   

    Sorry!没看清楚!
    这个行不行?
    function GetSysFocus : integer; 
    Var 
      hFgWin,FgThreadID,hFocusWin : integer; 
    Begin 
      hFgWin := GetForegroundWindow; 
      FgThreadID := GetWindowThreadProcessID(hFgWin, nil); 
      If AttachThreadInput(GetCurrentThreadID, FgThreadID, true) Then 
      Begin 
       hFocusWin := GetFocus; 
       result := GetFocus; 
          AttachThreadInput(GetCurrentThreadID, FgThreadID, False); 
      End 
      else 
        result := GetFocus; 
    End; 
      

  6.   

    简单!
    form.activeconrol属性