FindWindow函数详解

合集下载

findwindow 置顶函数用法 -回复

findwindow 置顶函数用法 -回复

findwindow 置顶函数用法-回复标题:破解Windows程序的“置顶”功能——深入探究findwindow置顶函数用法引言:在Windows操作系统中,置顶(topmost)是一个重要的功能,通常被用于将某个窗口置于其他所有窗口的前面,以保持其始终可见。

而findwindow置顶函数则是一种破解置顶功能的方法。

本文将一步一步地探究findwindow置顶函数的用法,帮助读者了解如何实现置顶效果以及相关的安全问题。

第一部分:了解findwindow置顶函数的基础知识1.1 理解findwindow函数findwindow函数是Windows API提供的一种用于搜索窗口的函数,可以通过窗口的类名或标题来查找窗口句柄(handle)。

一旦找到相应的窗口句柄,就可以对窗口进行各种操作,包括将其置顶。

(此处可适当展开关于findwindow函数更多的介绍,如参数的说明等)1.2 了解置顶功能的原理在Windows操作系统中,窗口分为普通窗口和置顶窗口两种类型。

普通窗口是默认的类型,它们根据层次结构来进行显示。

相比之下,置顶窗口则以特殊的方式进行处理,使其始终显示在其他窗口的前面。

为了实现置顶效果,可以通过修改窗口的窗口风格(window style)来将其置顶。

窗口风格是窗口的一些属性,可以通过窗口句柄进行设置或修改。

第二部分:实现findwindow置顶函数的步骤2.1 获取目标窗口句柄首先,需要通过findwindow函数来获取目标窗口的句柄。

句柄是一个唯一标识窗口的值,可以用于后续的操作。

2.2 修改窗口风格通过修改目标窗口的窗口风格,可以将其置顶。

具体来说,可以使用SetWindowLong(窗口句柄, GWL_STYLE, 新窗口风格)函数来实现。

其中,GWL_STYLE表示需要修改的窗口风格,新窗口风格是一个由特定标志位组成的数值。

2.3 设置置顶属性将目标窗口的置顶属性设置为真,即WS_EX_TOPMOST。

FindWindow查找窗口

FindWindow查找窗口

FindWindow查找窗⼝Declare Function SendMessage Lib "user32" Alias "SendMessageA" _(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, _ByVal lParam As Long) As LongDeclare Function FindWindow Lib "user32" Alias _"FindWindowA" (ByVal lpClassName As String, ByVal _lpWindowName As String) As LongDeclare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As LongPrivate Const WM_SETREDRAW = &HBPrivate Sub tryThis()Dim h As Longh = FindWindow("xlMain", vbNullString)LockWindowUpdate Application.VBE.MainWindow.hwndCall SendMessage(h, WM_SETREDRAW, 0, 0)Application.SendKeys "Range", TrueApplication.SendKeys "~", TrueApplication.Goto Reference:="tryThis"On Error Resume Next 'in case it's not thereWith ThisWorkbook.VBProject.VBComponents("Module2").CodeModule.DeleteLines 1, .CountOfLinesEnd WithCall SendMessage(h, WM_SETREDRAW, 1, 0)Application.VBE.MainWindow.Visible = FalseLockWindowUpdate 0ThisWorkbook.Close TrueEnd SubFindWindow(lpClassName, {窗⼝的类名}lpWindowName: PChar {窗⼝的标题}): HWND; {返回窗⼝的句柄; 失败返回 0}//FindWindowEx ⽐ FindWindow 多出两个句柄参数:FindWindowEx(Parent: HWND; {要查找⼦窗⼝的⽗窗⼝句柄}Child: HWND; {⼦窗⼝句柄}ClassName: PChar; {}WindowName: PChar {}): HWND;{如果 Parent 是 0, 则函数以桌⾯窗⼝为⽗窗⼝, 查找桌⾯窗⼝的所有⼦窗⼝;如果是 HWND_MESSAGE, 函数仅查找所有消息窗⼝;⼦窗⼝必须是 Parent 窗⼝的直接⼦窗⼝;如果 Child 是 0, 查找从 Parent 的第⼀个⼦窗⼝开始;如果 Parent 和 Child 同时是 0, 则函数查找所有的顶层窗⼝及消息窗⼝.}//测试1: 试着找找新建程序主窗⼝的句柄varh: HWND;begin{现在我们知道窗⼝的标题是: Form1、窗⼝的类名是: TForm1}h := FindWindow('TForm1', 'Form1');ShowMessage(IntToStr(h)); {656180; 这是随机, 每次启动窗⼝肯定不⼀样} {假如不知道类名}h := FindWindow(nil, 'Form1');ShowMessage(IntToStr(h)); {656180}{假如不知道标题名}h := FindWindow('TForm1', nil);ShowMessage(IntToStr(h)); {656180}{其实这个窗⼝的句柄不就是 Self.Handle 吗}ShowMessage(IntToStr(Handle)); {656180}end;//测试2: 找计算器窗⼝的句柄(先打开计算器)varh: HWND;begin{如果不是简体中⽂系统, 这样可能不灵}h := FindWindow(nil, '计算器');ShowMessage(IntToStr(h)); {1508334}{最好这样, 但你得提前知道计算器窗⼝的类名是: SciCalc}h := FindWindow('SciCalc', nil);ShowMessage(IntToStr(h)); {1508334}end;。

findwindow 函数的用法

findwindow 函数的用法

findwindow 函数的用法
`FindWindow`函数是Windows API中的一个函数,用于查找指定窗口的句柄(handle)。

它可以通过窗口的类名或窗口标题来匹配窗口并返回其句柄。

以下是FindWindow函数的使用方法:
```python
import ctypes
# 加载User32.dll库
user32 = er32
# 定义需要查找的窗口类名和窗口标题
class_name = "窗口类名"
window_title = "窗口标题"
# 使用FindWindow函数搜索匹配的窗口
window_handle = user32.FindWindowW(class_name, window_title)
# 检查是否找到了匹配的窗口
if window_handle == 0:
print("未找到匹配的窗口")
else:
print("窗口句柄: ", window_handle)
```
上述代码使用`ctypes`模块加载了`User32.dll`库,并调用了其`FindWindowW`函数来查找指定窗口。

`class_name`参数用于指定窗口的类名,可以通过工具如Spy++来获取窗口的类名。

`window_title`参数用于指定窗口的标题。

如果找到了匹配的窗口,`FindWindow`函数会返回该窗口的句柄(一个整数值),否则返回0表示未找到。

你可以根据需要对找到的窗口句柄进行后续操作,如发送消息、获取窗口位置等。

用例子说明FindWindow的用法

用例子说明FindWindow的用法

FindWindow
函数原型:
CWnd::FindWindow
static CWnd* PASCAL FindWindow( LPCTSTR lpszClassName, LPCTSTR lpszWindowName );
参数表:
IpClassName :指向一个指定了类名的空结束字符串,或一个标识类名字符串的成员的指针。

如果该参数为一个成员,则它必须为前次调用theGlobafAddAtom函数产生的全局成员。

该成员为16位,必须位于IpClassName的低16位,高位必须为0。

IpWindowName:指向一个指定了窗口名(窗口标题)的空结束字符串。

如果该参数为空,则为所有窗口全匹配。

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

如果函数执行失败,则返回值为NULL 。

可以通过调用GetLastError函数获得更加详细的错误信息。

例子:
建立基于对话框的应用程序工程名FindWindowFun,系统建立ID为:IDD_FINDWINDOWFUN_DIALOG,标题为:FindWindowFun的对话框窗口。

void CFindWindowFunDlg::OnButton1()
{
// TODO: Add your control notification handler code here
CWnd* phwnd=FindWindow(NULL,"FindWindowfun");
然后就可以用Phwnd操作本窗口了
.
.
.
}。

vb获取句柄的几种方式

vb获取句柄的几种方式

vb获取句柄的几种方式获取句柄是在VB中常见的操作之一,句柄可以用于标识和操作窗口、控制界面元素等。

下面将介绍几种常见的获取句柄的方式。

1. 使用FindWindow函数FindWindow函数可以根据窗口类名和窗口标题来查找窗口句柄。

可以使用以下代码获取窗口句柄:```vbDim hwnd As Longhwnd = FindWindow("窗口类名", "窗口标题")```其中,窗口类名是指窗口所属的类的名称,窗口标题是窗口上显示的文本。

2. 使用FindWindowEx函数FindWindowEx函数可以在指定窗口下查找符合条件的子窗口句柄。

可以使用以下代码获取子窗口句柄:```vbDim hwndParent As LongDim hwndChild As LonghwndParent = FindWindow("父窗口类名", "父窗口标题") hwndChild = FindWindowEx(hwndParent, 0, "子窗口类名", "子窗口标题")```其中,hwndParent是父窗口的句柄,hwndChild是子窗口的句柄。

3. 使用GetForegroundWindow函数GetForegroundWindow函数可以获取当前活动窗口的句柄。

可以使用以下代码获取当前活动窗口句柄:```vbDim hwnd As Longhwnd = GetForegroundWindow()```该函数不需要任何参数,直接调用即可。

4. 使用GetDesktopWindow函数GetDesktopWindow函数可以获取桌面窗口的句柄。

可以使用以下代码获取桌面窗口句柄:```vbDim hwnd As Longhwnd = GetDesktopWindow()```该函数不需要任何参数,直接调用即可。

FindWindow函数详解

FindWindow函数详解

C#中使用FindWindow函数详解FindWindow 用来根据类名和窗口名来得到窗口句柄的。

但是这个函数不能查找子窗口,也不区分大小写。

如果要从一个窗口的子窗口中查找需要使用FindWindowEX。

1.在C#中使用方法如下:[DllImport("User32.dll", EntryPoint = "FindWindow")]private static extern IntPtr FindWindow(string lpClassName,string lpWindowName);[DllImport("User32.dll", EntryPoint = "FindWindowEx")]private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpClassName, string lpWindowName); [DllImport("User32.dll", EntryPoint = "FindWindow")]private static extern IntPtr FindWindow(string lpClassName,string lpWindowName);[DllImport("User32.dll", EntryPoint = "FindWindowEx")]private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpClassName, string lpWindowName);2. 实例参考:IntPtr hWnd = FindWindow(null, "test Demo");这样会查找所有title是"test Demo"的窗口。

FINDWINDOWEX参数详解

FINDWINDOWEX参数详解

StringBuilder stbf_WndStr = new StringBuilder();//定义存储String的Butter stbf_WndStr.Capacity = 60; //1) 该例子一直无法找到Exit按键,因为Name不为null,而是等于"",null和""是有区别的 tbDisplay.Text = tbDisplay.Text + "\r\n\r\n1) 此处寻找不到Exit的按键,因为Name不为null,而是等 于\"\""; ExitWnd = FindWindowEx(ParenthWnd, new IntPtr(0), lpszClass_Submit, ""); if (!ExitWnd.Equals(IntPtr.Zero)) { GetWindowText(ExitWnd, stbf_WndStr, stbf_WndStr.Capacity - 1); tbDisplay.Text = tbDisplay.Text + "\r\n实验内容: ExitWnd.text = " + stbf_WndStr.ToString(); } else { tbDisplay.Text = tbDisplay.Text + "\r\nErr: ExitWnd = null!!!"; } //2) 寻找到Exit的按键,因为Name包含正确的名字"Exit" tbDisplay.Text = tbDisplay.Text + "\r\n\r\n2) 寻找到Exit的按键,因为Name包含正确的名字 \"Exit\""; ExitWnd = FindWindowEx(ParenthWnd, new IntPtr(0), lpszClass_Submit, "Exit"); if (!ExitWnd.Equals(IntPtr.Zero)) { GetWindowText(ExitWnd, stbf_WndStr, stbf_WndStr.Capacity - 1); tbDisplay.Text = tbDisplay.Text + "\r\n实验内容: ExitWnd.text = " + stbf_WndStr.ToString(); } else

C语言windows.h库的常用函数(一)

C语言windows.h库的常用函数(一)

C语言windows.h库的常用函数(一)1:FindWindow函数该函数可以通过窗口类名或者窗口标题名来查找特定窗口句柄,返回值是窗口的句柄(在Windows中,句柄是一个系统内部数据结构的引用。

例如当你操作一个窗口,或说是一个Delphi窗体时,系统会给你一个该窗口的句柄,系统会通知你:你正在操作142号窗口,就此你的应用程序就能要求系统对142号窗口进行操作——移动窗口、改变窗口大小、把窗口最小化等等。

实际上许多Windows API函数把句柄作为它的第一个参数,如GDI(图形设备接口)句柄、菜单句柄、实例句柄、位图句柄等,不仅仅局限于窗口函数。

换句话说,句柄是一种内部代码,通过它能引用受系统控制的特殊元素,如窗口、位图、图标、内存块、光标、字体、菜单等。

)函数用法#include 'stdafx.h'#include<windows.h>int main() {HWND window; //定义一个窗口句柄变量,用来储存窗口句柄/*FindWindow('这里填窗口类名','这里填窗口标题名')窗口类名和窗口标题名可以只填一个,不填的用NULL填充*/window = FindWindow(NULL,'文本.txt - 记事本'); //查找标题为'文本.txt - 记事本'的窗口SendMessage(window,WM_CLOSE,0,0); //向窗口发送关闭指令return 0;}2:SendMessage函数刚刚在第一个例子里面已经用到了SendMessage函数,这个函数的功能是向句柄对应窗口发送指令函数用法#include 'stdafx.h'#include<windows.h>int main() {POINT mouse;HWND window;while (1) {GetCursorPos(&mouse);window = WindowFromPoint(mouse);/*SendMessage(窗口句柄,消息类型,消息附带内容,消息附带内容) 比如我这里选定的消息类型是WM_CHAR消息附带内容为WPARAM('a')所以消息附带内容就是模拟键盘向窗口输入a*/SendMessage(window,WM_CHAR,WPARAM('a'),0);Sleep(100);}return 0;}3:WindowFromPoint函数在第二个例子中我们使用了一个叫做WindowFromPoint的函数,这个函数的功能是通过鼠标点击获得被点击窗口的句柄函数用法#include 'stdafx.h'#include<windows.h>int main() {POINT mouse; //定义一个结构体变量储存鼠标位置HWND window;while (1) {GetCursorPos(&mouse); //获取到当前鼠标位置/*WindowFromPoint(鼠标位置变量名)*/ window = WindowFromPoint(mouse); SendMessage(window,WM_CLOSE,0,0); Sleep(100);}return 0;}。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

C#中使用FindWindow函数详解
FindWindow 用来根据类名和窗口名来得到窗口句柄的。

但是这个函数不能查找子窗口,也不区分大小写。

如果要从一个窗口的子窗口中查找需要使用FindWindowEX。

1.在C#中使用方法如下:
[DllImport("User32.dll", EntryPoint = "FindWindow")]
private static extern IntPtr FindWindow(string lpClassName,string lpWindowName);
[DllImport("User32.dll", EntryPoint = "FindWindowEx")]
private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpClassName, string lpWindowName); [DllImport("User32.dll", EntryPoint = "FindWindow")]
private static extern IntPtr FindWindow(string lpClassName,string lpWindowName);
[DllImport("User32.dll", EntryPoint = "FindWindowEx")]
private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpClassName, string lpWindowName);
2. 实例参考:
IntPtr hWnd = FindWindow(null, "test Demo");
这样会查找所有title是"test Demo"的窗口。

参考下面的资料解释
3. FindWindow参数详解:
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.
Remarks
If the lpWindowName parameter is not NULL, FindWindow calls the GetWindowText function to retrieve the window name for comparison. For a description of a potential problem that can arise, see the Remarks for GetWindowText.
To check if the Microsoft IntelliType version 1.x software is running, call FindWindow as follows:
Copy Code
FindWindow("MSITPro::EventQueue",NULL); To check if the IntelliType version 2.0 software is running, call FindWindow as follows:
Copy Code
FindWindow("Type32_Main_Window", NULL); If the IntelliType software is running, it sends WM_APPCOMMAND messages to the application. Otherwise the application must install a hook to receive WM_APPCOMMAND messages.
Microsoft Windows 95 or later: FindWindowW is supported by the Microsoft Layer for Unicode (MSLU). To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows
95/98/Me Systems.
Example
For an example, see Retrieving the Number of Mouse Wheel Scroll Lines.
Function Information
Minimum DLL Version user32.dll
Header Declared in Winuser.h, include Windows.h
Import library User32.lib
Minimum operating systems Windows 95, Windows NT 3.1 Unicode Implemented as ANSI and Unicode versions.。

相关文档
最新文档