Sign in to follow this  
Followers 0
greenmachine

Unregister Guiregistermsg Message

2 posts in this topic

#1 ·  Posted (edited)

Is there a way to unregister a message registered by GuiRegisterMsg? I thought that it would have the format of HotKeySet if it were possible, but it doesn't appear to work like that. Should I simply re-route the msg to a dummy function when I don't want it, and route it back to the real function when I do? I just thought about that, and that may have to be the workaround, but I was still wondering if it would be possible to unregister the registered messages instead of being forced to have them registered at all times (once initially registered).

Edit - it doesn't appear that you can change the function either... once it's registered to a certain function, it doesn't move.

Edited by greenmachine

Share this post


Link to post
Share on other sites



New findings. Turns out you can't actually call GuiRegisterMsg with "" as the function name (it freaks and errors out). Also, when changing the registered msg to a dummy func, it must be called twice in succession in order for it to work.

Here's the code I used to test. Thanks to LazyCat for coming up with it.

HotKeySet ("1", "SetMSG")
HotKeySet ("2", "UnSetMSG")
Global Const $WM_WINDOWPOSCHANGING = 0x0046
Global Const $SPI_GETWORKAREA = 0x30

Global $nGap = 30, $nEdge = BitOR(1, 2, 4, 8); Left, Top, Right, Bottom

$hGUI = GUICreate("Snapped window", 300, 200)

GUISetState()

While 1
    $GUIMsg = GUIGetMsg()
    
    Switch $GUIMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Func SetMSG()
    $IsSet = GUIRegisterMsg($WM_WINDOWPOSCHANGING, "MY_WM_WINDOWPOSCHANGING")
    MsgBox (0, "Set Docking?", $IsSet)
EndFunc

Func UnSetMSG()
    $IsSet = GUIRegisterMsg($WM_WINDOWPOSCHANGING, "Dummy")
    MsgBox (0, "UnSet Docking?", $IsSet)
EndFunc

Func Dummy()
    TrayTip ("should be...", "in dummy", 1)
   ; dummy
EndFunc

Func MY_WM_WINDOWPOSCHANGING($hWnd, $Msg, $wParam, $lParam)
#cs
    HWND hwnd;
    HWND hwndInsertAfter;
    int x;
    int y;
    int cx;
    int cy;
    UINT flags;
#ce
    Local $stRect = DllStructCreate("int;int;int;int")
    Local $stWinPos = DllStructCreate("uint;uint;int;int;int;int;uint", $lParam)
    DllCall("User32.dll", "int", "SystemParametersInfo", "int", $SPI_GETWORKAREA, "int", 0, "ptr", DllStructGetPtr($stRect), "int", 0)
    Local $nLeft   = DllStructGetData($stRect, 1)
    Local $nTop = DllStructGetData($stRect, 2)
    Local $nRight  = DllStructGetData($stRect, 3) - DllStructGetData($stWinPos, 5)
    Local $nBottom = DllStructGetData($stRect, 4) - DllStructGetData($stWinPos, 6)
    If BitAND($nEdge, 1) and Abs($nLeft   - DllStructGetData($stWinPos, 3)) <= $nGap Then DllStructSetData($stWinPos, 3, $nLeft)
    If BitAND($nEdge, 2) and Abs($nTop  - DllStructGetData($stWinPos, 4)) <= $nGap Then DllStructSetData($stWinPos, 4, $nTop)
    If BitAND($nEdge, 4) and Abs($nRight  - DllStructGetData($stWinPos, 3)) <= $nGap Then DllStructSetData($stWinPos, 3, $nRight)
    If BitAND($nEdge, 8) and Abs($nBottom - DllStructGetData($stWinPos, 4)) <= $nGap Then DllStructSetData($stWinPos, 4, $nBottom)
    Return 0
EndFunc

When I ran it, I initially moved the window near a border - no docking. Then I pressed 1, got the MsgBox, moved it toward a border, and got docking. Then I pressed 2, got the MsgBox declaring success, moved it toward a border, and it still docked. Then I pressed 2 again, got the MsgBox declaring success again, moved it toward a border, and this time it didn't dock. Interesting....

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0