zoukankan      html  css  js  c++  java
  • 关于获取其它程序窗口编辑框内容解决思路

    关于获取其它程序窗口编辑框内容
    想通过一个小程序获取一个叫“客户信息”窗口中不为空编辑框的内容
    窗口有四个编辑框,请大家指教。

     


    ------解决方案--------------------
    先获取到编辑框的句柄,可以根据Z序查找到句柄,你用Spy++看下;
    然后用下面的函数获取编辑框里面的内容:

    function GetWndText(ThWnd: hWnd): string;
    var
      Ret:LongInt;
      mText:PChar;
      Buf:Integer;
    begin
      Ret := SendMessage(ThWnd, WM_GETTEXTLENGTH, 0, 0) + 1;
      GetMem(mText,Ret);
      try
        Buf := LongInt(mText);
        SendMessage(ThWnd, WM_GETTEXT, Ret, Buf);
        Result := StrPas(mText);
      finally
        FreeMem(mText,Ret);
      end;
    end;


    ------解决方案--------------------
    既然找到了句柄,直接用api GetWindowText不就得了
    ------解决方案--------------------
    1.FindWindows 先找主窗体
    2.EnumChildWindows 找出所有子窗体
      循环再判一下就成了
    ------解决方案--------------------
    listbox不能这么读啊
    要读内存,用下面的函数:

    uses CommCtrl;


    function TreeNodeGetNext(mHandle: THandle; mTreeItem: HTreeItem): HTreeItem;
    var
      vParentID: HTreeItem;
    begin
      Result := nil;
      if (mHandle <> 0) and (mTreeItem <> nil) then begin
        Result := TreeView_GetChild(mHandle, mTreeItem);
        if Result = nil then
          Result := TreeView_GetNextSibling(mHandle, mTreeItem);
        vParentID := mTreeItem;
        while (Result = nil) and (vParentID <> nil) do begin
          vParentID := TreeView_GetParent(mHandle, vParentID);
          Result := TreeView_GetNextSibling(mHandle, vParentID);
        end;
      end;
    end;

    function TreeView_SelectItem_Ex(hwndTV: HWND; slText: TStringList): Boolean;
    var
      vItemCount: Integer; 
      vBuffer: array[0..255] of Char; 
      vProcessId: DWORD; 
      vProcess: THandle; 
      vPointer: Pointer; 
      vNumberOfBytesRead: Cardinal;
      I: Integer;
      vItem: TTVItem;//uses CommCtrl
      vTreeItem: HTreeItem;
    begin
      Result := False;
      if hwndTV = 0 then exit;
      GetWindowThreadProcessId(hwndTV, @vProcessId); // ?瑕?蝒?餈?ID
      vProcess := OpenProcess(PROCESS_VM_OPERATION or PROCESS_VM_READ or
        PROCESS_VM_WRITE, False, vProcessId);
      if (vProcess = 0) then
        Exit;
      vPointer := VirtualAllocEx(vProcess, nil, 4096, MEM_RESERVE or MEM_COMMIT,
        PAGE_READWRITE);
      if vPointer = nil then exit;
      try
        vItemCount := TreeView_GetCount(hwndTV);
  • 相关阅读:
    教你如何去除电脑QQ聊天窗口上的广告?
    Web 通信技术 ——跨文档信息传输(JavaScript)
    JavaScript中如何给按钮设置隐藏与显示属性
    JavaScript中的innerHTML属性的使用
    JavaScript中点击按钮弹出新的浏览器窗口
    JavaScript中prompt的使用
    考试报名管理系统
    Python——用turtle模块画海龟的第一步
    Cardinality Estimation算法学习(二)(Linear Counting算法、最大似然估计(MLE))
    用KMP算法与Trie字典树实现屏蔽敏感词(UTF-8编码)
  • 原文地址:https://www.cnblogs.com/jijm123/p/6487308.html
Copyright © 2011-2022 走看看