Option Explicit
Private Declare Function FindWindow Lib "user32.dll" _
Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function GetWindowLong Lib "user32" _
Alias "GetWindowLongA" ( _
ByVal hwnd As Long, _
ByVal nIndex As Long) 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 CallNextHookEx Lib "user32" _
(ByVal hHook As Long, _
ByVal nCode As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Private Declare Function UnhookWindowsHookEx Lib "user32" _
(ByVal hHook As Long) As Long
Private Declare Function GetCurrentThreadId Lib "kernel32" _
() As Long
Private Declare Function GetClassName Lib "user32.dll" _
Alias "GetClassNameA" _
(ByVal hwnd As Long, _
ByVal lpClassName As String, _
ByVal nMaxCount As Long) As Long
Public Declare Function SetParent Lib "user32.dll" _
(ByVal hWndChild As Long, _
ByVal hWndNewParent As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32.dll" _
() As Long
Private Declare Function LockWindowUpdate Lib "user32.dll" _
(ByVal hwndLock As Long) As Long
Private Declare Function ShowWindow Lib "user32.dll" _
(ByVal hwnd As Long, _
ByVal nCmdShow As Long) As Long
Private Const GWL_HINSTANCE As Long = (-6)
Private Const WH_CBT As Long = 5
Private Const HCBT_ACTIVATE As Long = 5
Private lCBTHook As Long
Private lVBEhwnd As Long
Public Sub Hide_The_VBE_Window()
Application.SendKeys "%{F11}"
lCBTHook = SetWindowsHookEx(WH_CBT, AddressOf CBTProc, _
GetAppInstance, GetCurrentThreadId)
End Sub
Public Sub Restore_The_VBE_Window()
LockWindowUpdate GetDesktopWindow
ShowWindow lVBEhwnd, 0
SetParent lVBEhwnd, 0
ShowWindow lVBEhwnd, 3
ShowWindow lVBEhwnd, 0
LockWindowUpdate 0
End Sub
Private Function CBTProc _
(ByVal idHook As Long, ByVal wParam As Long, _
ByVal lParam As Long) As Long
Dim sBuffer As String
Dim lRetVal As Long
Dim hParentWnd As Long
'Lock the screen.
LockWindowUpdate GetDesktopWindow
Select Case idHook
Case Is = HCBT_ACTIVATE 'A window has been activated
'Is it the VBE window ?
sBuffer = Space(256)
lRetVal = GetClassName(wParam, sBuffer, 256)
If Left(sBuffer, lRetVal) = "wndclass_desked_gsk" Then
'It's our VBE window so remove the CBT hook now.
UnhookWindowsHookEx lCBTHook
'Hide the VBE window.
ShowWindow wParam, 0
'Store the VBE hwnd for restoring it later.
lVBEhwnd = wParam
'Retrieve the XL process 'Thunder' window.
hParentWnd = FindWindow("ThunderMain", vbNullString)
If hParentWnd Then
'Make the VBE window the child of the Thunder
'window to remain invisible.
SetParent wParam, hParentWnd
End If
End If
End Select
'Unlock the screen.
LockWindowUpdate 0
CBTProc = CallNextHookEx _
(lCBTHook, idHook, ByVal wParam, ByVal lParam)
End Function
Private Function GetAppInstance() As Long
GetAppInstance = GetWindowLong _
(FindWindow("XLMAIN", Application.Caption), GWL_HINSTANCE)
End Function