阅读背景:

如何获得字符串的价值?

来源:互联网 
{ *
  * AControl: Control handle determined by Spy++ (e.g. 0037064A)
  * ANewText: Text to assign to control
  * AWinTitle: Window Title/Caption
  * }
function ControlSetText(const AControl, ANewText, AWinTitle: string): boolean;
  function EnumChildren(AWindowHandle: HWND; ALParam: lParam): bool; stdcall;
  begin
    ShowMessage(AControl); // if commented out - code works fine
    TStrings(ALParam).Add(IntToStr(GetDlgCtrlID(AWindowHandle)));
    Result := true;
  end;

var
  _MainWindowHandle: HWND;
  _WindowControlList: TStringlist;
  i: integer;
  _ControlHandle: integer;
begin
  Result := false;
  _MainWindowHandle := FindWindow(nil, PWideChar(AWinTitle));
  if _MainWindowHandle <> 0 then
  begin
    _WindowControlList := TStringlist.Create;
    try
      if TryStrToInt('$' + Trim(AControl), _ControlHandle) then
        try
          EnumChildWindows(_MainWindowHandle, @EnumChildren,
            UINT_PTR(_WindowControlList));
          for i := 0 to _WindowControlList.Count - 1 do
          begin
            if (StrToInt(_WindowControlList[i]) = _ControlHandle)
            then
            begin
              SendMessage(StrToInt(_WindowControlList[i]), WM_SETTEXT, 0,
                integer(PCHAR(ANewText)));
              Result := true;
            end;
          end;
        except
          on E: Exception do
            MessageDlg(E.Message, TMsgDlgType.mtError, [TMsgDlgBtn.mbOK], 0)
        end;
    finally
      FreeAndNil(_WindowControlList);
    end;
  end;
end;
{ *
  * AControl: Control handle determined by 



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: