Jump to content
Advert

Recommended Posts

Posted (edited)
; #FUNCTION# ====================================================================================================================
; Name...........: _GUIRegisterMsgTell
; Description ...: A wrapper for GUIRegisterMsg that registers Windows messages while tracking their assigned function names.
; Syntax.........: _GUIRegisterMsgTell($msgID[, $function = Default])
; Parameters ....: $msgID    - The Windows message ID to intercept (e.g., $WM_COMMAND, $WM_NOTIFY).
;                  $function - [optional] The name of the user-defined function to call, or the function itself.
;                              If omitted or set to Default, the function operates in "Retrieve Mode".
;                              If set to "" (empty string), it explicitly unregisters the message ID.
; Return values .: Retrieve Mode ($function = Default):
;                    Success - Returns the registered function name as a string. (@error = 0, @extended = 0)
;                              Returns "" if explicitly unregistered by the user. (@error = 0, @extended = 0)
;                    Failure - Returns "" if the ID has never been touched by this script. (@error = 0, @extended = 1)
;                  Register Mode:
;                    Success - Returns 1 (Return value passed through from native GUIRegisterMsg).
;                    Failure - Returns 0 (Return value passed through from native GUIRegisterMsg).
; Author ........: argumentum
; Related .......: GUIRegisterMsg
; ===============================================================================================================================
Func _GUIRegisterMsgTell($msgID, $function = Default)
    Local Static $mFuncs[]
    Local $sFuncName, $sKey = String($msgID) ; due to AutoIt's Map integer/string bug

    If IsKeyword($function) Then
        If MapExists($mFuncs, $sKey) Then Return SetError(0, 0, $mFuncs[$sKey])
        Return SetError(0, 1, "") ; @error = 0, @extended = 1 (Never Touched flag)
    EndIf
    $sFuncName = (VarGetType($function) = "UserFunction" ? FuncName($function) : $function)
    $mFuncs[$sKey] = $sFuncName

    ;~     ConsoleWrite('+ _GUIRegisterMsgTell("' & $msgID & '", "' & $sFuncName & '")' & @CRLF)
    Return GUIRegisterMsg($msgID, $function)
EndFunc   ;==>_GUIRegisterMsgTell

Am working on my code and, is the message ID registered prior to my script by another script/UDF ? 🤔

Using this in your UDF will help us all have a way to know if that message was registered :)

Edit:
for example, something like this ?

...
Func _MsgGui_WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $hWndFrom, $iCode, $tNMHDR, $hWndListView
    $hWndListView = $g_idListview
    If Not IsHWnd($g_idListview) Then $hWndListView = GUICtrlGetHandle($g_idListview)

    ; my stuff
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the main mouse button
                    AdlibRegister(ListView_Event_OnDBLCLK, 20)
            EndSwitch
    EndSwitch


    ; and pass it along to the original 
    Return __GUIDarkTheme_WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
EndFunc   ;==>_MsgGui_WM_NOTIFY

...

 

Edited by argumentum
added an example

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting  image.gif.922e3a93535f431de08b31ee669cc446.gif
autoit_scripter_blue_userbar.png

Advert

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...