【VB技巧】VB查找指定名称窗口并发送消息

  • A+
所属分类:lcx

    VB查找指定名称窗口并发送消息,VB查找指定名称窗口发送消息,VB查找指定窗口发送消息,VB查找窗口发送消息,VB指定窗口发送消息,VB窗口发送消息,VB窗口消息,VB窗口,FindWindow(vbNullString, "Windows 文件保护"),PostMessage(hwnd, WM_QUIT, 0, 0),VB 关闭Windows 文件保护窗口,VB 关闭Windows 窗口,VB 关闭文件保护窗口,VB 关闭Windows 文件保护,VB Windows 文件保护窗口,VB Windows 文件保护,VB 关闭窗口。

VB查找指定名称窗口并发送消息:

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long '查找窗口
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long '发送消息
Private Const WM_QUIT = &H12
Dim hwnd  As Long                                                               '定义存放"Windows 文件保护"窗口句柄的变量
hwnd = FindWindow(vbNullString, "Windows 文件保护")                             '查找"Windows 文件保护"窗口,并把对应的句柄存入变量
If hwnd 0 Then Call PostMessage(hwnd, WM_QUIT, 0, 0)                         '如果窗口存在则退出窗口

VB查找指定名称窗口并发送消息精简代码:

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long '查找窗口
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long '发送消息
Private Const WM_QUIT = &H12
If FindWindow(vbNullString, "Windows 文件保护") 0 Then Call PostMessage(FindWindow(vbNullString, "Windows 文件保护"), WM_QUIT, 0, 0) '如果窗口存在则关闭窗口

部分常量参数值:

Private Const WM_QUIT = &H12
退出:WM_QUIT
隐藏:SW_HIDE
Private Const WM_QUIT = &H10
关闭:WM_CLOSE
Private Const WM_LBUTTONDOWN = &H201
鼠标左键按下:WM_LBUTTONDOWN
Private Const WM_KEYDOWN = &H100
Private Const WM_KEYUP = &H101
Private Const WM_MOUSEMOVE = &H200
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_LBUTTONUP = &H202
Private Const WM_LBUTTONDBLCLK = &H203
Private Const WM_RBUTTONDOWN = &H204
Private Const WM_RBUTTONUP = &H205
Private Const WM_RBUTTONDBLCLK = &H206
Private Const WM_MBUTTONDOWN = &H207
Private Const WM_MBUTTONUP = &H208
Private Const WM_MBUTTONDBLCLK = &H209
Private Const WM_MOUSEWHEEL = &H20A
Private Const WM_SYSTEMKEYDOWN = &H104
Private Const WM_SYSTEMKEYUP = &H105

文章来源于lcx.cc:【VB技巧】VB查找指定名称窗口并发送消息

相关推荐: VB EnumWindows枚举所有窗口函数详解

    EnumWindows 枚举所有窗口函数功能详解 函数功能:     该函数枚举所有屏幕上的顶层窗口,并将窗口句柄传送给应用程序定义的回调函数。回调函数返回FALSE将停止枚举,否则EnumWindows函数继续到所有顶层窗口枚举完为止。 函数原型: …

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: