如何获得其他程序中RICHVIEW控件中的文字内容? ( 积分: 100 )

  • 主题发起人 主题发起人 fxb
  • 开始时间 开始时间
F

fxb

Unregistered / Unconfirmed
GUEST, unregistred user!
如何获得其他程序中RICHVIEW控件中的文字内容?并且如何清除其中的内容?<br>(句柄已知)
 
如何获得其他程序中RICHVIEW控件中的文字内容?并且如何清除其中的内容?<br>(句柄已知)
 
已知句柄,取得文字内容可以用GetWindowText,清除内容可以用SetWindowText。<br>function SetWindowText(hWnd: HWND; lpString: PChar): BOOL;<br>function GetWindowText(hWnd: HWND; lpString: PChar; nMaxCount: Integer): Integer;
 
总感觉这种说法不太不太……<br><br>Delphi里面自然就是RichEdit了,VC里面RichView其实一个View,而不是控件,如果是RichEdit,一点废话,<br><br>后面的楼上兄弟很清楚了<br><br>PostMessage(Handle, WM_SETTEXT, 0, Integer(PChar('')))<br><br>或者<br>PostMessage(Handle, EM_SETSEL , 0, 0);// 全选<br>PostMessage(Handle, WM_CLEAR, 0, 0);// 清空<br><br>个人看法,仅供参考
 
如果RichView.Flags中,rvflCanProcessGetText为True,那么可以用WM_SETTEXT,否则就要Hook进入该RichView所在的进程才能想办法做到啦<br>SendMessage(Handle, WM_SETTEXT, 1, Integer(PChar('')));<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ^^^切记[:)]<br>另外,WM_CLEAR清除的是当前选中部分的内容,这里显然是不适用的
 
procedure TCursorOper.Timer1Timer(Sender: TObject);<br>var<br> &nbsp;p:TPoint;<br> &nbsp;hand:hwnd;<br> &nbsp;str:Array[0..255] of char;<br> &nbsp;strclass:Array[0..255] of char;<br>begin<br> &nbsp;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;<br>end;
 
将 RichEdit 内容保存在 lpText 中,然后清空:<br>var<br> &nbsp;lpText: PChar;<br>begin<br> &nbsp;SendMessage(hWndRich, WM_GETTEXT, 255, lpText);//取内容<br> &nbsp;...<br> &nbsp;SendMessage(hWndRich, WM_SETTEXT, 0, ''); //清空<br> &nbsp;...<br>end;
 
后退
顶部