findwindow 百科内容来自于: 百度百科

简述

FindWindow这个函数检索处理顶级窗口的类名和窗口名称匹配指定的字符串。这个函数不搜索子窗口.lpClassName参数指向类名,lpWindowName指向窗口名,如果有指定的类名和窗口的名字则表示成功返回一个窗口的句柄。否则返回零。
Fin dWindow,
LPCTSTR lpClassName, // pointer to class name
LPCTSTR lpWindowName // pointer to window name
);
HWND hWnd, // handle of window
LPDWORD lpdwProcessId // address of variable for process identifier
);
DWORD dwDesiredAccess, // access flag
BOOL bInheritHandle, // handle inheritance flag
DWORD dwProcessId // process identifier
);
HANDLE hProcess, // handle to process whose memory is written to
LPVOID lpBaseAddress, // address to start writing to
LPVOID lpBuffer, // pointer to buffer to write data to
DWORD nSize, // number of bytes to write
LPDWORD lpNumberOfBytesWritten // actual number of bytes written
);
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);
if hw = 0 then
Exit;
GetWindowThreadProcessId(hw, @pid);
h := OpenProcess(PROCESS_ALL_ACCESS, false, pid);
if h = 0 then
Exit;
if flatcheckbox1.Checked=true then
begin
WriteProcessMemory(h, Pointer(ResourceOffset), @Resource, sizeof(Resource), tt);
WriteProcessMemory(h, Pointer(ResourceOffset1), @Resource1, sizeof(Resource1), tt);
end;
if flatcheckbox2.Checked=true then
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;
CloseHandle(h);
close

函数原型

HWND FindWindow
(
LPCSTR lpClassName,
LPCSTR lpWindowName
);

参数表

lpClassName
指向一个以null结尾的、用来指定类名的字符串或一个可以确定类名字符串的原子。如果这个参数是一个原子,那么它必须是一个在调用此函数前已经通过 GlobalAddAtom函数创建好的全局原子。这个原子(一个16bit的值),必须被放置在lpClassName的低位字节中,lpClassName的高位字节置零。
如果该参数为null时,将会寻找任何与lpWindowName参数匹配的窗口。
lpWindowName
指向一个以null结尾的、用来指定窗口名(即窗口标题)的字符串。如果此参数为NULL,则匹配所有窗口名。

返回值

如果函数执行成功,则返回值是拥有指定窗口类名或窗口名的窗口的句柄。
如果函数执行失败,则返回值为 NULL 。可以通过调用 GetLastError函数获得更加详细的错误信息

C#中

导入库:user32.lib
头文件:winuser.h
***.Net 中运用
命名空间 using System.Runtime.InteropServices;
导入库 [DllImport("user32.dll")]
函数原型 public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
参数说明 lpClassName String,指向包含了窗口类名的空中止(C语言)字串的指针;或设为零,表示接收任何类
lpWindowName String,指向包含了窗口文本(或标签)的空中止(C语言)字串的指针;或设为零,表示接收 任何窗口标题
返回值 :句柄

C++中

头文件:afxwin.h
例子:
// activate an application with a window with a specific class name
BOOL CMyApp::FirstInstance()
{
CWnd *pWndPrev, *pWndChild;
// Determine if a window with the class name exists...
pWndPrev = CWnd::FindWindow(_T("MyNewClass"), NULL);
if(NULL != pWndPrev)
{
// If so, does it have any popups?
pWndChild = pWndPrev->GetLastActivePopup();
// If iconic, restore the main window
if(pWndPrev->IsIconic())
pWndPrev->ShowWindow(SW_RESTORE);
// Bring the main window or its popup to the foreground
pWndChild->SetForegroundWindow();
// and you are done activating the other application
returnFALSE;
}
returnTRUE;
}

声明

VB6.0中的声明:
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
FINDWINDOWS Delphi简单例子:
var
t:thandle;
begin
t:=findwindow(nil,'计算器'); //运行windows计算器,获取计算器的句柄
showmessage(inttostr(t));
end;
易语言中的声明:
.版本 2
.DLL命令 FindWindow, 整数型, "user32.dll", "FindWindowA"
.参数 类名, 文本型
.参数 标题, 文本型
$firstVoiceSent
- 来自原声例句
小调查
请问您想要如何调整此模块?

感谢您的反馈,我们会尽快进行适当修改!
进来说说原因吧 确定
小调查
请问您想要如何调整此模块?

感谢您的反馈,我们会尽快进行适当修改!
进来说说原因吧 确定