首页
社区
课程
招聘
[求助]如何获取进程id?
发表于: 2009-2-23 12:21 11041

[求助]如何获取进程id?

2009-2-23 12:21
11041
收藏
免费 0
支持
分享
最新回复 (2)
雪    币: 130
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
用到两个API函数“FindWindow”,“GetWindowThreadProcessId”。

The FindWindow function retrieves a handle to the top-level window whose class name and window name match the specified strings. This function does not search child windows. This function does not perform a case-sensitive search.

To search child windows, beginning with a specified child window, use the FindWindowEx function.


Syntax

HWND FindWindow( LPCTSTR lpClassName,
LPCTSTR lpWindowName
);
Parameters

lpClassName
[in] Pointer to a null-terminated string that specifies the class name or a class atom created by a previous call to the RegisterClass or RegisterClassEx function. The atom must be in the low-order word of lpClassName; the high-order word must be zero.
If lpClassName points to a string, it specifies the window class name. The class name can be any name registered with RegisterClass or RegisterClassEx, or any of the predefined control-class names.

If lpClassName is NULL, it finds any window whose title matches the lpWindowName parameter.

lpWindowName
[in] Pointer to a null-terminated string that specifies the window name (the window's title). If this parameter is NULL, all window names match.
Return Value

If the function succeeds, the return value is a handle to the window that has the specified class name and window name.

If the function fails, the return value is NULL. To get extended error information, call GetLastError.



The GetWindowThreadProcessId function retrieves the identifier of the thread that created the specified window and, optionally, the identifier of the process that created the window.

Syntax

DWORD GetWindowThreadProcessId( HWND hWnd,
LPDWORD lpdwProcessId
);
Parameters

hWnd
[in] Handle to the window.
lpdwProcessId
[out] Pointer to a variable that receives the process identifier. If this parameter is not NULL, GetWindowThreadProcessId copies the identifier of the process to the variable; otherwise, it does not.
Return Value

The return value is the identifier of the thread that created the window.



Delphi代码:

var
  thwnd :Thandle ;   //声明变量 窗口句柄
  pid:Thandle;      //进程句柄

begin
     thWnd := FindWindow(nil,'*****'); //得窗口句柄。
   GetWindowThreadProcessId(thwnd,@pid);//得进程ID放到pid变量。
end;
2009-2-23 20:42
0
雪    币: 185
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
已经解决了,呵呵.
2009-2-24 09:06
0
游客
登录 | 注册 方可回帖
返回