当windows应用程序运行时,如何得到它的名称?(100分)

  • 主题发起人 主题发起人 chen___ye
  • 开始时间 开始时间
C

chen___ye

Unregistered / Unconfirmed
GUEST, unregistred user!
急急急!
 
可以使用GetWindowText得到制定HWND的Window Text,之间可能使用FindWindow函数。<br>相关应用可以参看帮助。<br>
 
或者使用WM_GETTEXT消息,当然也要用到FindWindow
 
同意楼上。
 
能说的具体点么?
 
如果你还不知道窗体的Name,那么就用EnumWindows把他们列出来判断。
 
用FindWindow
 
对,我就是这个意思我想将所有在任务栏上的应用程序列出来,刚才我看了EnumWindows的<br>函数,但还是不知道怎么用,赐教
 
代码:
<br>function GetText(Wnd : HWND) : string;<br>var<br>&nbsp; &nbsp; textlength : integer;<br>&nbsp; &nbsp; text : String;<br>begin<br>&nbsp; &nbsp; textlength:=SendMessage(Wnd,WM_GETTEXTLENGTH,0,0);<br>&nbsp; &nbsp; if textlength=0 then<br>&nbsp; &nbsp; &nbsp; Result := ''<br>&nbsp; &nbsp; else begin<br>&nbsp; &nbsp; &nbsp; SetLength(text, textlength+1) ;<br>&nbsp; &nbsp; &nbsp; SendMessage(Wnd,WM_GETTEXT,textlength+1,PChar(text));<br>&nbsp; &nbsp; &nbsp; Result:=text;<br>&nbsp; &nbsp; end;<br>end;<br><br>function EnumWindowsProc (Wnd: HWND; LParam: LPARAM): BOOL; stdcall;<br>var<br>&nbsp; &nbsp; s : String ;<br>begin<br>&nbsp; &nbsp; Result := True;<br>&nbsp; &nbsp; if (IsWindowVisible(Wnd)) and (GetWindowLong(Wnd, GWL_HWNDPARENT) = 0) and (GetWindowLong(Wnd, GWL_EXSTYLE) and WS_EX_TOOLWINDOW = 0) then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; s := ''+Inttostr(Wnd)+', '+ GetText(Wnd) ;<br>&nbsp; &nbsp; &nbsp; &nbsp; Form1.Listbox1.items.add(s);<br>&nbsp; &nbsp; end;<br>end; &nbsp; <br><br>procedure TForm1.BtnRefreshClick(Sender: TObject);<br>var<br>&nbsp; &nbsp; Param : Longint;<br>begin<br>&nbsp; &nbsp; Param := 0 ;<br>&nbsp; &nbsp; EnumWindows(@EnumWindowsProc , Param);<br>end;<br>
<br>典型的回调函数示例,<br>手头有这段,就拷贝给你了,注意:代码加了判断条件,专门用于Taskbar任务栏的窗口类<br>句柄,并不是枚举所有窗口,不然会看傻掉的。
 
真不好意思,我运行了一下程序,发现<br>SendMessage(Wnd,WM_GETTEXT,textlength+1,PChar(text));中的PChar(text)是不符合类型的<br>并且text也没有赋值,怎么回事?<br>赐教
 
function GetText(Wnd : HWND) : string;<br>var<br>&nbsp; &nbsp; textlength : integer;<br>&nbsp; &nbsp; text : PChar;<br>begin<br>&nbsp; &nbsp; textlength:=SendMessage(Wnd,WM_GETTEXTLENGTH,0,0);<br>&nbsp; &nbsp; if textlength=0 then<br> &nbsp; &nbsp;Result := ''<br>&nbsp; &nbsp; else begin<br>&nbsp; &nbsp; &nbsp; &nbsp; getmem(text,textlength+1);<br>&nbsp; &nbsp; &nbsp; &nbsp; SendMessage(Wnd,WM_GETTEXT,textlength+1,Integer(text));<br>&nbsp; &nbsp; &nbsp; &nbsp; Result:=text;<br>&nbsp; &nbsp; &nbsp; &nbsp; freemem(text);<br>&nbsp; &nbsp; end;<br>end;
 
好了,太谢谢你了,我也明白了,分数全给你!
 
后退
顶部