C#中使用FindWindow函数详解

 FindWindow 用来根据类名和窗口名来得到窗口句柄的。但是这个函数不能查找子窗口,也不区分大小写。

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

1.在C#中使用方法如下:

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:

FindWindow("MSITPro::EventQueue",NULL);   

To check if the IntelliType version 2.0 software is running, call FindWindow as follows:

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 Versionuser32.dll
HeaderDeclared in Winuser.h, include Windows.h
Import libraryUser32.lib
Minimum operating systems Windows 95, Windows NT 3.1
UnicodeImplemented as ANSI and Unicode versions.
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值