;~~ @jugador #include-once Global $__g_hSubclassMap = ObjCreate("Scripting.Dictionary") Global $__g_hCallback = 0 OnAutoItExitRegister("__SubclassCleanup") ; #FUNCTION# ============================================================================= ; Name...........: GUIRegisterMsgEx ; ======================================================================================== Func GUIRegisterMsgEx($hWnd, $iMsgID, $sFunctionName, $pData = 0) Local Static $iCount = 0 If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) If Not IsHWnd($hWnd) Then Return SetError(1, 0, 0) Local $sKey = $hWnd & "_" & $iMsgID Local $sSubclassID = $hWnd & "_" & $iMsgID & "_sID" If $sFunctionName = "" Then If $__g_hSubclassMap.Exists($sKey) Then Local $iStoredID = $__g_hSubclassMap.Item($sSubclassID) $__g_hSubclassMap.Remove($sKey) DllCall("comctl32.dll", "bool", "RemoveWindowSubclass", "hwnd", $hWnd, "ptr", DllCallbackGetPtr($__g_hCallback), "uint_ptr", $iStoredID) EndIf Return True EndIf If $__g_hSubclassMap.Exists($sKey) Then $__g_hSubclassMap.Item($sKey) = $sFunctionName Return True EndIf If $__g_hCallback = 0 Then $__g_hCallback = DllCallbackRegister("__SubclassWndProc", "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr") EndIf Local $iAssignedID If $__g_hSubclassMap.Exists($sSubclassID) Then $iAssignedID = $__g_hSubclassMap.Item($sSubclassID) Else $iCount += 1 $iAssignedID = $iCount $__g_hSubclassMap.Item($sSubclassID) = $iAssignedID EndIf $__g_hSubclassMap.Item($sKey) = $sFunctionName DllCall("comctl32.dll", "bool", "SetWindowSubclass", _ "hwnd", $hWnd, _ "ptr", DllCallbackGetPtr($__g_hCallback), _ "uint_ptr", $iAssignedID, _ "dword_ptr", $pData) Return True EndFunc ; #FUNCTION# ============================================================================= ; Name...........: GUIRegisterMsgEx_Bypass ; ======================================================================================== Func GUIRegisterMsgEx_Bypass($hWnd, $bBypass, $pData = 0) If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) If $__g_hCallback = 0 Then Return False Local $aKeys = $__g_hSubclassMap.Keys() Local $sTargetPrefix = $hWnd & "_" For $sKey In $aKeys If StringLeft($sKey, StringLen($sTargetPrefix)) = $sTargetPrefix And StringInStr($sKey, "_sID") Then Local $iStoredID = $__g_hSubclassMap.Item($sKey) If $bBypass Then DllCall("comctl32.dll", "bool", "RemoveWindowSubclass", "hwnd", $hWnd, "ptr", DllCallbackGetPtr($__g_hCallback), "uint_ptr", $iStoredID) Else DllCall("comctl32.dll", "bool", "SetWindowSubclass", "hwnd", $hWnd, "ptr", DllCallbackGetPtr($__g_hCallback), "uint_ptr", $iStoredID, "dword_ptr", $pData) EndIf EndIf Next Return True EndFunc ;~~~~ internal use Func __SubclassWndProc($hWnd, $iMsg, $wParam, $lParam, $uIdSubclass, $dwRefData) Local $sKey = $hWnd & "_" & $iMsg If $__g_hSubclassMap.Exists($sKey) Then Local $sUserFunc = $__g_hSubclassMap.Item($sKey) Local $mResult = Call($sUserFunc, $hWnd, $iMsg, $wParam, $lParam, $uIdSubclass, $dwRefData) If $mResult <> 0xCAFEBABE Then Return $mResult EndIf EndIf Return DllCall("comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam)[0] EndFunc Func __SubclassCleanup() If $__g_hCallback <> 0 Then Local $aKeys = $__g_hSubclassMap.Keys() For $sKey In $aKeys If StringInStr($sKey, "_sID") Then ContinueLoop Local $sID = $__g_hSubclassMap.Item($sKey & "_sID") Local $aSplit = StringSplit($sKey, "_", 2) Local $hWnd = HWND($aSplit[0]) DllCall("comctl32.dll", "bool", "RemoveWindowSubclass", "hwnd", $hWnd, "ptr", DllCallbackGetPtr($__g_hCallback), "uint_ptr", $sID) Next EndIf $__g_hSubclassMap.RemoveAll() $__g_hSubclassMap = 0 If $__g_hCallback <> 0 Then DllCallbackFree($__g_hCallback) $__g_hCallback = 0 EndIf EndFunc