RegisterWindowMessage

RegisterWindowMessage用于在windows系统中注册一个唯一的消息。

如果注册成功时,直接返回消息号,消息号的范围在 0xC000 (3072) 到 0xFFFF (65535) 之间。

如果注册失败时,则该函数返回 0。

 

注意:当以字符串所标识的消息存在时,则直接返回该字符串所对应的消息号。

转载于:https://www.cnblogs.com/railgunman/archive/2010/08/30/1812980.html

' API Declarations Private Declare PtrSafe Function EnumWindows Lib "user32" (ByVal lpEnumFunc As LongPtr, ByVal lParam As LongPtr) As Boolean Private Declare PtrSafe Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As LongPtr, ByVal lpString As String, ByVal cch As Long) As Long Private Declare PtrSafe Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hWnd As LongPtr) As Long Private Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As LongPtr, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Private Declare PtrSafe Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageA" (ByVal lpString As String) As Long ' Global variable to store found window handle Dim ghWnd As LongPtr ' Callback function for EnumWindows Public Function EnumWindowsProc(ByVal hWnd As LongPtr, ByVal lParam As LongPtr) As Long Dim length As Long Dim title As String length = GetWindowTextLength(hWnd) If length > 0 Then title = Space$(length + 1) GetWindowText hWnd, title, length + 1 ' Trim null terminator title = Left$(title, length) ' Check if title contains "Color iControl" If InStr(title, "Color iControl") > 0 Then ghWnd = hWnd ' Return 0 to stop enumeration EnumWindowsProc = 0 Exit Function End If End If ' Return 1 to continue enumeration EnumWindowsProc = 1 End Function Sub FindAndSendCopyCommand() Dim msgId As Long Dim result As Long ' Initialize ghWnd = 0 ' Step 1: Enumerate all windows and find one with "Color iControl" in title EnumWindows AddressOf EnumWindowsProc, 0 If ghWnd = 0 Then MsgBox "未找到 Color iControl 窗口!", vbCritical Exit Sub Else MsgBox "找到窗口句柄: " & ghWnd End If ' Step 2: Get the registered message ID msgId = RegisterWindowMessage("iControl_Command") If msgId = 0 Then MsgBox "无法注册 iControl_Command 消息。", vbCritical Exit Sub End If ' Step 3: Send command 301 - Copy Meas To Clipboard result = SendMessage(ghWnd, msgId, 301, 0) MsgBox "已发送复制命令!结果码: " & result, vbInformation End Sub 这个代码上修改,希望测量完成502能够触发301
最新发布
10-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值