根據視窗控制代碼獲取所在程式路徑

2021-06-07 23:16:56 字數 889 閱讀 7528

var

form1: tform1;

implementation

uses psapi;

function getproces***epath(h: hwnd): string;

varpid: cardinal;

phandle: thandle;

buf: array[0..max_path] of char;

begin

getwindowthreadprocessid(h, @pid);

phandle := openprocess(process_all_access, false, pid);

getmodulefilenameex(phandle, 0, buf, length(buf));

closehandle(phandle);

result := buf;

end;

procedure tform1.button1click(sender: tobject);

varpath: string;

begin

path := getproces***epath(handle);

showmessage(path);

end;

procedure tform1.button2click(sender: tobject);

varwh: hwnd;

path: string;

begin

wh := findwindow('notepad', nil);

path := getproces***epath(wh);

showmessage(path);

end;

end.

獲取視窗控制代碼

在windows中,控制代碼是乙個系統內部資料結構的引用。例如當你操作乙個視窗,或說是乙個delphi窗體時,系統會給你乙個該視窗的控制代碼,系統會通知你 你正在操作142號視窗,就此你的應用程式就能要求系統對 142號視窗進行操作 移動視窗 改變視窗大小 把視窗最小化等等。實際上許多windows...

獲取視窗控制代碼

afxgetmainwnd afxgetmainwnd獲取自身視窗控制代碼 hwnd hwnd afxgetmainwnd m hwnd gettopwindow 函式功能 該函式檢查與特定父視窗相聯的子視窗z序 z序 垂直螢幕的方向,即疊放次序 並返回在z序頂部的子視窗的控制代碼。函式原型 hwn...

MFC 視窗控制代碼獲取

控制代碼獲取方法 獲取該視窗的控制代碼後,即可向該視窗類類傳送訊息 處理程式 0。獲取所在類視窗的控制代碼 this m hwnd 1。主視窗的控制代碼 無論在主視窗類內,還是子視窗類內,獲取主視窗控制代碼的方法 afxgetmainwnd m hwnd,如 sendmessage afxgetma...