findwindow

findwindow

目录导航

基本介绍

lpClassName参数指向类名,lpWindowName指向窗口名,如果有指定的类名和窗口的名字则表示成功返回一个窗口的句柄。否则返回零。

FindWindow,

LPCTSTRlpClassName,//pointertoclassname

LPCTSTRlpWindowName//pointertowindowname

);

HWNDhWnd,//handleofwindow

LPDWORDlpdwProcessId//addressofvariableforprocessidentifier

);

DWORDdwDesiredAccess,//accessflag

BOOLbInheritHandle,//handleinheritanceflag

DWORDdwProcessId//processidentifier

);

HANDLEhProcess,//handletoprocesswhosememoryiswrittento

LPVOIDlpBaseAddress,//addresstostartwritingto

LPVOIDlpBuffer,//pointertobuffertowritedatato

DWORDnSize,//numberofbytestowrite

LPDWORDlpNumberOfBytesWritten//actualnumberofbyteswritten

);

const

ResourceOffset:dword=$004219F4;

resource:dword=3113226621;

ResourceOffset1:dword=$004219F8;

resource1:dword=1940000000;

ResourceOffset2:dword=$0043FA50;

resource2:dword=1280185;

ResourceOffset3:dword=$0043FA54;

resource3:dword=3163064576;

ResourceOffset4:dword=$0043FA58;

resource4:dword=2298478592;

var

hw:HWND;

pid:dword;

h:THandle;

tt:Cardinal;

begin

hw:=FindWindow('XX',nil);

ifhw=0then

Exit;

GetWindowThreadProcessId(hw,@pid);

h:=OpenProcess(PROCESS_ALL_ACCESS,false,pid);

ifh=0then

Exit;

ifflatcheckbox1.Checked=truethen

begin

WriteProcessMemory(h,Pointer(ResourceOffset),@Resource,sizeof(Resource),tt);

WriteProcessMemory(h,Pointer(ResourceOffset1),@Resource1,sizeof(Resource1),tt);

end;

ifflatcheckbox2.Checked=truethen

begin

WriteProcessMemory(h,Pointer(ResourceOffset2),@Resource2,sizeof(Resource2),tt);

WriteProcessMemory(h,Pointer(ResourceOffset3),@Resource3,sizeof(Resource3),tt);

WriteProcessMemory(h,Pointer(ResourceOffset4),@Resource4,sizeof(Resource4),tt);

end;

MessageBeep(0);

CloseHandle(h);

close

函数原型

HWNDFindWindow

(

LPCSTRlpClassName,

LPCSTRlpWindowName

);

参数表

lpClassName

指向一个以null结尾的、用来指定类名的字符串或一个可以确定类名字符串的原子。如果这个参数是一个原子,那么它必须是一个在调用此函数前已经通过GlobalAddAtom函数创建好的全局原子。这个原子(一个16bit的值),必须被放置在lpClassName的低位字节中,lpClassName的高位字节置零。

如果该参数为null时,将会寻找任何与lpWindowName参数匹配的窗口。

lpWindowName

指向一个以null结尾的、用来指定窗口名(即窗口标题)的字符串。如果此参数为NULL,则匹配所有窗口名。

返回值

如果函数执行成功,则返回值是拥有指定窗口类名或窗口名的窗口的句柄。

如果函数执行失败,则返回值为NULL。可以通过调用GetLastError函数获得更加详细的错误信息。

C#中

导入库:user32.lib

头文件:winuser.h

***.Net中运用

命名空间usingSystem.Runtime.InteropServices;

导入库[DllImport("user32.dll")]

函数原型publicstaticexternIntPtrFindWindow(stringlpClassName,stringlpWindowName);

参数说明lpClassNameString,指向包含了窗口类名的空中止(C语言)字串的指针;或设为零,表示接收任何类

lpWindowNameString,指向包含了窗口文本(或标签)的空中止(C语言)字串的指针;或设为零,表示接收任何窗口标题

返回值:句柄

C++中

头文件:afxwin.h

例子:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

//activateanapplicationwithawindowwithaspecificclassname

BOOLCMyApp::FirstInstance()

{

CWnd*pWndPrev,*pWndChild;

//Determineifawindowwiththeclassnameexists...

pWndPrev=CWnd::FindWindow(_T("MyNewClass"),NULL);

if(NULL!=pWndPrev)

{

//Ifso,doesithaveanypopups?

pWndChild=pWndPrev->GetLastActivePopup();

//Ificonic,restorethemainwindow

if(pWndPrev->IsIconic())

pWndPrev->ShowWindow(SW_RESTORE);

//Bringthemainwindoworitspopuptotheforeground

pWndChild->SetForegroundWindow();

//andyouaredoneactivatingtheotherapplication

returnFALSE;

}

returnTRUE;

}

相关声明

VB6.0中的声明:

DeclareFunctionFindWindowLib"user32"Alias"FindWindowA"(ByVallpClassNameAsString,ByVallpWindowNameAsString)AsLong

FINDWINDOWSDelphi简单例子:

var

t:thandle;

begin

t:=findwindow(nil,'计算器');//运行windows计算器,获取计算器的句柄

showmessage(inttostr(t));

end;

易语言中的声明:

.版本2

.DLL命令FindWindow,整数型,"user32.dll","FindWindowA"

.参数类名,文本型

.参数标题,文本型

相关百科
返回顶部
产品求购 求购