资源描述:
《getwindowthreadprocessid函数使用方法》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、GetWindowThreadProcessId函数使用方法GetWindowThreadProcessId获得窗口所在进程ID和线程ID在得到窗口句柄后我们可以通过GetWindowThreadProcessId这个函数来获得窗口所属进程ID和线程ID,从而判断创建窗口的进程和线程。函数原型:DWORDGetWindowThreadProcessId(HWNDhWnd,LPDWORDlpdwProcessId);参数说明:hWnd:传入的窗口句柄;lpdwProcessId:返回的进程ID地址。返回值:函数返回的是窗口所属线程ID。使用例子:DW
2、ORDProcessID;DWORDThreadID;ThreadID=GetWindowThreadProcessId(hWnd,&ProcessID);---------------------------------------------------------------------------------一、VC--------------------------------------------------------------------------------TheGetWindowThreadProcessIdfunctio
3、nretrievestheidentifierofthethreadthatcreatedthespecifiedwindowand,optionally,theidentifieroftheprocessthatcreatedthewindow.意译:找出某个窗口的创建者(线程或进程),返回创建者的标志符。哪个线程创建了这个窗口,返回的就是这个线程的id号(进程只有一个线程的话,那么线程标志符与进程标志符就是指同一个标志符)可理解为找出某栋房屋的建筑工人的名字。1.函数原型DWORDGetWindowThreadProcessId(HWNDhWn
4、d,LPDWORDlpdwProcessId);2.参数hWnd[in](向函数提供的)被查找窗口的句柄.lpdwProcessId[out]答案的存放地址(变量地址)Pointertoavariablethatreceivestheprocessidentifier.IfthisparameterisnotNULL,GetWindowThreadProcessIdcopiestheidentifieroftheprocesstothevariable;otherwise,itdoesnot.(如果参数不为NULL,即提供了存放处--变量,那么本函
5、数把进程标志拷贝到存放处,否则不动作。)3.返回值Thereturnvalueistheidentifierofthethreadthatcreatedthewindow.返回创建者的标志,注意,lpdwProcessId是存放创建者标志的变量。即,返回值是答案,lpdwProcessId是答案存放处。当然可以把答案再放到其它地方。如DWORDPID;PID=GetWindowThreadProcessId(hWnd,lpdwProcessId);4.函数相关信息HeaderDeclaredinWinuser.h,includeWindows.hI
6、mportlibraryUser32.libMinimumoperatingsystemsWindows95,WindowsNT3.1[]二、VB声明DeclareFunctionGetWindowThreadProcessIdLib"user32"Alias"GetWindowThreadProcessId"(ByValhwndAsLong,lpdwProcessIdAsLong)AsLong1、说明TheGetWindowThreadProcessIdfunctionretrievestheidentifierofthethreadthatcr
7、eatedthespecifiedwindowand,optionally,theidentifieroftheprocessthatcreatedthewindow这个函数获得指定线程的标识符,此线程创建了指定的窗口,并且随机的产生了这个标识符.2、返回值Long,拥有窗口的线程的标识符3、参数表参数类型及说明lpdwProcessIdLong,指定一个变量,用于装载拥有那个窗口的一个进程的标识符hwndLong,指定窗口句柄delphi实例:vart:thandle;begint:=findwindow('Notepad2',nil);show
8、message(inttostr(t));memo1.lines.Add(inttostr(GetWindowThread