问一个API问题(50分)

  • 主题发起人 主题发起人 yanyandt2
  • 开始时间 开始时间
Y

yanyandt2

Unregistered / Unconfirmed
GUEST, unregistred user!
我通过findwindow获得一个窗口的句柄<br>如果通过句柄得到这个窗口的 window caption?<br>就是 application.title 这个东西<br><br>谢谢!
 
getwindowText<br><br>The GetWindowText function copies the text of the specified window's title bar<br>&nbsp;(if it has one) into a buffer. If the specified window is a control, the text <br>of the control is copied. However, GetWindowText cannot retrieve the text of a <br>control in another application.<br><br>Syntax<br><br>int GetWindowText( &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;HWND hWnd,<br>&nbsp; &nbsp; LPTSTR lpString,<br>&nbsp; &nbsp; int nMaxCount<br>);<br>
 
An application sends a WM_GETTEXT message to copy the text that <br>corresponds to a window into a buffer provided by the caller. <br><br>Syntax<br><br><br>To send this message, call the SendMessage function as follows. <br>lResult = SendMessage( &nbsp; &nbsp; &nbsp;// returns LRESULT in lResult &nbsp; <br>&nbsp; (HWND) hWndControl, &nbsp; &nbsp; &nbsp;// handle to destination control &nbsp; <br>&nbsp; (UINT) WM_GETTEXT, &nbsp; &nbsp; &nbsp;// message ID &nbsp; <br>&nbsp; (WPARAM) wParam, &nbsp; &nbsp; &nbsp;// = (WPARAM) () wParam; &nbsp; <br>&nbsp;(LPARAM) lParam &nbsp; &nbsp; &nbsp;// = (LPARAM) () lParam; ); &nbsp;<br>
 
我是这么写的,可是得不到,为什么?<br>var<br>&nbsp; &nbsp; w_handle:THandle;<br>&nbsp; &nbsp; title:string;<br>begin<br>w_handle:=findwindow(nil,'FlashFxp');<br>if( w_handle&gt;0 ) then<br>begin<br>&nbsp; &nbsp; GetWindowText(w_handle,pchar(title),255);<br>&nbsp; &nbsp; lb.Caption:='find '+string(title);<br>end<br>else<br>&nbsp; &nbsp; lb.Caption:='no find';<br>end;
 
GetWindowText cannot retrieve the text of a control in another application.<br>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br><br>GetWindowText 是不能获得另一个程序的标题的,所以要用<br>sendmessage(handle,WM_GETTEXT ,......)才行
 
hehe,看来pchar也难倒了yanyandt2兄.<br>改用<br>&nbsp; title: array [0..255] of Char;<br>吧.
 
不好意思,疏忽了<br>应该用getmem分配,或者 LeeChange 老兄说的那个<br>赫赫
 
getwindowtext得不到程序的title,<br>pink_wt,给我讲讲sendmessage方法?
 
procedure TForm1.Button1Click(Sender: TObject);<br>var<br>p:pchar;<br>h:hwnd;<br>begin<br>&nbsp; getmem(p,255);<br>&nbsp; h:=findwindow(nil,'计算器');<br>&nbsp; sendmessage(h,WM_GETText,255,integer(p));<br>&nbsp; edit1.text:=string(p);<br>end;
 
多人接受答案了。
 
后退
顶部