I wrote a program similar to dm2 (anyone remembers? 

) a few years ago and never had problems with the global hook since! 
Here are the core functions...
nlh.dll
Code: Select all
Enumeration
  #NLH_DLL_CONTROL = #WM_USER + 101
EndEnumeration
ProcedureDLL NLH( nCode, wParam, *lParam.MOUSEHOOKSTRUCT )
  
  If nCode < 0 : ProcedureReturn CallNextHookEx_( @NLH(), nCode, wParam, *lParam ) : EndIf
  
  Select wParam
      
    Case #WM_NCRBUTTONDOWN
      Select *lParam\wHitTestCode
          
        Case #HTCAPTION
          ProcedureReturn PostMessage_(FindWindow_(0,"[ nlh ]"), #NLH_DLL_CONTROL, *lParam\hwnd, *lParam\wHitTestCode)
          
      EndSelect
      
  EndSelect
  
  ProcedureReturn CallNextHookEx_( @NLH(), nCode, wParam, *lParam )
  
EndProcedure
 
nlh.exe
Code: Select all
Enumeration
  #Window
  #NLH_DLL
  #NLH_DLL_CONTROL = #WM_USER + 101
EndEnumeration
OpenWindow(#Window, 0, 0, 320, 100, "[ nlh ]", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_Invisible)
TextGadget(0, 20,40,300,30, "Right-Click on any titlebar to minimize the selected window")
If OpenLibrary(#NLH_DLL, "nlh.dll")
  NLH_DLL = SetWindowsHookEx_(#WH_MOUSE, GetFunction(#NLH_DLL, "NLH"), LibraryID(#NLH_DLL), #Null )
Else
  MessageRequester("", "nlh.dll not found...")
  End
EndIf
HideWindow(#Window, #False, #PB_Window_ScreenCentered)
Repeat
  event = WaitWindowEvent()
  Select event
      
    Case #NLH_DLL_CONTROL
      Select EventlParam()
          
        Case #HTCAPTION
          hWnd = EventwParam()
          ShowWindow_(hWnd, #SW_MINIMIZE)
          Beep_(800,50)
          
      EndSelect
      
  EndSelect
Until event = #PB_Event_CloseWindow
If NLH_DLL
  UnhookWindowsHookEx_(NLH_DLL)
EndIf
If IsLibrary(#NLH_DLL)
  CloseLibrary(#NLH_DLL)
EndIf
 
Reminds me to rewrite [ nlh ] with PB5.21  
cheers, chi