|
发表于 2022-4-16 16:30
来自手机
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 lss001 于 2022-4-19 08:08 编辑
Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" ( _
ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function GetCurrentThreadId Lib "kernel32" () As Long
Private Declare Function SetWindowsHookEx Lib "user32" Alias _
"SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, _
ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, _
ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, _
ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function GetActiveWindow Lib "user32" () As Long
Const GWL_HINSTANCE = (-6), SWP_NOSIZE = &H1, HCBT_ACTIVATE = 5
Const SWP_NOZORDER = &H4, SWP_NOACTIVATE = &H10, WH_CBT = 5
Private hHook As Long, mLeft As Long, mTop As Long
Function WinProc(ByVal lMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If lMsg = HCBT_ACTIVATE Then
SetWindowPos wParam, 0, mLeft, mTop, 0, 0, SWP_NOSIZE Or _
SWP_NOZORDER Or SWP_NOACTIVATE
UnhookWindowsHookEx hHook
End If
WinProc1 = False
End Function
Sub 自定义MsgBox显示位置()
Dim hInst As Long, Thread As Long
mLeft = 100: mTop = 300 '指定位置
hInst = GetWindowLong(Application.Hinstance, GWL_HINSTANCE)
Thread = GetCurrentThreadId()
If GetActiveWindow() <> Application.Hwnd Then
Application.VBE.CommandBars. _
FindControl(ID:=752).Execute '关闭VBE窗口
Application.VBE.MainWindow.Visible = False
End If
hHook = SetWindowsHookEx(WH_CBT, AddressOf WinProc, hInst, Thread)
MsgBox "MsgBox当前位置(x=" & mLeft & ", y=" & mTop & ")", 1 + 64, "系统提示!"
End Sub |
评分
-
1
查看全部评分
-
|