Capture Excel Application 'Main Window' Events

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
9,630
Office Version
  1. 2016
Platform
  1. Windows
Workbook Example

Hi all, As we know, Excel exposes events for the Worksheet and Workbook objects but for some reason it skipped events related to the application Object ... For example, there is no VBA native way to detect when the user deactivates the excel main window before switching to a different application or a way to capture the resizing of the main excel window and so on so forth... So here, I will be attempting to fill that gap by using the Win32 API.

Although there is code out there on the net that uses 'Subclassing' meant to work for achieving similar functionality on compiled VB6 exes, I have never seen or been able to make the same code work for Excel/VBA without causing excel to crash .

Anyway, here are the events that should be supported :
_WindowMinMaxSize
_WindowResizing
_WindowMoving
_WindowActivate
_WindowDeActivate
_WindowMaximize
_WindowMinimise
_WindowRestore
_WindowBeforeClose

Project code :

1- In a Standard Module ( Hook_bas ) :
Code:
Option Explicit
Private Type FunctPtrs
    WndActivate As Long
    WndDeActivate As Long
    WndMinMaxSize As Long
    WndResizing As Long
    WndMoving As Long
    WndMaximize As Long
    WndMinimise As Long
    WndRestore As Long
    WndClose As Long
End Type
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" _
(ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
Private Declare Function GetProp Lib "user32" Alias "GetPropA" (ByVal hwnd As Long, ByVal lpString As String) As Long
Private Declare Function SetProp Lib "user32" Alias "SetPropA" (ByVal hwnd As Long, ByVal lpString As String, ByVal hData As Long) As Long
Private Declare Function RemoveProp Lib "user32" Alias "RemovePropA" (ByVal hwnd As Long, ByVal lpString As String) As Long

Private Const DLL_PATH_NAME = "C:\ExcelAppEvents.dll"
Private Const DLL_MODULE_HANDLE = "DllHandle"

Public Sub Hook()
    Call StartHook(Application.hwnd)
End Sub

Public Sub UnHook()
    Call EndHook(Application.hwnd)
End Sub

Private Sub StartHook(ByVal hwnd As Long)
    Dim tFuncPtrs As FunctPtrs
    Dim lb As Long
    Dim pa As Long
    
    With tFuncPtrs
        .WndActivate = GetFuncAddr(AddressOf Application_WindowActivate)
        .WndClose = GetFuncAddr(AddressOf Application_WindowBeforeClose)
        .WndDeActivate = GetFuncAddr(AddressOf Application_WindowDeActivate)
        .WndMaximize = GetFuncAddr(AddressOf Application_WindowMaximize)
        .WndMinimise = GetFuncAddr(AddressOf Application_WindowMinimise)
        .WndMinMaxSize = GetFuncAddr(AddressOf Application_WindowMinMaxSize)
        .WndMoving = GetFuncAddr(AddressOf Application_WindowMoving)
        .WndResizing = GetFuncAddr(AddressOf Application_WindowResizing)
        .WndRestore = GetFuncAddr(AddressOf Application_WindowRestore)
    End With
    If GetProp(hwnd, DLL_MODULE_HANDLE) = 0 Then
        Call BuildDll(DLL_PATH_NAME)
        If Len(Dir(DLL_PATH_NAME)) > 0 Then
            lb = LoadLibrary(DLL_PATH_NAME)
            Call SetProp(hwnd, DLL_MODULE_HANDLE, lb)
            pa = GetProcAddress(lb, "HOOK")
            Call CallWindowProc(pa, hwnd, VarPtr(tFuncPtrs), ByVal 0&, ByVal 0&)
        End If
    End If
End Sub

Private Sub EndHook(ByVal hwnd As Long)
    Dim lb As Long
    Dim pa As Long
    Call FreeLibrary(GetProp(hwnd, DLL_MODULE_HANDLE))
    Call RemoveProp(hwnd, DLL_MODULE_HANDLE)
    lb = LoadLibrary(DLL_PATH_NAME)
    pa = GetProcAddress(lb, "UNHOOK")
    Call CallWindowProc(pa, hwnd, ByVal 0&, ByVal 0&, ByVal 0&)
    Call FreeLibrary(lb)
    If Len(Dir(DLL_PATH_NAME)) > 0 Then
        Kill DLL_PATH_NAME
    End If
End Sub

Private Function GetFuncAddr(FuncAddr As Long) As Long
    GetFuncAddr = FuncAddr
End Function

2- In a Standard Module ( DllBuilder_bas )
Code:
Option Explicit
Private Declare Sub CopyMemory Lib "kernel32" Alias _
"RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
Private ar1() As Variant, ar2() As Variant, ar3() As Variant, ar4() As Variant, ar5() As Variant
Private ar6() As Variant, ar7() As Variant, ar8() As Variant, ar9() As Variant, ar10() As Variant, ar11() As Variant

Private Sub GetDllBytes1()
    ar1 = Array(77, 90, 10, 0, 2, 0, 0, 0, 4, 0, 15, 0, 255, 255, 0, 0, 192, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 0, 0, 0, 180, 9, 102, 186, 16, 0, 14, 31, 205, 33, 102, 184, 1, 76, 205, 33, 84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 87, 105, 110, 51, 50, 32, 112, 114, 111, 103, _
    114, 97, 109, 46, 13, 10, 36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 80, 69, 0, 0, 76, 1, 4, 0, 57, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 224, 0, 14, 35, 11, 1, 2, 52, 152, 19, 0, 0, 0, 8, 0, 0, 220, 8, 0, 0, 104, 26, 0, 0, 0, 16, 0, 0, 0, 48, 0, 0, 0, 0, 32, 0, 0, 16, 0, 0, 0, 2, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, _
    4, 0, 0, 0, 0, 0, 0, 0, 0, 96, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 16, 0, 0, 64, 0, 0, 0, 0, 1, 0, 0, 16, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 80, 67, 0, 0, 85, 0, 0, 0, 0, 64, 0, 0, 80, 3, 0, 0, 0, 0,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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 232, 79, 11, 0, 0, 199, 5, 48, 54, 32, 0, 48, 24, 32, 0, 199, 5, 52, 54, 32, 0, 180, 24, 32, 0, 199, 5, 56, 54, 32, 0, 168, 25, 32, 0, 199, 5, 60, 54, 32, 0, 172, 25, 32, 0, 199, 5, 64, 54, 32, 0, 176, 25, 32, 0, 199, 5, 68, 54, 32, 0, 177, 25, 32, 0, 199, 5, 72, 54, 32, 0, 181, 25, 32, 0, 199, _
    5, 76, 54, 32, 0, 185, 25, 32, 0, 139, 229, 93, 195, 0, 0, 0, 0, 0, 0, 0, 110, 17, 32, 0, 0, 0, 0, 0, 112, 98, 85, 139, 236, 83, 86, 87, 104, 63, 19, 0, 0, 131, 236, 112, 104, 106, 16, 32, 0, 49, 246, 185, 14, 0, 0, 0, 86, 73, 117, 252, 106, 36, 255, 117, 12, 141, 157, 68, 255, 255, 255, 83, 255, 21, 100, 65, 32, 0, 217, 109, 240, 139, 133, 68, 255, 255, 255, 137, 5, 80, 58, 32, 0, 139, 133, 72, 255, 255, 255, 137, _
    5, 84, 58, 32, 0, 139, 133, 76, 255, 255, 255, 137, 5, 88, 58, 32, 0, 139, 133, 80, 255, 255, 255, 137, 5, 92, 58, 32, 0, 139, 133, 84, 255, 255, 255, 137, 5, 96, 58, 32, 0, 139, 133, 88, 255, 255, 255, 137, 5, 100, 58, 32, 0, 139, 133, 92, 255, 255, 255, 137, 5, 104, 58, 32, 0, 139, 133, 96, 255, 255, 255, 137, 5, 108, 58, 32, 0, 139, 133, 100, 255, 255, 255, 137, 5, 112, 58, 32, 0, 106, 0, 186, 148, 58, 32, 0, 232, 191, 17, 0, _
    0, 106, 0, 139, 220, 232, 57, 17, 0, 0, 255, 117, 8, 255, 21, 76, 65, 32, 0, 217, 109, 240, 143, 69, 208, 59, 69, 208, 15, 133, 56, 0, 0, 0, 184, 60, 18, 32, 0, 80, 106, 252, 255, 117, 8, 255, 21, 72, 65, 32, 0, 217, 109, 240, 137, 198, 139, 198, 80, 186, 148, 58, 32, 0, 232, 123, 17, 0, 0, 106, 0, 139, 220, 232, 245, 16, 0, 0, 255, 117, 8, 255, 21, 80, 65, 32, 0, 217, 109, 240, 141, 101, 244, 95, 94, 91, 93, 194, 16, 0)
    
    ar3 = Array(0, 0, 0, 0, 0, 0, 0, 33, 18, 32, 0, 0, 0, 0, 0, 112, 98, 85, 139, 236, 83, 86, 87, 104, 63, 19, 0, 0, 131, 236, 112, 104, 137, 17, 32, 0, 49, 246, 86, 86, 86, 86, 86, 106, 0, 186, 148, 58, 32, 0, 232, 37, 17, 0, 0, 106, 0, 139, 220, 232, 159, 16, 0, 0, 255, 117, 8, 255, 21, 76, 65, 32, 0, 217, 109, 240, 143, 69, 208, 59, 69, 208, 15, 132, 81, 0, 0, 0, 186, 148, 58, 32, 0, 232, 250, 16, 0, 0, 106, 0, _
    139, 220, 232, 116, 16, 0, 0, 255, 117, 8, 255, 21, 76, 65, 32, 0, 217, 109, 240, 137, 198, 139, 198, 80, 106, 252, 255, 117, 8, 255, 21, 72, 65, 32, 0, 217, 109, 240, 186, 148, 58, 32, 0, 232, 200, 16, 0, 0, 106, 0, 139, 220, 232, 66, 16, 0, 0, 255, 117, 8, 255, 21, 84, 65, 32, 0, 217, 109, 240, 141, 101, 244, 95, 94, 91, 93, 194, 16, 0, 0, 0, 0, 0, 0, 0, 0, 184, 23, 32, 0, 0, 0, 0, 0, 112, 98, 85, 139, 236, 83, _
    86, 87, 104, 63, 19, 0, 0, 131, 236, 112, 104, 60, 18, 32, 0, 49, 246, 49, 255, 185, 32, 0, 0, 0, 86, 73, 117, 252, 49, 192, 232, 137, 16, 0, 0, 129, 125, 12, 49, 2, 0, 0, 15, 133, 20, 0, 0, 0, 199, 5, 120, 58, 32, 0, 255, 255, 255, 255, 199, 5, 128, 58, 32, 0, 255, 255, 255, 255, 129, 125, 12, 50, 2, 0, 0, 15, 133, 20, 0, 0, 0, 199, 5, 120, 58, 32, 0, 0, 0, 0, 0, 199, 5, 128, 58, 32, 0, 0, 0, 0, _
    0, 129, 125, 12, 20, 2, 0, 0, 15, 133, 60, 0, 0, 0, 106, 16, 255, 117, 20, 141, 157, 88, 255, 255, 255, 83, 255, 21, 100, 65, 32, 0, 217, 109, 240, 255, 181, 100, 255, 255, 255, 255, 181, 96, 255, 255, 255, 255, 181, 92, 255, 255, 255, 255, 181, 88, 255, 255, 255, 255, 53, 92, 58, 32, 0, 255, 21, 60, 65, 32, 0, 217, 109, 240, 129, 125, 12, 22, 2, 0, 0, 15, 133, 60, 0, 0, 0, 106, 16, 255, 117, 20, 141, 157, 72, 255, 255, 255, 83, 255, _
    21, 100, 65, 32, 0, 217, 109, 240, 255, 181, 84, 255, 255, 255, 255, 181, 80, 255, 255, 255, 255, 181, 76, 255, 255, 255, 255, 181, 72, 255, 255, 255, 255, 53, 96, 58, 32, 0, 255, 21, 60, 65, 32, 0, 217, 109, 240, 131, 125, 12, 6, 15, 133, 186, 0, 0, 0, 141, 157, 64, 255, 255, 255, 137, 59, 83, 141, 157, 68, 255, 255, 255, 137, 51, 83, 141, 93, 16, 83, 232, 125, 4, 0, 0, 139, 181, 68, 255, 255, 255, 139, 189, 64, 255, 255, 255, 141, 157, 60, 255, _
    255, 255, 83, 255, 117, 20, 255, 21, 88, 65, 32, 0, 217, 109, 240, 131, 254, 0, 15, 133, 49, 0, 0, 0, 255, 21, 104, 65, 32, 0, 217, 109, 240, 59, 133, 60, 255, 255, 255, 15, 132, 23, 0, 0, 0, 106, 0, 106, 0, 106, 0, 106, 0, 255, 53, 84, 58, 32, 0, 255, 21, 60, 65, 32, 0, 217, 109, 240, 233, 70, 0, 0, 0, 255, 21, 104, 65, 32, 0, 217, 109, 240, 59, 133, 60, 255, 255, 255, 15, 132, 49, 0, 0, 0, 106, 0, 255, 117, 8, 255, _
    21, 92, 65, 32, 0, 217, 109, 240, 143, 69, 208, 59, 69, 208, 15, 133, 23, 0, 0, 0, 106, 0, 106, 0, 106, 0, 106, 0, 255, 53, 80, 58, 32, 0, 255, 21, 60, 65, 32, 0, 217, 109, 240, 129, 125, 12, 18, 1, 0, 0, 15, 133, 55, 0, 0, 0, 129, 125, 16, 48, 240, 0, 0, 116, 13, 129, 125, 16, 50, 240, 0, 0, 15, 133, 33, 0, 0, 0, 199, 5, 124, 58, 32, 0, 255, 255, 255, 255, 106, 0, 106, 0, 106, 0, 106, 0, 255, 53, 100, 58)
    
    ar4 = Array(32, 0, 255, 21, 60, 65, 32, 0, 217, 109, 240, 131, 125, 12, 5, 15, 133, 120, 0, 0, 0, 199, 5, 124, 58, 32, 0, 0, 0, 0, 0, 219, 69, 16, 219, 125, 176, 219, 5, 208, 58, 32, 0, 219, 109, 176, 222, 217, 223, 224, 158, 15, 133, 28, 0, 0, 0, 106, 0, 106, 0, 106, 0, 106, 0, 255, 53, 104, 58, 32, 0, 255, 21, 60, 65, 32, 0, 217, 109, 240, 233, 56, 0, 0, 0, 219, 5, 204, 58, 32, 0, 219, 109, 176, 222, 217, 223, 224, 158, 15, _
    133, 36, 0, 0, 0, 131, 61, 128, 58, 32, 0, 0, 15, 133, 23, 0, 0, 0, 106, 0, 106, 0, 106, 0, 106, 0, 255, 53, 108, 58, 32, 0, 255, 21, 60, 65, 32, 0, 217, 109, 240, 131, 125, 12, 16, 15, 133, 196, 0, 0, 0, 49, 210, 82, 82, 82, 49, 192, 141, 92, 36, 8, 83, 137, 3, 49, 192, 141, 92, 36, 8, 83, 137, 3, 49, 192, 141, 92, 36, 8, 83, 137, 3, 141, 157, 56, 255, 255, 255, 83, 255, 53, 112, 58, 32, 0, 255, 21, 60, 65, _
    32, 0, 131, 196, 12, 217, 109, 240, 131, 189, 56, 255, 255, 255, 0, 15, 132, 20, 0, 0, 0, 199, 133, 104, 255, 255, 255, 1, 0, 0, 0, 233, 152, 2, 0, 0, 233, 106, 0, 0, 0, 186, 148, 58, 32, 0, 232, 165, 13, 0, 0, 106, 0, 139, 220, 232, 31, 13, 0, 0, 255, 117, 8, 255, 21, 76, 65, 32, 0, 217, 109, 240, 137, 133, 52, 255, 255, 255, 255, 181, 52, 255, 255, 255, 106, 252, 255, 117, 8, 255, 21, 72, 65, 32, 0, 217, 109, 240, 186, 148, _
    58, 32, 0, 232, 108, 13, 0, 0, 106, 0, 139, 220, 232, 230, 12, 0, 0, 255, 117, 8, 255, 21, 84, 65, 32, 0, 217, 109, 240, 106, 0, 106, 0, 106, 16, 255, 117, 8, 255, 21, 68, 65, 32, 0, 217, 109, 240, 131, 125, 12, 36, 15, 133, 217, 1, 0, 0, 131, 61, 120, 58, 32, 0, 0, 15, 133, 204, 1, 0, 0, 141, 157, 252, 254, 255, 255, 83, 141, 157, 0, 255, 255, 255, 83, 141, 157, 4, 255, 255, 255, 83, 141, 157, 8, 255, 255, 255, 83, 255, 53, _
    88, 58, 32, 0, 255, 21, 60, 65, 32, 0, 217, 109, 240, 131, 61, 124, 58, 32, 0, 255, 15, 133, 206, 0, 0, 0, 106, 0, 255, 21, 64, 65, 32, 0, 217, 109, 240, 137, 133, 8, 255, 255, 255, 106, 1, 255, 21, 64, 65, 32, 0, 217, 109, 240, 137, 133, 0, 255, 255, 255, 139, 133, 8, 255, 255, 255, 137, 133, 36, 255, 255, 255, 139, 133, 0, 255, 255, 255, 137, 133, 40, 255, 255, 255, 49, 192, 139, 141, 4, 255, 255, 255, 59, 200, 184, 255, 255, 255, 255, 116, _
    1, 64, 133, 192, 15, 132, 18, 0, 0, 0, 106, 0, 255, 21, 64, 65, 32, 0, 217, 109, 240, 232, 199, 11, 0, 0, 235, 6, 219, 133, 4, 255, 255, 255, 219, 157, 44, 255, 255, 255, 49, 192, 139, 141, 252, 254, 255, 255, 59, 200, 184, 255, 255, 255, 255, 116, 1, 64, 133, 192, 15, 132, 18, 0, 0, 0, 106, 1, 255, 21, 64, 65, 32, 0, 217, 109, 240, 232, 143, 11, 0, 0, 235, 6, 219, 133, 252, 254, 255, 255, 219, 157, 48, 255, 255, 255, 106, 40, 141, 157, _
    12, 255, 255, 255, 83, 255, 117, 20, 255, 21, 100, 65, 32, 0, 217, 109, 240, 199, 133, 104, 255, 255, 255, 1, 0, 0, 0, 233, 12, 1, 0, 0, 139, 133, 8, 255, 255, 255, 137, 133, 36, 255, 255, 255, 139, 133, 0, 255, 255, 255, 137, 133, 40, 255, 255, 255, 49, 192, 139, 141, 4, 255, 255, 255, 59, 200, 184, 255, 255, 255, 255, 116, 1, 64, 133, 192, 15, 132, 18, 0, 0, 0, 106, 0, 255, 21, 64, 65, 32, 0, 217, 109, 240, 232, 27, 11, 0, 0, 235, 6, _
    219, 133, 4, 255, 255, 255, 219, 157, 44, 255, 255, 255, 49, 192, 139, 141, 252, 254, 255, 255, 59, 200, 184, 255, 255, 255, 255, 116, 1, 64, 133, 192, 15, 132, 18, 0, 0, 0, 106, 1, 255, 21, 64, 65, 32, 0, 217, 109, 240, 232, 227, 10, 0, 0, 235, 6, 219, 133, 252, 254, 255, 255, 219, 157, 48, 255, 255, 255, 131, 189, 8, 255, 255, 255, 0, 15, 132, 34, 0, 0, 0, 131, 189, 0, 255, 255, 255, 0, 15, 132, 21, 0, 0, 0, 106, 40, 141, 157, 12, 255)
    
    ar5 = Array(255, 255, 83, 255, 117, 20, 255, 21, 100, 65, 32, 0, 217, 109, 240, 199, 133, 104, 255, 255, 255, 1, 0, 0, 0, 233, 70, 0, 0, 0, 186, 148, 58, 32, 0, 232, 88, 11, 0, 0, 106, 0, 139, 220, 232, 210, 10, 0, 0, 255, 117, 8, 255, 21, 76, 65, 32, 0, 217, 109, 240, 137, 5, 116, 58, 32, 0, 255, 117, 20, 255, 117, 16, 255, 117, 12, 255, 117, 8, 255, 53, 116, 58, 32, 0, 255, 21, 60, 65, 32, 0, 217, 109, 240, 137, 133, 104, 255, 255, 255, _
    139, 133, 104, 255, 255, 255, 141, 101, 244, 95, 94, 91, 93, 194, 16, 0, 0, 0, 0, 0, 0, 0, 0, 28, 24, 32, 0, 0, 0, 0, 0, 112, 98, 85, 139, 236, 83, 86, 87, 104, 63, 19, 0, 0, 131, 236, 112, 104, 217, 23, 32, 0, 49, 246, 86, 86, 86, 86, 184, 255, 255, 0, 0, 139, 93, 8, 35, 3, 139, 93, 12, 137, 3, 184, 0, 0, 1, 0, 139, 93, 8, 137, 69, 208, 139, 3, 153, 247, 125, 208, 37, 255, 255, 0, 0, 139, 93, 16, 137, 3, _
    141, 101, 244, 95, 94, 91, 93, 194, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 35, 0, 0, 112, 35, 0, 35, 0, 0, 35, 112, 0, 0, 0, 0, 129, 35, 0, 0, 112, 35, 0, 35, 0, 0, 35, 112, 0, 0, 0, 0, 130, 35, 0, 0, 112, 35, 0, 35, 0, 0, 35, 112, 0, 0, 0, 0, 131, 35, 0, 0, 112, 35, 0, 35, 0, 0, 35, 112, 0, 0, 0, 0, 132, 35, 0, 0, 112, 35, 0, 35, 0, 0, 35, 112, 0, _
    0, 0, 0, 133, 35, 0, 0, 112, 35, 0, 35, 0, 0, 35, 112, 0, 0, 0, 0, 134, 35, 0, 0, 112, 35, 0, 35, 0, 0, 35, 112, 0, 0, 0, 0, 135, 35, 0, 0, 112, 35, 0, 35, 0, 0, 35, 112, 0, 0, 0, 0, 136, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 192, 0, 0, 0, 0, 0, 0, 70, 1, 0, 0, 0, 0, 0, 0, 0, 192, 0, 0, 0, 0, 0, 0, 70, 132, 178, 150, 177, 180, 186, 26, 16, 182, 156, 0, 170, _
    0, 52, 29, 7, 134, 178, 150, 177, 180, 186, 26, 16, 182, 156, 0, 170, 0, 52, 29, 7, 0, 4, 2, 0, 0, 0, 0, 0, 192, 0, 0, 0, 0, 0, 0, 70, 35, 0, 0, 112, 35, 0, 35, 0, 0, 35, 112, 0, 0, 0, 0, 17, 35, 0, 0, 112, 35, 0, 35, 0, 0, 35, 112, 0, 0, 0, 0, 18, 35, 0, 0, 112, 35, 0, 35, 0, 0, 35, 112, 0, 0, 0, 0, 19, 35, 0, 0, 112, 35, 0, 35, 0, 0, 35, 112, 0, 0, 0, 0, 20, _
    35, 0, 0, 112, 35, 0, 35, 0, 0, 35, 112, 0, 0, 0, 0, 21, 35, 0, 0, 112, 35, 0, 35, 0, 0, 35, 112, 0, 0, 0, 0, 22, 35, 0, 0, 112, 35, 0, 35, 0, 0, 35, 112, 0, 0, 0, 0, 23, 35, 0, 0, 112, 35, 0, 35, 0, 0, 35, 112, 0, 0, 0, 0, 24, 35, 0, 0, 112, 35, 0, 35, 0, 0, 35, 112, 0, 0, 0, 0, 25, 0, 0, 35, 112, 0, 0, 0, 0, 129, 92, 0, 0, 0, 0, 66, 0, 0, 0, 0, 0, _
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 14, 0, 100, 0, 225, 255, 66, 98, 72, 104, 79, 111, 81, 113, 8, 8, 8, 8, 16, 16, 2, 2, 63, 19, 50, 19, 63, 27, 63, 31, 63, 23, 5, 132, 0, 64, 28, 70, 0, 0, 200, 66, 0, 0, 0, 127, 0, 0, 0, 63, 0, 0, 192, 255, 0, 0, 128, 127, 53, 194, 104, 33, 162, 218, 15, 201, 255, 63, 53, 194, 104, 33, 162, 218, 15, 201, 254, 63, _
    133, 100, 222, 249, 51, 243, 4, 181, 255, 63, 0, 66, 192, 255, 0, 72, 192, 255, 0, 74, 192, 255, 80, 0, 111, 0, 119, 0, 101, 0, 114, 0, 66, 0, 65, 0, 83, 0, 73, 0, 67, 0, 0, 0, 67, 79, 78, 73, 78, 36, 0, 116, 99, 112, 0, 144, 0, 0, 0, 1, 128, 0, 0, 0, 44, 34, 161, 28, 32, 0, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 85, 139, 236, 83, 86, 87, 187, 0, 48, 32, 0, 102)
    
    ar6 = Array(247, 5, 74, 26, 32, 0, 0, 1, 117, 5, 233, 30, 2, 0, 0, 233, 44, 4, 0, 0, 255, 21, 24, 65, 32, 0, 131, 248, 255, 249, 116, 64, 137, 131, 224, 5, 0, 0, 199, 131, 232, 5, 0, 0, 0, 0, 0, 0, 232, 235, 2, 0, 0, 114, 41, 137, 131, 228, 5, 0, 0, 199, 64, 104, 1, 0, 0, 0, 199, 64, 108, 1, 0, 0, 0, 199, 64, 112, 2, 0, 0, 0, 199, 64, 116, 3, 0, 0, 0, 199, 64, 120, 0, 0, 0, 0, 195, 232, 243, 2, _
    0, 0, 114, 12, 255, 179, 224, 5, 0, 0, 255, 21, 28, 65, 32, 0, 195, 233, 18, 245, 255, 255, 139, 55, 131, 199, 4, 209, 238, 114, 20, 116, 17, 209, 238, 115, 37, 193, 230, 2, 139, 52, 51, 232, 84, 6, 0, 0, 235, 228, 195, 209, 238, 114, 35, 193, 230, 2, 184, 1, 0, 0, 0, 83, 3, 222, 232, 130, 1, 0, 0, 91, 235, 204, 193, 230, 2, 139, 12, 51, 227, 196, 81, 139, 9, 255, 81, 8, 235, 188, 193, 230, 2, 141, 12, 51, 81, 255, 21, 52, _
    65, 32, 0, 235, 173, 131, 248, 1, 124, 7, 61, 255, 0, 0, 0, 126, 2, 176, 5, 233, 100, 1, 0, 0, 187, 0, 48, 32, 0, 131, 187, 0, 6, 0, 0, 1, 117, 31, 232, 136, 0, 0, 0, 232, 157, 0, 0, 0, 232, 116, 0, 0, 0, 102, 247, 5, 74, 26, 32, 0, 0, 2, 116, 5, 232, 96, 4, 0, 0, 90, 51, 219, 51, 246, 51, 255, 83, 139, 236, 83, 86, 87, 104, 63, 19, 0, 0, 131, 236, 112, 83, 83, 83, 83, 83, 255, 226, 253, 139, 75, _
    24, 141, 115, 32, 3, 241, 78, 139, 123, 28, 3, 251, 3, 249, 79, 243, 164, 185, 16, 0, 0, 0, 141, 187, 79, 10, 0, 0, 243, 164, 51, 192, 102, 137, 131, 248, 5, 0, 0, 137, 131, 228, 5, 0, 0, 199, 131, 228, 8, 0, 0, 148, 0, 0, 0, 1, 155, 68, 10, 0, 0, 1, 155, 76, 10, 0, 0, 252, 195, 104, 63, 19, 0, 0, 217, 44, 36, 88, 195, 252, 51, 192, 139, 139, 64, 10, 0, 0, 139, 187, 68, 10, 0, 0, 193, 233, 2, 243, 171, 232, _
    184, 3, 0, 0, 195, 252, 187, 0, 48, 32, 0, 51, 192, 185, 140, 5, 0, 0, 141, 123, 16, 243, 170, 72, 185, 64, 0, 0, 0, 141, 187, 156, 5, 0, 0, 243, 170, 195, 60, 97, 114, 6, 60, 122, 119, 2, 52, 32, 195, 102, 131, 56, 34, 117, 19, 131, 192, 2, 102, 131, 56, 34, 117, 247, 131, 192, 2, 102, 131, 56, 32, 116, 247, 195, 102, 131, 56, 32, 116, 11, 131, 192, 2, 102, 131, 56, 32, 119, 247, 114, 9, 131, 192, 2, 102, 131, 56, 32, 116, 247, _
    195, 82, 80, 106, 64, 255, 21, 16, 65, 32, 0, 90, 133, 192, 116, 1, 195, 176, 7, 249, 195, 133, 192, 116, 13, 82, 80, 255, 21, 20, 65, 32, 0, 90, 133, 192, 117, 1, 195, 176, 241, 249, 195, 186, 52, 0, 0, 0, 235, 19, 186, 5, 0, 0, 0, 235, 12, 186, 244, 0, 0, 0, 235, 5, 186, 99, 0, 0, 0, 182, 176, 102, 137, 149, 112, 255, 255, 255, 235, 11, 180, 176, 102, 137, 133, 112, 255, 255, 255, 51, 192, 246, 133, 112, 255, 255, 255, 255, 117, 9, _
    102, 199, 133, 112, 255, 255, 255, 51, 176, 80, 83, 81, 86, 87, 102, 139, 133, 114, 255, 255, 255, 102, 137, 69, 242, 139, 69, 200, 137, 69, 192, 139, 69, 204, 137, 69, 196, 232, 158, 0, 0, 0, 114, 23, 247, 64, 36, 255, 255, 255, 255, 116, 14, 247, 64, 32, 255, 255, 255, 255, 116, 5, 232, 146, 255, 255, 255, 139, 189, 124, 255, 255, 255, 139, 84, 36, 20, 59, 215, 114, 48, 59, 87, 246, 119, 43, 139, 79, 250, 227, 47, 51, 219, 51, 246, 138, 25, 65, 128, 251, _
    255, 117, 8, 129, 198, 254, 0, 0, 0, 235, 240, 3, 243, 3, 254, 59, 250, 114, 230, 137, 120, 44, 43, 254, 137, 120, 40, 235, 9, 102, 129, 165, 112, 255, 255, 255, 255, 127, 102, 247, 5, 74, 26, 32, 0, 0, 32, 116, 22, 247, 133, 116, 255, 255, 255, 255, 255, 255, 255, 117, 10, 232, 47, 255, 255, 255, 131, 248, 1, 117, 15, 128, 189, 112, 255, 255, 255, 241, 115, 6, 95, 94, 89, 91, 88, 195, 104, 255, 0, 0, 0, 255, 21, 0, 65, 32, 0, 176, 0, 207)
End Sub

Private Sub GetDllBytes2()
    ar7 = Array(81, 82, 232, 181, 0, 0, 0, 117, 45, 161, 76, 26, 32, 0, 232, 194, 254, 255, 255, 114, 33, 232, 177, 0, 0, 0, 86, 87, 252, 185, 5, 0, 0, 0, 139, 53, 228, 53, 32, 0, 133, 246, 116, 8, 141, 118, 104, 141, 120, 104, 243, 165, 95, 94, 90, 89, 195, 83, 81, 82, 86, 87, 232, 121, 0, 0, 0, 116, 103, 139, 216, 139, 61, 60, 54, 32, 0, 232, 8, 253, 255, 255, 51, 201, 135, 75, 32, 227, 7, 81, 255, 21, 252, 64, 32, 0, 51, 201, 135, 75, _
    8, 227, 7, 81, 255, 21, 4, 65, 32, 0, 139, 75, 60, 232, 60, 0, 0, 0, 139, 75, 64, 232, 52, 0, 0, 0, 139, 75, 68, 232, 44, 0, 0, 0, 139, 75, 88, 232, 36, 0, 0, 0, 139, 75, 92, 232, 28, 0, 0, 0, 139, 75, 96, 232, 20, 0, 0, 0, 139, 195, 232, 68, 254, 255, 255, 51, 192, 232, 31, 0, 0, 0, 95, 94, 90, 89, 91, 195, 227, 7, 81, 255, 21, 48, 65, 32, 0, 195, 255, 53, 224, 53, 32, 0, 255, 21, 32, 65, 32, 0, _
    133, 192, 195, 80, 80, 255, 53, 224, 53, 32, 0, 255, 21, 36, 65, 32, 0, 88, 100, 103, 139, 22, 24, 0, 137, 66, 20, 133, 192, 117, 7, 255, 13, 232, 53, 32, 0, 195, 255, 5, 232, 53, 32, 0, 195, 15, 182, 133, 112, 255, 255, 255, 195, 51, 192, 195, 51, 192, 102, 135, 133, 112, 255, 255, 255, 15, 182, 192, 195, 102, 199, 133, 112, 255, 255, 255, 0, 0, 195, 136, 133, 112, 255, 255, 255, 195, 135, 219, 131, 125, 12, 1, 15, 133, 150, 0, 0, 0, 232, 218, _
    252, 255, 255, 199, 131, 220, 5, 0, 0, 0, 0, 0, 0, 141, 131, 228, 8, 0, 0, 80, 255, 21, 12, 65, 32, 0, 102, 139, 13, 74, 26, 32, 0, 139, 147, 244, 8, 0, 0, 102, 247, 193, 32, 0, 117, 17, 131, 250, 2, 116, 27, 102, 247, 193, 64, 0, 117, 5, 233, 166, 0, 0, 0, 232, 157, 253, 255, 255, 129, 139, 220, 5, 0, 0, 128, 0, 0, 0, 255, 21, 8, 65, 32, 0, 232, 28, 253, 255, 255, 137, 131, 240, 5, 0, 0, 139, 69, 8, 137, 131, _
    252, 5, 0, 0, 139, 69, 16, 137, 131, 4, 6, 0, 0, 232, 82, 251, 255, 255, 114, 109, 102, 255, 131, 248, 5, 0, 0, 15, 183, 13, 72, 26, 32, 0, 227, 12, 81, 106, 8, 84, 255, 21, 244, 64, 32, 0, 88, 88, 139, 69, 12, 137, 131, 0, 6, 0, 0, 83, 232, 134, 251, 255, 255, 91, 131, 187, 0, 6, 0, 0, 3, 117, 5, 232, 91, 254, 255, 255, 131, 187, 0, 6, 0, 0, 0, 117, 42, 139, 139, 220, 0, 0, 0, 232, 45, 0, 0, 0, 139, 139, _
    184, 0, 0, 0, 227, 7, 81, 255, 21, 4, 65, 32, 0, 139, 187, 56, 6, 0, 0, 232, 78, 251, 255, 255, 232, 48, 251, 255, 255, 15, 183, 131, 248, 5, 0, 0, 95, 94, 91, 93, 194, 12, 0, 227, 7, 81, 255, 21, 252, 64, 32, 0, 195, 135, 219, 144, 51, 192, 137, 131, 32, 6, 0, 0, 137, 131, 36, 6, 0, 0, 137, 131, 40, 6, 0, 0, 141, 131, 196, 0, 0, 0, 137, 131, 44, 6, 0, 0, 195, 190, 0, 48, 32, 0, 185, 204, 0, 0, 0, 232, _
    56, 1, 0, 0, 252, 51, 192, 193, 233, 2, 243, 171, 137, 150, 36, 6, 0, 0, 199, 66, 4, 1, 0, 0, 0, 199, 66, 8, 1, 0, 0, 0, 199, 66, 36, 0, 32, 0, 0, 199, 66, 40, 0, 0, 0, 65, 199, 66, 64, 144, 1, 0, 0, 198, 66, 71, 0, 232, 13, 0, 0, 0, 77, 83, 32, 83, 97, 110, 115, 32, 83, 101, 114, 105, 102, 252, 51, 192, 185, 13, 0, 0, 0, 94, 141, 122, 76, 172, 102, 171, 226, 251, 185, 204, 0, 0, 0, 232, 214, 0)
    
    ar8 = Array(0, 0, 252, 51, 192, 193, 233, 2, 243, 171, 190, 0, 48, 32, 0, 139, 134, 36, 6, 0, 0, 137, 16, 199, 66, 4, 1, 0, 0, 0, 199, 66, 8, 2, 0, 0, 0, 199, 66, 36, 0, 32, 0, 0, 199, 66, 40, 0, 0, 0, 0, 199, 66, 64, 144, 1, 0, 0, 198, 66, 71, 0, 198, 66, 75, 1, 232, 14, 0, 0, 0, 76, 117, 99, 105, 100, 97, 32, 67, 111, 110, 115, 111, 108, 101, 252, 51, 192, 185, 14, 0, 0, 0, 94, 141, 122, 76, 172, 102, 171, _
    226, 251, 185, 204, 0, 0, 0, 232, 104, 0, 0, 0, 252, 51, 192, 193, 233, 2, 243, 171, 190, 0, 48, 32, 0, 139, 134, 36, 6, 0, 0, 139, 0, 137, 16, 199, 66, 4, 1, 0, 0, 0, 199, 66, 8, 3, 0, 0, 0, 199, 66, 36, 0, 32, 0, 0, 199, 66, 40, 0, 0, 48, 65, 199, 66, 64, 144, 1, 0, 0, 198, 66, 71, 0, 198, 66, 75, 1, 232, 14, 0, 0, 0, 76, 117, 99, 105, 100, 97, 32, 67, 111, 110, 115, 111, 108, 101, 252, 51, 192, _
    185, 14, 0, 0, 0, 94, 141, 122, 76, 172, 102, 171, 226, 251, 195, 144, 227, 22, 80, 81, 81, 106, 0, 255, 21, 44, 65, 32, 0, 89, 133, 192, 116, 14, 139, 208, 139, 248, 88, 195, 51, 210, 191, 196, 48, 32, 0, 195, 185, 0, 0, 0, 0, 139, 209, 191, 196, 48, 32, 0, 88, 184, 7, 0, 0, 0, 249, 195, 247, 198, 1, 0, 0, 0, 117, 17, 133, 246, 116, 13, 80, 81, 82, 86, 255, 21, 48, 65, 32, 0, 90, 89, 88, 248, 195, 90, 227, 8, 94, 232, _
    220, 255, 255, 255, 226, 248, 255, 226, 131, 230, 254, 116, 6, 139, 78, 252, 133, 201, 195, 139, 206, 190, 196, 48, 32, 0, 195, 131, 231, 254, 116, 6, 139, 87, 252, 133, 210, 195, 139, 215, 191, 196, 48, 32, 0, 195, 83, 81, 87, 131, 230, 254, 232, 115, 255, 255, 255, 114, 57, 139, 217, 232, 198, 255, 255, 255, 59, 203, 114, 2, 139, 203, 43, 217, 252, 80, 86, 51, 192, 81, 193, 233, 2, 243, 165, 89, 131, 225, 3, 243, 164, 139, 203, 209, 233, 243, 102, 171, 128, 209, _
    0, 243, 170, 94, 88, 232, 114, 255, 255, 255, 139, 242, 95, 89, 91, 195, 232, 103, 255, 255, 255, 95, 91, 91, 249, 195, 248, 195, 102, 152, 102, 137, 69, 148, 223, 69, 148, 195, 15, 183, 192, 137, 69, 148, 219, 69, 148, 195, 137, 69, 148, 199, 69, 152, 0, 0, 0, 0, 223, 109, 148, 195, 137, 69, 148, 137, 85, 152, 223, 109, 148, 195, 223, 125, 148, 138, 69, 148, 195, 223, 125, 148, 102, 139, 69, 148, 195, 223, 125, 148, 139, 69, 148, 195, 135, 219, 86, 131, 173, 120, _
    255, 255, 255, 4, 139, 181, 120, 255, 255, 255, 131, 202, 1, 137, 84, 53, 148, 94, 195, 86, 87, 139, 181, 120, 255, 255, 255, 139, 116, 53, 148, 131, 133, 120, 255, 255, 255, 4, 247, 198, 1, 0, 0, 0, 116, 5, 131, 230, 254, 117, 10, 135, 51, 232, 222, 254, 255, 255, 95, 94, 195, 232, 254, 254, 255, 255, 139, 59, 11, 255, 116, 5, 59, 79, 252, 116, 32, 232, 146, 254, 255, 255, 114, 41, 252, 81, 193, 233, 2, 243, 165, 89, 131, 225, 3, 243, 164, 135, 19, 139, _
    242, 232, 174, 254, 255, 255, 95, 94, 195, 252, 81, 193, 233, 2, 243, 165, 89, 131, 225, 3, 243, 164, 95, 94, 195, 135, 19, 139, 242, 232, 146, 254, 255, 255, 95, 94, 233, 231, 249, 255, 255, 135, 219, 144, 86, 131, 173, 120, 255, 255, 255, 4, 139, 181, 120, 255, 255, 255, 131, 202, 1, 137, 84, 53, 148, 94, 195, 144, 137, 133, 116, 255, 255, 255, 102, 129, 165, 112, 255, 255, 255, 255, 127, 195, 51, 192, 102, 247, 133, 112, 255, 255, 255, 0, 16, 116, 4, 15, 183, 69)
    
    ar9 = Array(242, 195, 81, 86, 87, 51, 201, 141, 117, 192, 102, 247, 133, 112, 255, 255, 255, 0, 16, 116, 12, 128, 60, 14, 32, 116, 6, 65, 131, 249, 8, 114, 244, 232, 63, 0, 0, 0, 95, 94, 89, 195, 135, 219, 51, 210, 85, 131, 173, 120, 255, 255, 255, 4, 3, 173, 120, 255, 255, 255, 137, 85, 148, 93, 195, 86, 87, 232, 2, 0, 0, 0, 13, 10, 185, 2, 0, 0, 0, 94, 232, 16, 0, 0, 0, 95, 94, 195, 51, 201, 139, 214, 246, 2, 255, 116, 4, 65, 66, 235, _
    247, 131, 173, 120, 255, 255, 255, 4, 232, 171, 253, 255, 255, 252, 81, 193, 233, 2, 243, 165, 89, 131, 225, 3, 243, 164, 139, 181, 120, 255, 255, 255, 137, 84, 53, 148, 195, 135, 219, 144, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 80, 10, 0, 0, 76, 0, 0, 0, 144, 10, 0, 0, 6, 0, 0, 0, 87, 95, 80, 82, 79, 67, 0, 0, 252, 255, 255, 255, 49, 2, 0, 0, 50, 2, 0, 0, _
    20, 2, 0, 0, 5, 0, 0, 0, 22, 2, 0, 0, 6, 0, 0, 0, 18, 1, 0, 0, 16, 0, 0, 0, 36, 0, 0, 0, 50, 240, 0, 0, 48, 240, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 255, 255, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 126, 65, 0, 0, 252, 64, 0, 0, 176, 64, 0, 0)
    
    ar10 = Array(0, 0, 0, 0, 0, 0, 0, 0, 140, 65, 0, 0, 44, 65, 0, 0, 192, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 154, 65, 0, 0, 60, 65, 0, 0, 232, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 162, 65, 0, 0, 100, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 56, 66, 0, 0, 0, 0, 0, 0, 190, 65, 0, 0, 204, 65, 0, 0, 218, 65, 0, 0, 230, 65, 0, 0, _
    12, 66, 0, 0, 28, 66, 0, 0, 42, 66, 0, 0, 154, 66, 0, 0, 166, 66, 0, 0, 176, 66, 0, 0, 190, 66, 0, 0, 0, 0, 0, 0, 114, 66, 0, 0, 138, 66, 0, 0, 204, 66, 0, 0, 0, 0, 0, 0, 172, 65, 0, 0, 248, 65, 0, 0, 80, 66, 0, 0, 96, 66, 0, 0, 220, 66, 0, 0, 232, 66, 0, 0, 244, 66, 0, 0, 40, 67, 0, 0, 68, 67, 0, 0, 0, 0, 0, 0, 2, 67, 0, 0, 18, 67, 0, 0, 0, 0, 0, 0, _
    56, 66, 0, 0, 0, 0, 0, 0, 190, 65, 0, 0, 204, 65, 0, 0, 218, 65, 0, 0, 230, 65, 0, 0, 12, 66, 0, 0, 28, 66, 0, 0, 42, 66, 0, 0, 154, 66, 0, 0, 166, 66, 0, 0, 176, 66, 0, 0, 190, 66, 0, 0, 0, 0, 0, 0, 114, 66, 0, 0, 138, 66, 0, 0, 204, 66, 0, 0, 0, 0, 0, 0, 172, 65, 0, 0, 248, 65, 0, 0, 80, 66, 0, 0, 96, 66, 0, 0, 220, 66, 0, 0, 232, 66, 0, 0, 244, 66, 0, 0, _
    40, 67, 0, 0, 68, 67, 0, 0, 0, 0, 0, 0, 2, 67, 0, 0, 18, 67, 0, 0, 0, 0, 0, 0, 67, 79, 77, 67, 84, 76, 51, 50, 46, 68, 76, 76, 0, 0, 75, 69, 82, 78, 69, 76, 51, 50, 46, 68, 76, 76, 0, 0, 79, 76, 69, 65, 85, 84, 51, 50, 46, 68, 76, 76, 0, 0, 85, 83, 69, 82, 51, 50, 0, 0, 75, 69, 82, 78, 69, 76, 51, 50, 0, 0, 0, 0, 67, 97, 108, 108, 87, 105, 110, 100, 111, 119, 80, 114, 111, 99, _
    65, 0, 0, 0, 67, 108, 111, 115, 101, 72, 97, 110, 100, 108, 101, 0, 0, 0, 69, 120, 105, 116, 80, 114, 111, 99, 101, 115, 115, 0, 0, 0, 70, 105, 110, 100, 67, 108, 111, 115, 101, 0, 0, 0, 71, 101, 116, 67, 111, 109, 109, 97, 110, 100, 76, 105, 110, 101, 87, 0, 0, 0, 71, 101, 116, 83, 121, 115, 116, 101, 109, 77, 101, 116, 114, 105, 99, 115, 0, 0, 0, 0, 71, 101, 116, 86, 101, 114, 115, 105, 111, 110, 69, 120, 65, 0, 0, 0, 71, 108, _
    111, 98, 97, 108, 65, 108, 108, 111, 99, 0, 0, 0, 71, 108, 111, 98, 97, 108, 70, 114, 101, 101, 0, 0, 0, 0, 73, 110, 105, 116, 67, 111, 109, 109, 111, 110, 67, 111, 110, 116, 114, 111, 108, 115, 69, 120, 0, 0, 0, 0, 80, 111, 115, 116, 77, 101, 115, 115, 97, 103, 101, 65, 0, 0, 0, 0, 83, 101, 116, 87, 105, 110, 100, 111, 119, 76, 111, 110, 103, 65, 0, 0, 0, 0, 83, 121, 115, 65, 108, 108, 111, 99, 83, 116, 114, 105, 110, 103, 66, 121, _
    116, 101, 76, 101, 110, 0, 0, 0, 83, 121, 115, 70, 114, 101, 101, 83, 116, 114, 105, 110, 103, 0, 0, 0, 84, 108, 115, 65, 108, 108, 111, 99, 0, 0, 0, 0, 84, 108, 115, 70, 114, 101, 101, 0, 0, 0, 84, 108, 115, 71, 101, 116, 86, 97, 108, 117, 101, 0, 0, 0, 84, 108, 115, 83, 101, 116, 86, 97, 108, 117, 101, 0, 0, 0, 86, 97, 114, 105, 97, 110, 116, 67, 108, 101, 97, 114, 0, 0, 0, 0, 71, 101, 116, 80, 114, 111, 112, 65, 0, 0, _
    0, 0, 83, 101, 116, 80, 114, 111, 112, 65, 0, 0, 0, 0, 82, 101, 109, 111, 118, 101, 80, 114, 111, 112, 65, 0, 0, 0, 82, 116, 108, 77, 111, 118, 101, 77, 101, 109, 111, 114, 121, 0, 0, 0, 71, 101, 116, 67, 117, 114, 114, 101, 110, 116, 80, 114, 111, 99, 101, 115, 115, 73, 100, 0, 0, 0, 71, 101, 116, 87, 105, 110, 100, 111, 119, 84, 104, 114, 101, 97, 100, 80, 114, 111, 99, 101, 115, 115, 73, 100, 0, 0, 0, 0, 73, 115, 73, 99, 111, 110)
    
    ar11 = Array(105, 99, 0, 0, 0, 0, 0, 0, 40, 67, 49, 0, 0, 0, 0, 0, 140, 67, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 120, 67, 0, 0, 128, 67, 0, 0, 136, 67, 0, 0, 106, 16, 0, 0, 137, 17, 0, 0, 153, 67, 0, 0, 158, 67, 0, 0, 0, 0, 1, 0, 119, 110, 100, 69, 118, 101, 110, 116, 46, 100, 108, 108, 0, 72, 79, 79, 75, 0, 85, 78, 72, 79, 79, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 20, 1, 0, 0, 7, 48, 11, 48, 17, 48, 21, 48, 27, 48, 31, 48, _
    37, 48, 41, 48, 47, 48, 51, 48, 57, 48, 61, 48, 67, 48, 71, 48, 77, 48, 81, 48, 96, 48, 121, 48, 150, 48, 165, 48, 177, 48, 189, 48, 201, 48, 213, 48, 225, 48, 237, 48, 249, 48, 5, 49, 12, 49, 35, 49, 55, 49, 67, 49, 80, 49, 103, 49, 127, 49, 152, 49, 166, 49, 189, 49, 209, 49, 232, 49, 251, 49, 3, 50, 26, 50, 50, 50, 75, 50, 114, 50, 124, 50, 147, 50, 157, 50, 192, 50, 225, 50, 231, 50, 9, 51, 42, 51, 48, 51, 116, 51, _
    134, 51, 163, 51, 169, 51, 183, 51, 209, 51, 238, 51, 244, 51, 32, 52, 50, 52, 56, 52, 75, 52, 91, 52, 119, 52, 125, 52, 139, 52, 159, 52, 180, 52, 186, 52, 244, 52, 250, 52, 38, 53, 61, 53, 87, 53, 95, 53, 118, 53, 136, 53, 155, 53, 196, 53, 202, 53, 211, 53, 226, 53, 243, 53, 54, 54, 110, 54, 150, 54, 226, 54, 26, 55, 92, 55, 115, 55, 138, 55, 147, 55, 165, 55, 171, 55, 207, 55, 232, 55, 138, 58, 228, 58, 59, 59, 111, 60, 133, 60, _
    240, 61, 254, 61, 88, 62, 105, 62, 141, 61, 75, 62, 118, 58, 116, 59, 158, 61, 89, 61, 111, 58, 85, 59, 11, 60, 184, 61, 221, 61, 82, 62, 99, 62, 125, 62, 132, 62, 82, 58, 221, 62, 78, 63, 66, 63, 214, 62, 16, 63, 145, 63, 184, 63, 226, 63, 0, 32, 0, 0, 24, 0, 0, 0, 91, 48, 201, 48, 49, 49, 110, 49, 67, 49, 80, 49, 146, 49, 165, 49, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
End Sub

Sub BuildDll(ByVal DLL_PATH_NAME As String)
    Dim i As Long
    Dim lPos As Long
    Dim FileNum As Long
    Dim dllBytesArray As Variant
    Dim tempArray() As Variant
    Dim Bytes() As Byte
    Call GetDllBytes1
    Call GetDllBytes2
    dllBytesArray = Array(ar1, ar2, ar3, ar4, ar5, ar6, ar7, ar8, ar9, ar10, ar11)
    tempArray = dllBytesArray(0)
    lPos = UBound(tempArray)
    For i = 0 To UBound(dllBytesArray) - 1
        lPos = UBound(tempArray)
        ReDim Preserve tempArray(UBound(tempArray) + UBound(dllBytesArray(i + 1)) + 1)
        CopyMemory ByVal VarPtr(tempArray(lPos + 1)), _
        ByVal VarPtr(dllBytesArray(i + 1)(0)), 16 * (UBound(dllBytesArray(i + 1)) + 1)
    Next i
    ReDim Bytes(LBound(tempArray) To UBound(tempArray))
    For i = LBound(tempArray) To UBound(tempArray)
        Bytes(i) = CByte(tempArray(i))
    Next i
    FileNum = FreeFile
    Open DLL_PATH_NAME For Binary As #FileNum
        Put #FileNum, 1, Bytes
    Close FileNum
End Sub

3- And finally, the code for the event handlers also located in a Standard Module ( EventHandlers_bas )
Code:
Option Explicit
[B][COLOR=#008000]'///////////////////////////////////////////////
'//HAVE AN ERROR HANDLER IN EACH EVENT PROC !!//
'///////////////////////////////////////////////[/COLOR][/B]
Public Function Application_WindowMinMaxSize(ByRef MinWidth As Long, ByRef MaxWidth As Long, _
ByRef MinHeight As Long, ByRef MaxHeight As Long) As Long
    On Error Resume Next
    MinWidth = 600
    MinHeight = 400
    With ThisWorkbook.Sheets(1)
        .Range("E11") = MinWidth
        .Range("E12") = MinHeight
    End With
End Function

Public Function Application_WindowResizing _
(ByVal Left As Long, ByVal Top As Long, ByVal Right As Long, ByVal Bottom As Long) As Long
    On Error Resume Next
    With ThisWorkbook.Sheets(1)
        .Range("E15") = Left
        .Range("E16") = Top
        .Range("E17") = Right
        .Range("E18") = Bottom
    End With
End Function

Public Function Application_WindowMoving _
(ByVal Left As Long, ByVal Top As Long, ByVal Right As Long, ByVal Bottom As Long) As Long
    On Error Resume Next
    With ThisWorkbook.Sheets(1)
        .Range("E21") = Left
        .Range("E22") = Top
        .Range("E23") = Right
        .Range("E24") = Bottom
    End With
End Function
    
[B][COLOR=#008000]'////////////////////////////////////////
'//DO NOT USE THE 'Dummy' PARAMETERS !!//
'////////////////////////////////////////
[/COLOR][/B]Public Function Application_WindowActivate _
(ByVal Dummy1 As Long, ByVal Dummy2 As Long, ByVal Dummy3 As Long, ByVal Dummy4 As Long) As Long
    On Error Resume Next
    MsgBox "App Activated"
End Function

Public Function Application_WindowDeActivate _
(ByVal Dummy1 As Long, ByVal Dummy2 As Long, ByVal Dummy3 As Long, ByVal Dummy4 As Long) As Long
    On Error Resume Next
    MsgBox "App Deactivated"
End Function

Public Function Application_WindowMaximize _
(ByVal Dummy1 As Long, ByVal Dummy2 As Long, ByVal Dummy3 As Long, ByVal Dummy4 As Long) As Long
    On Error Resume Next
    MsgBox "App Maximized"
End Function

Public Function Application_WindowMinimise _
(ByVal Dummy1 As Long, ByVal Dummy2 As Long, ByVal Dummy3 As Long, ByVal Dummy4 As Long) As Long
    On Error Resume Next
    MsgBox "App Minimised"
End Function

Public Function Application_WindowRestore _
(ByVal Dummy1 As Long, ByVal Dummy2 As Long, ByVal Dummy3 As Long, ByVal Dummy4 As Long) As Long
    On Error Resume Next
    MsgBox "App Restored"
End Function

Public Function Application_WindowBeforeClose _
(ByRef Cancel As Boolean, ByRef Dummy1 As Long, ByRef Dummy2 As Long, ByRef Dummy3 As Long) As Long
    On Error Resume Next
    Dim lRes As VbMsgBoxResult
    lRes = MsgBox("Proceed closing Excel ?", vbQuestion + vbYesNo)
    If lRes = vbNo Then
        Cancel = True
    End If
End Function

I have written and tested the code on Excel 2007 Win XP so I am not sure how stable this will be on other platforms... Any feedback will be much appreciated
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Just tested the code today in 32 bit Office on Windows 7 64 bit and worked - Obviously the code won't work for 64 bit versions of excel without editing the API declarations.

On a different note, one may get a runtime error when starting the hook code - This happend to me on the Win 7 machine as it seems that it dosen't allow to save files directly to the root C:\ drive... Changing the DLL_PATH_NAME Const located at the top of the Hook_bas module and making it point to a different disk location (like to the CurDir or ThisWorkbook.Path) solved the problem

by the way merry xmas to everyone !
 
Upvote 0

Forum statistics

Threads
1,215,703
Messages
6,126,320
Members
449,308
Latest member
Ronaldj

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top