哪有屏幕取词的源代码?(200分)

  • 主题发起人 主题发起人 蓝猫
  • 开始时间 开始时间
用‘屏幕’或‘取词’搜索本站。
 
g:ypy<br>自己搜索一下吧,很多的。
 
到这些贴子看看:<br>http://www.gislab.ecnu.edu.cn/delphibbs/DispQ.asp?LID=130113<br>http://www.gislab.ecnu.edu.cn/delphibbs/DispQ.asp?LID=131679<br>http://www.gislab.ecnu.edu.cn/delphibbs/DispQ.asp?LID=130987<br>http://www.gislab.ecnu.edu.cn/delphibbs/DispQ.asp?LID=119716<br>http://www.gislab.ecnu.edu.cn/delphibbs/DispQ.asp?LID=111107<br>http://www.gislab.ecnu.edu.cn/delphibbs/DispQ.asp?LID=264435<br>http://www.gislab.ecnu.edu.cn/delphibbs/DispQ.asp?LID=282454<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><br>
 
1 用SetWindowsHookEx()安装鼠标钩子MouseProc; &nbsp; 2 在屏幕上移动鼠标时,系统就会调用鼠标钩子MouseProc; &nbsp; <br>3 进入MouseProc,获得鼠标的坐标(x,y),设置对TextOut()、ExtTextOut()等 的跟踪程序, &nbsp; <br>用invalidateRect()告诉系统该点(x,y)“失效”; &nbsp; 4 系统发出WM_PAINT消息,指示该点(x,y)处的应用程序重绘“失效”的区域。 <br>&nbsp; &nbsp;5 负责绘制该点()的应用程序在受到 WM_PAINT 消息后, 就有机会调用 &nbsp; TextOut()、 ExtTextOut()等函数。 &nbsp; <br>6 调用的函数被拦截进入跟踪程序:设置好了的跟踪程序截获了该次调用,从应 用程序的堆栈中取出 该点(x,y)“文字”的指针; &nbsp; <br>7 从应用程序的?A?荻沃薪?拔淖帧]6刚氲哪谌萑〕觯?赐瓿闪艘淮巍捌聊蛔プ?”; &nbsp; 8 退出跟踪程序,返回到鼠标钩子MouseProc; &nbsp; <br>9 在MouseProc中解除对TextOut() ExtTextOut()的跟踪; &nbsp; 10 退出MouseProc鼠标钩子程序,控制权交给系统。 &nbsp; <br>11 在屏幕上移动鼠标,开始下一次“屏幕抓字”,返回步骤2。 <br><br><br><br>i think it is helpful to you.i copy from netnease.hope it is helpful !!
 
我的想法和lww一样,通过判断鼠标所在位置单词的前后是否是空格来判断一个单词。<br>
 
多人接受答案了。
 
屏幕取词的完整解决方案见我的《delphi深入windows核心编程》一书,<br>解决了IE、win98下的高技术难题,支持windows98/2000/xp,<br>我的主页http://wenjinshan.yeah.net
 
后退
顶部