屏幕取词!!!!!!!!!(200分)

  • 主题发起人 主题发起人 sdafth46
  • 开始时间 开始时间
S

sdafth46

Unregistered / Unconfirmed
GUEST, unregistred user!
屏幕取词!!!!!!!!!
 
GetWindowText
 
楼上的弟兄说的太简单了吧!!!<br>
 
抄cAkk的<br>1、添加form,在上面添加一个richedit,名字叫rich1<br>2、在form的onload事件中往rich1里面随便添加一段文字做测试用:<br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>&nbsp; rich1.Lines.Add('cAkk is a good boy');<br>end;<br><br>3、定义rich1的onmousemove事件:<br>procedure TForm1.rich1MouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer);<br>var txt:String;<br>begin<br>&nbsp; txt:= RichWordOver(rich1, X, Y);<br>&nbsp; //截词结果显示在form的caption上<br>&nbsp; If Caption &lt;&gt; txt Then<br>&nbsp; &nbsp; &nbsp;Caption:= txt;<br>end;<br><br>4、定义函数RichWordOver<br><br>Function TForm1.RichWordOver(rch:trichedit; X,Y:integer):string;<br>var pt:tpoint;<br>&nbsp; &nbsp; pos,<br>&nbsp; &nbsp; start_pos,<br>&nbsp; &nbsp; end_pos:Integer;<br>&nbsp; &nbsp; ch,txt:String;<br>&nbsp; &nbsp; txtlen:Integer;<br>begin<br><br>&nbsp; &nbsp; pt.X:= X;<br>&nbsp; &nbsp; pt.Y:= Y;<br>&nbsp; &nbsp; pos:=rch.Perform(EM_CHARFROMPOS, 0, longint(@pt));<br>&nbsp; &nbsp; If pos &lt;= 0 Then Exit;<br>&nbsp; &nbsp; txt:= rch.Text;<br>&nbsp; &nbsp; For start_pos:= pos downTo 1 do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; ch:=copy(rch.text,start_pos, 1);<br>&nbsp; &nbsp; &nbsp; &nbsp; If Not (<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ( (ch &gt;= '0') And (ch &lt;= '9') ) Or<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ( (ch &gt;= 'a') And (ch &lt;= 'z') ) Or<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ( (ch &gt;= 'A') And (ch &lt;= 'Z') ) Or<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (ch = '_')<br>&nbsp; &nbsp; &nbsp; &nbsp; ) Then break;<br>&nbsp; &nbsp; end;<br><br>&nbsp; &nbsp; inc(start_pos);<br><br>&nbsp; &nbsp; txtlen:= Length(txt);<br>&nbsp; &nbsp; For end_pos:= pos To txtlen do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; ch:= copy(txt, end_pos, 1);<br>&nbsp; &nbsp; &nbsp; &nbsp; If Not (<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ( (ch &gt;= '0') And (ch &lt;= '9') ) Or<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ( (ch &gt;= 'a') And (ch &lt;= 'z') ) Or<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ( (ch &gt;= 'A') And (ch &lt;= 'Z') ) Or<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (ch = '_')<br>&nbsp; &nbsp; &nbsp; &nbsp; ) Then break;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; dec(end_pos);<br><br>&nbsp; &nbsp; If start_pos &lt;= end_pos Then<br>&nbsp; &nbsp; &nbsp; &nbsp; result:=copy(txt, start_pos, end_pos - start_pos + 1);<br>End;<br>
 
接受答案了.
 
屏幕取词的完整解决方案见我的《delphi深入windows核心编程》一书,<br>解决了IE、win98下的高技术难题,支持windows98/2000/xp,<br>我的主页http://wenjinshan.yeah.net
 
楼上的就不要作广告了.你不觉的很烦么<br>
 
后退
顶部