在VB中如何使用FindWindow或FindWindowEx函数查找某窗体句柄

来源:百度知道 编辑:UC知道 时间:2024/05/09 09:03:36
例如打开一个记事本,他的标题是名称加" - 记事本",用FindWindow或FindWindowEx函数该怎么查找他的句柄?或者只知道那个窗体标题中包含的几个字符,有没有办法查找到它的句柄...请大家帮忙!
对下面几个API并不是很熟悉!如方便的请完整给出代码...或参考资料
最后问题补充:答案无法满足我的条件(很多看不懂的)!对不起...请再详细点!

1.定义一个模块, 内容为:
Option Explicit

Public Declare Function GetNextWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As Long, ByVal wFlag As Long) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

Public Declare Function FindWindowa Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Public Declare Function GetForegroundWindow Lib "user32" () As Long

2. 给窗口加一个按钮, 在按钮的click事件里写以下内容:
Option Explicit

Private Sub Command1_Click()

Dim hwnd As Long
hwnd = GetForegroundWindow ' FindWindowa("Notepad", "新建 文本文档.txt - 记事本")

Dim str1 As String, len1 As Long
str1 = Space(255) '定义接收字串.
GetWindowText hwnd, str1, 1024

Do While