Jump to content

transparent movable windows with drop shadow


Go to solution Solved by Nine,

Recommended Posts

Posted (edited)

@Nine before ending this interesting thread, I have a last question if you don't mind.
Please have a look at my last script in the preceding post (the one which uses _WinAPI_SetWindowSubclass to subclass the button)

* The button seems correctly subclassed
* There is no call to _WinAPI_TrackMouseEvent() in the script
* $WM_MOUSELEAVE is triggered at the right moment.

Now the question : why $WM_MOUSEHOVER is never triggered when we use this part of code instead :

Func _BtnProc($hWnd, $iMsg, $wParam, $lParam, $IdSubclass, $dwRefData)

    Local Static $bHover, $iCounter = 0

    Switch $iMsg
        Case $WM_MOUSEMOVE
            If Not $bHover Then
                GUICtrlSetImage($dwRefData, @ScriptDir & "\OK 52-51.bmp")
                $bHover = True
            EndIf

        Case $WM_MOUSEHOVER ; never triggered :(
            $iCounter += 1
            ConsoleWrite("$WM_MOUSEHOVER : $iCounter = " & $iCounter & @crlf)

        Case $WM_MOUSELEAVE
            GUICtrlSetImage($dwRefData, @ScriptDir & "\Cancel 52-51.bmp")
            $bHover = False
            $iCounter += 1
            ConsoleWrite("$WM_MOUSELEAVE : $iCounter = " & $iCounter & @crlf)
    EndSwitch

    Return _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam)
EndFunc   ;==>_BtnProc

I mean, when the button is subclassed, if $WM_MOUSELEAVE is triggered without the use of _WinAPI_TrackMouseEvent() , then why $WM_MOUSEHOVER doesn't react the same way ?

Many thanks if you got the explanation... same thanks if you don't :D

Edited by pixelsearch
added to code the "never triggered" comment
Posted (edited)

@Nine thanks for the test on a Label control.
My goal was to get rid of $WM_MOUSEMOVE but apparently it can't be easily done... and maybe it's a good thing, let's see why.

I just tested with a few other controls, like Input, List etc... and each one reacts differently.
To test them, I started to modify 1 line in the script (without modifying the variable name or we'll never end)

; Local $idBtn = GUICtrlCreateButton("", 0, 0, 52, 51, $BS_BITMAP)
; Local $idBtn = GUICtrlCreateInput("", 0, 0, 52, 51)
; Local $idBtn = GUICtrlCreateList("", 0, 0, 52, 51)
Local $idBtn = GUICtrlCreateLabel("", 0, 0, 52, 51)
etc...

and with this subclass function :

Func _BtnProc($hWnd, $iMsg, $wParam, $lParam, $IdSubclass, $dwRefData)

    Local Static $bHover, $iCounter = 0, $sClassName = _WinAPI_GetClassName($g_hBtn)

    Switch $iMsg
        Case $WM_MOUSEMOVE
            _WinAPI_TrackMouseEvent($g_hBtn, $TME_HOVER + $TME_LEAVE, 10) ; 10ms

        Case $WM_MOUSEHOVER ; not 100% satisfying
            If Not $bHover Then
                If $sClassName = "Button" Then GUICtrlSetImage($dwRefData, @ScriptDir & "\OK 52-51.bmp")
                $iCounter += 1
                ConsoleWrite("$WM_MOUSEHOVER : $iCounter = " & $iCounter & @crlf)
                $bHover = True
            EndIf

        Case $WM_MOUSELEAVE
            If $sClassName = "Button" Then GUICtrlSetImage($dwRefData, @ScriptDir & "\Cancel 52-51.bmp")
            $iCounter += 1
            ConsoleWrite("$WM_MOUSELEAVE : $iCounter = " & $iCounter & @crlf)
            $bHover = False
    EndSwitch

    Return _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam)
EndFunc   ;==>_BtnProc

But results are not 100% satisfying because, as you indicated in this post, the 10ms wait parameter can create issues, like those displayed below in the Console, when you move quickly the mouse inside and outside the control, then several "MouseLeave" may be displayed instead of 1 only (this is a real Console display below)

$WM_MOUSEHOVER : $iCounter = 1
$WM_MOUSELEAVE : $iCounter = 2
$WM_MOUSEHOVER : $iCounter = 3
$WM_MOUSELEAVE : $iCounter = 4
$WM_MOUSEHOVER : $iCounter = 5
$WM_MOUSELEAVE : $iCounter = 6
$WM_MOUSELEAVE : $iCounter = 7 <=== bad
$WM_MOUSEHOVER : $iCounter = 8
$WM_MOUSELEAVE : $iCounter = 9

Changing 10ms to 1ms won't change anything and also changing it to 0ms will use the hovering system default (which is about 400ms I guess, not sure though)

So my conclusion is to start scripting it as you initially did (e.g. without using $WM_MOUSEHOVER at all) but we need to add a call to _WinAPI_TrackMouseEvent(...$TME_LEAVE) in case the subclassed control requires it (your test with a Label control, mine with a List control which requires it too) . This is the resulting function :

Func _BtnProc($hWnd, $iMsg, $wParam, $lParam, $IdSubclass, $dwRefData)

    Local Static $bHover, $iCounter = 0, $sClassName = _WinAPI_GetClassName($g_hBtn)

    Switch $iMsg
        Case $WM_MOUSEMOVE
            If Not $bHover Then
                If $sClassName = "Button" Then GUICtrlSetImage($dwRefData, @ScriptDir & "\OK 52-51.bmp")
                $iCounter += 1
                ConsoleWrite("$WM_MOUSEMOVE : $iCounter = " & $iCounter & @crlf)
                $bHover = True
            EndIf
            _WinAPI_TrackMouseEvent($g_hBtn, $TME_LEAVE)

        Case $WM_MOUSELEAVE
            If $sClassName = "Button" Then GUICtrlSetImage($dwRefData, @ScriptDir & "\Cancel 52-51.bmp")
            $iCounter += 1
            ConsoleWrite("$WM_MOUSELEAVE : $iCounter = " & $iCounter & @crlf)
            $bHover = False
    EndSwitch

    Return _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam)
EndFunc   ;==>_BtnProc

With this reworked function, we'll never find several followed "MouseLeave" in Console (tested) but only 1, preceded and followed by 1 "MouseMove", even if we move quickly the mouse inside/outside the control, and this, no matter the subclassed control is a Button, Label, Input, List control etc...

I wonder if I should post a reworked script including these last modifications, but with this imaged button code, maybe it won't be clear.
Anyway you got the idea. Hope it helps :)

Edited by pixelsearch
typo

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...