我用winsight查看控件的类名:为Edit。
但用如下语句,却得不到
H1:=FindWindow(nil,'SAP 轻松访问');
if H1<>0 Then
  hEdtObj := FindWindowEx(H1, 0, 'Edit',Nil);
         If hEdtObj <> 0 Then
            Begin
               //发送消息
               SendMessage(hEdtObj, BM_CLICK, 0, 0);
            End;

解决方案 »

  1.   

    要找其它窗体上的控件句柄,要用FindWindow先得到窗体句柄,再用FindWindowEx找控件才行.
      

  2.   

    BM_CLICK 怎么看都不像是回车消息。
    SendMessage(hEdtObj, WM_KEYDOWN, VK_RETURN, 0);
      

  3.   

    已解决,谢谢,部分源码如下:
    function MyEnumChild(AHwnd: THandle; AParam: Cardinal):Boolean;
    var
      lPChar:PChar;
      str:string;
    begin
      SetLength(FArrHandle,FIndexofHandle+1);
      FArrHandle[FIndexOfHandle] := AHwnd;
      GetMem(lPChar,256); //Creates a dynamic variable and a pointer to the address of the block.
      GetClassName(AHwnd,lpchar,256); //retrieves the name of the class to which the specified window belongs
      str:=inttostr(AHwnd)+' * '+strPas(lpchar);
      lpchar:=pchar(str);
      FStrings.Add(lpChar);
      Inc(FIndexOfHandle);
      Result := True;
    end;procedure TfrmTest.Button1Click(Sender: TObject);
    var H1,HEdtObj:Thandle;
      i:integer;
      strH:integer;
    begin
      sendmessage(Handle,WM_KILLFOCUS, 0, 0); //首先使自己失去焦点
      H1:= FindWindow(nil,'Form1');
      Windows.BringWindowToTop(H1) ;//设为当前活动的窗体
      FStrings := TStringList.Create;
      if EnumChildWindows(H1,@MyEnumChild,110) then //当@MyEnumChild为true,继续枚举
      begin
        //ShowMessage('Successed');
        for i:=0 to FStrings.Count-1 do
        begin
          if pos('TextBox',fstrings[i])>0 then
          begin
            strH:=strtoint(copy(fstrings[i],1,pos('*',fstrings[i])-2));
            SendMessage(strH, WM_char, ord('s'), $00380001);
            sendMessage(strH, WM_char, ord('e'), $00380001);
            sendMessage(strH, WM_char, ord('3'), $00380001);
            sendMessage(strH, WM_char, ord('8'), $00380001);
            SendMessage(strH, WM_KEYDown, 13, 0); //13 VK_RETURN
          end;
        end;
      end;
      FStrings.Free;
    end;