Never used hooks before:
I'm using Excel. When The Excel window is minimized my Form is hidden.
What I want to do: When the Excel minimized icon is clicked, I need to show my Form again. There is no Application event
I can tap to show my form so I'm trying to use a Hook.

Here's what I have so far...
My Declarations in a mod:
VB Code:
  1. Option Explicit
  2.  
  3. Public Const HCBT_MINMAX = 1
  4. Public Const WH_MAX As Long = 11
  5. Public Const WH_CBT As Long = 5
  6.  
  7. Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long
  8. Public 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
  9. Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
  10. Public Declare Function GetCurrentThreadId Lib "kernel32.dll" () As Long
  11.  
  12. Public hHook As Long
My hook calling prodedure:
VB Code:
  1. Application.WindowState = xlMinimized
  2.     ThreadId = GetCurrentThreadId()
  3.     hHook = SetWindowsHookEx(WH_CBT, AddressOf RESIZEProc, 0, ThreadId)
My Callback Procedure:
VB Code:
  1. Public Sub RESIZEProc(ByVal idHook As Long, ByVal wParam As Long, ByVal lParam As Long)
  2.  
  3.     'if idHook is less than zero, no further processing is required
  4.     If idHook < 0 Then
  5.         'call the next hook
  6.         RESIZEProc = CallNextHookEx(hHook, idHook, wParam, ByVal lParam)
  7.     Else
  8.         If hHook = HCBT_MINMAX Then
  9.             MsgBox "Message Was Sent To Minimize or Maximize The Window"
  10.         End If
  11.         If wParam = MainHwnd Then
  12.             MsgBox "MainHwnd Was Passed"
  13.         End If
  14.         RESIZEProc = CallNextHookEx(hHook, idHook, wParam, ByVal lParam)
  15.     End If
  16.  
  17. End Sub
In the procedure above MainHwnd is already set when the form is initilized.
When using VBA you have to get your own handle using other API's because
there is no Me.Hwnd available. Therefore I have already set a global variable
called MainHwnd that contains the correct handle.

Problem, regardless if all of this is set up correctly, I can't run it yet because
when I compile the project I get "argument not optional" on RESIZProc in the following code:
VB Code:
  1. If idHook < 0 Then
  2.         'call the next hook
  3.         RESIZEProc = CallNextHookEx(hHook, idHook, wParam, ByVal lParam)
  4.     Else

Can someone tell me if I'm headed in the right direction with this. My intention is to eventually use the
following code section as the location in which to show my form again.
VB Code:
  1. If hHook = HCBT_MINMAX Then
  2.             MsgBox "Message Was Sent To Minimize or Maximize The Window"
  3.         End If