获得另一个程序一批Edit中的文字,再将其修改后顺序写回(100)(100分)

  • 主题发起人 proudjia
  • 开始时间
P

proudjia

Unregistered / Unconfirmed
GUEST, unregistred user!
<br>function EnumChildWindowsProc(hwnd: Integer; lparam: Longint): Boolean; stdcall;<br>//得到窗口(是一个MDIChild类型)中每个控件的 Text 内容(TEdit,TMaskEdit...),成功了。<br>var<br>&nbsp; buffer: array[0..255] of char;<br>&nbsp; s: string;<br>begin<br>&nbsp; Result := True;<br>&nbsp; GetClassName(hwnd, buffer, 256);<br>&nbsp; s := STRPAS(BUFFER);<br>&nbsp; if ((s &lt;&gt; 'TStaticText') and (s &lt;&gt; 'TGroupBox') and (s &lt;&gt; 'TPanel') and (s &lt;&gt; 'TStatusBar') and (s &lt;&gt; 'TButton')<br>&nbsp; &nbsp; &nbsp; &nbsp;and (s &lt;&gt; 'TBitBtn') and (s &lt;&gt; 'MDIClient') and (s &lt;&gt; 'TWjfDBGrid')) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; form1.ListBox2.Items.Add(inttostr(hwnd) + ' &nbsp;' + StrPas(Buffer));<br>&nbsp; &nbsp; &nbsp; SetLength(s, 256);<br>&nbsp; &nbsp; &nbsp; SendMessage(hwnd, WM_GETTEXT, 256, LongInt(S));<br>&nbsp; &nbsp; &nbsp; form1.ListBox1.Items.Add(S);<br>&nbsp; &nbsp; end;<br>end;<br><br>function EnumChildWindowsSendDJSW(hwnd: Integer; lparam: Longint): Boolean; stdcall;<br>//想法是把 ListBox2 中的文字再按读出时的顺序写回,虽然我注意了一下这一过程中没个控件也是按上面<br>//的顺序遍历的(hwnd的出现顺序完全同上),但执行完了字符却没写回到相应的地方,哪里有问题吗?<br>//是因为 MDI 子窗口?还是不能在回调函数中写 SendMessage ?还是方法不对?还是。。。其他原因?<br>var<br>&nbsp; buffer: array[0..255] of char;<br>&nbsp; s: string;<br>begin<br>&nbsp; Result := True;<br>&nbsp; GetClassName(hwnd, buffer, 256);<br>&nbsp; s := STRPAS(BUFFER);<br>&nbsp; if ((s &lt;&gt; 'TStaticText') and (s &lt;&gt; 'TGroupBox') and (s &lt;&gt; 'TPanel') and (s &lt;&gt; 'TStatusBar') and (s &lt;&gt; 'TButton')<br>&nbsp; &nbsp; &nbsp; &nbsp;and (s &lt;&gt; 'TBitBtn') and (s &lt;&gt; 'MDIClient') and (s &lt;&gt; 'TDjwjfFMnzqy1') and (s &lt;&gt; 'TWjfDBGrid')) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; i := i + 1;<br>&nbsp; &nbsp; &nbsp; SendMessage(hwnd,WM_SETTEXT,0,LongInt(PChar(form1.ListBox2.Items.Strings[form1.ListBox3.Items.count - i])));<br>&nbsp; &nbsp; end;<br>end;<br><br>//下面是得到所有编辑控件中的字符。<br>&nbsp; hwnd := FindWindow('&lt;另外一个别人写的程序(Delphi)&gt;', nil);<br>&nbsp; if hwnd &lt;&gt; 0 then<br>&nbsp; &nbsp; &nbsp; EnumChildWindows(hwnd, @EnumChildWindowsProc, Integer(@buffer[0]));<br><br>//下面是想把字符再写回去<br>&nbsp; hwnd := FindWindow('&lt;另外一个别人写的程序(Delphi)&gt;', nil);<br>&nbsp; if hwnd &lt;&gt; 0 then<br>&nbsp; &nbsp; &nbsp; EnumChildWindows(hwnd, @EnumChildWindowsSend, Integer(@buffer[0]));<br><br><br>也看过以前各位高手提供的解决方法,但一般例程仅解决一个窗口上放一个EDIT控件的,我这里的上面有60几个Edit呢,<br>怎么解决顺序的问题呢???(其实我现在就是顺序不对了,获得和写回功能都行了,仅仅是顺序问题)
 
Windows枚举时不一定是按照顺序来的,我想你也许可以在第一次枚举时就把对应的Hwnd存下来,<br>然后写值回去的时候,就不要再去枚举了,不知这样行不行,另外在取得Hwnd后是否可以获得<br>实例名了.<br>注:是我来骗分了要我来骗分的.
 
老大,我对着一个Edit的handle发SETTEXT消息他也不把字写到这个Edit里[:(]<br>而且窗口一关,下次再创建就不是原来的handle号了。[:(]<br>我想不出方法通过handle来得到一个东西的name[:(][:(]<br><br>再回答我一次我就上分了 ^_^
 
老大,我对着一个Edit的handle发SETTEXT消息他也不把字写到这个Edit里[:(]<br>而且窗口一关,下次再创建就不是原来的handle号了。[:(]<br>我想不出方法通过handle来得到一个东西的name[:(][:(]<br><br>再回答我一次我就上分了 ^_^
 
是在DELPHI 嗎,為何不這樣寫利用VCL超強功勞<br>name:tstringlist; //記錄沒個控件的name<br>.....<br>var<br>&nbsp; i:integer;<br>&nbsp; s:Tcomponent;<br>begin<br>&nbsp; name:=stringlist.create;<br>&nbsp; for i:=0 to form1.ComponentCount-1 do<br>&nbsp; begin<br>&nbsp; &nbsp; &nbsp;s:=form1.components;<br>&nbsp; &nbsp; &nbsp;if (s is Tedit) or (s is tmaskedit) or () .... then<br>&nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp;listbox.items.add(s.text);<br>&nbsp; &nbsp; &nbsp; &nbsp;name.add(s.name) //<br>&nbsp; &nbsp; &nbsp;end<br>&nbsp; end<br><br>....<br>寫回去時候可以根據記錄下的name判斷....<br>就不用說了吧!<br>
 
没有啊,我把你的代码稍微改了一下,成功了啊,要不你把你的调试程序发给我,我帮你调一<br>下.heavenghost2k@hotmail.com<br>在我这儿每次枚举出来的顺序是完全一样的.
 
我已经完全成功了,你留个信箱,我发我的调试代码发给你.
 
To Jhdandcl<br>先谢了。用繁体字。。。。。。是“海龟派”吗 ^_^<br>我说的另一个程序是别人用DELPHI写的,我并没有源码,所以没办法用你的方法了。<br><br>To proman<br>等你的代码来了我再试试,估计是找到原因了。<br><br>上分!
 
To Jhdandcl<br>先谢了。用繁体字。。。。。。是“海龟派”吗 ^_^<br>我说的另一个程序是别人用DELPHI写的,我并没有源码,所以没办法用你的方法了。<br><br>To proman<br>等你的代码来了我再试试,估计是找到原因了。<br>可能是我 FindWindow 时因为有 MDI 原因没有找的足够深,因而写回时就会顺序乱了。<br><br>上分!<br>
 
多人接受答案了。
 
顶部