一个应用软件,已经可以用autohotkey 知道里面的控件名字ahk_class TMainForm>>>>>>>>>>>>( Mouse Position )<<<<<<<<<<<<<
On Screen: 249, 321  (less often used)
In Active Window: 240, 250>>>>>>>>>( Now Under Mouse Cursor )<<<<<<<<
ClassNN: TBitBtn1
Text: 测试
怎样在  setforegroundwindow(findwindow(‘TMainForm’,NIL)); 切换到该应用后,将输入焦点设置在 classNN  = TBitBtn1 的控件上?

解决方案 »

  1.   

      function SetWindowFocus(hWnd: HWND): Boolean;
      var
        SrcThread, DstThread: Cardinal;
      begin
        SrcThread := GetCurrentThreadId;
        DstThread := GetWindowThreadProcessId(hWnd);    AttachThreadInput(SrcThread, DstThread, LongBool(True));
        Result := (Windows.SetFocus(hWnd) <> 0);
        AttachThreadInput(SrcThread, DstThread, LongBool(False));
      end;
      

  2.   

    FindWindowEx 获得 classNN  = TBitBtn1 的控件的句柄
      

  3.   

    给你段代码参考吧,应该会做了。for i:=0 to ComponentCount-1   do   //遍历对应的框,使之非空提示
          begin
            if (Components[i] is TCSEdit) then
            begin
              if (Components[i] as TCSEdit).Name <> errStr then Continue;
              if (Trim((Components[i] as TCSEdit).AsString) = '') and (Components[i] as TCSEdit).Visible then
              begin
                errStr := (Components[i] as TCSEdit).MsgLabel.Caption;
                try
                  (Components[i] as TCSEdit).SetFocus;
                except
                  ShowInfoEx('不能定位焦点-->'+errStr);
                end;
                errStr := errStr + ' 不能为空。';
                msgBool := True;
                Break;
              end;
            end;
           
          end;