如何得到VB程序中一个控件的文字内容? ( 积分: 100 )

  • 主题发起人 主题发起人 lilor
  • 开始时间 开始时间
L

lilor

Unregistered / Unconfirmed
GUEST, unregistred user!
有一个VB编的程序,其界面上有几个Text(或TextBox?)和Label,我想通过Delphi编程得到其中一个Text(或TextBox)的文字内容,请问如何实现?
 
有一个VB编的程序,其界面上有几个Text(或TextBox?)和Label,我想通过Delphi编程得到其中一个Text(或TextBox)的文字内容,请问如何实现?
 
用API应该可以吧~
 
请教如何具体实现?
 
因为TextBox是有句柄的,所以可以通过下面的方法来获得,Label没有句柄,所以要获得它的内容就需要通过象金山词霸那样的方式,请参考http://www.delphibbs.com/delphibbs/dispq.asp?lid=1098331<br><br>procedure TForm11.Button1Click(Sender: TObject);<br>var<br> &nbsp; &nbsp;FormHandle, hText: THandle;<br> &nbsp; &nbsp;strContext : array[0..254] of char;<br> &nbsp; &nbsp;nRet : Integer;<br>begin<br> &nbsp; &nbsp;Memo1.Lines.Clear;<br> &nbsp; &nbsp;Formhandle := FindWindow(nil, PChar('Form1'));<br> &nbsp; &nbsp;if FormHandle = 0 then Exit;<br> &nbsp; &nbsp;hText := FindWindowEx(FormHandle, 0, PChar('ThunderTextBox'), nil);// 这里的这个ThunderTextBox是通过Spy查出来的,其他VB控件类似<br> &nbsp; &nbsp;while hText &gt; 0 do begin<br> &nbsp; &nbsp; &nbsp; &nbsp;nRet := SendMessage(hText, WM_GETTEXT, 255, Integer(@strContext));<br> &nbsp; &nbsp; &nbsp; &nbsp;if nRet &gt; 0 then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Memo1.Lines.Add(strContext);<br> &nbsp; &nbsp; &nbsp; &nbsp;hText := FindWindowEx(FormHandle, hText, PChar('ThunderTextBox'), nil);<br> &nbsp; &nbsp;end;<br>end;
 
我用SPY++只发现以下相关内容<br>|-VBBubleRT6<br>|-ThunderRT6FormDC<br>| |-ThunderRT6PictureBoxDC<br>| |-ThunderRT6PictureBoxDC<br>| &nbsp; |-ThunderRT6Timer<br>| &nbsp; |-ThunderRT6Timer<br>| &nbsp; |-ThunderRT6Timer<br>| &nbsp; |-ThunderRT6Timer<br>|-ThunderRT6Main<br>| |-VBFocusRT6<br>|-VBMsoStdCompMgr<br><br>没有发现其他VB控件
 
timer1.Enabled:=false;<br> &nbsp;GetCursorPos(p);<br> &nbsp;if (p.X&gt;=CursorOper.Left) and (p.X&lt;=CursorOper.Left+CursorOper.Width)<br> &nbsp; &nbsp;and (p.Y&gt;=CursorOper.Top) and (p.Y&lt;=CursorOper.Top+CursorOper.Height) then<br> &nbsp;begin<br> &nbsp; &nbsp;CursorStatus.Panels[0].Text:='在本窗体内';<br> &nbsp;end else<br> &nbsp;begin<br> &nbsp; &nbsp;CursorStatus.Panels[0].Text:='在本窗体外';<br> &nbsp; &nbsp;hand:=WindowFromPoint(p);<br><br> &nbsp; &nbsp;if anEnabled.Checked then EnumChildWindows(hand, @WindowEnabled, 0);<br> &nbsp; &nbsp;if Not anEnabled.Checked then EnumChildWindows(hand, @WindowDisEnabled, 0);<br> &nbsp; &nbsp;if anShow.Checked then EnumChildWindows(hand, @WindowShow, 0);<br> &nbsp; &nbsp;if Not anShow.Checked then EnumChildWindows(hand, @WindowHide, 0);<br><br> &nbsp; &nbsp;getwindowtext(hand,@str,length(str));<br> &nbsp; &nbsp;getclassname(hand,@strclass,length(str));<br> &nbsp; &nbsp;if CheckHand=hand then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;if i&gt;=15 then<br> &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;AddANXinXi(inttostr(hand),str,strclass);<br> &nbsp; &nbsp; &nbsp; &nbsp;i:=0;<br> &nbsp; &nbsp; &nbsp;end else<br> &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;i:=i+1;<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp;end;<br> &nbsp; &nbsp;JuBing.Text:= inttostr(hand);<br> &nbsp; &nbsp;NeiRong.Text:=str;<br> &nbsp; &nbsp;LeiMing.Text:=strclass;<br> &nbsp; &nbsp;ShuBiao_X.Caption:=IntToStr(p.X);<br> &nbsp; &nbsp;ShuBiao_Y.Caption:=IntToStr(p.Y);<br> &nbsp; &nbsp;CheckHand:=hand;<br> &nbsp;end;<br> &nbsp;timer1.Enabled:=true;
 
VB不是很熟悉,我想楼主的意思可能哪个文本不在TextBox里面,那用spy看到的文本在什么控件里面,就按我的代码把那个类名换掉看看,实在不行就用我后面给你的那个地址里面的东西,屏幕取词的方式
 
后退
顶部