Jump to content

Recommended Posts

Posted (edited)

Hello everybody :)
I got an issue with the following script (tested on Windows 11)

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WinAPISysWin.au3>
#include <WindowsConstants.au3>

Opt("MustDeclareVars", 1)
Global $g_hGui

Example()

;==============================================
Func Example()

    Local $idButton, $idLabel, $idCheckbox, $idEdit
    $g_hGui = GUICreate("Drag controls (GUI_ONTOP issue)", 400, 150)

    $idButton = GUICtrlCreateButton("", 10, 30, 80, 80, $WS_CLIPSIBLINGS)
    GUICtrlSetData(-1, "Button " & $idButton)

    $idLabel = GUICtrlCreateLabel("", 100, 40, 80, 60, BitOr($SS_CENTERIMAGE, $SS_CENTER, $WS_CLIPSIBLINGS))
    GUICtrlSetData(-1, "Label " & $idLabel)
    GUICtrlSetBkColor(-1, 0x00FF00) ; green

    $idCheckbox = GUICtrlCreateCheckbox("", 190, 50, 80, 40, $WS_CLIPSIBLINGS)
    GUICtrlSetData(-1, "Checkbox " & $idCheckbox)
    GUICtrlSetBkColor(-1, 0xFFFF00) ; yellow

    $idEdit = GUICtrlCreateEdit("", 280 ,40, 100, 70, BitOr($GUI_SS_DEFAULT_EDIT, $WS_CLIPSIBLINGS))
    GUICtrlSetData(-1, "Edit " & $idEdit)

    GUISetState()

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                Exit
            Case $GUI_EVENT_PRIMARYDOWN
                _ControlMove()
        EndSwitch
    WEnd
EndFunc   ;==>Example

;==============================================
Func _ControlMove()

    Local $aInfo, $idControl, $hControl, $aPos, $iSubtractX, $iSubtractY, $iLoopCount
    $aInfo = GUIGetCursorInfo($g_hGUI)

    If Not @error And $aInfo[4] Then
        $idControl = $aInfo[4]
        $hControl = GUICtrlGetHandle($idControl)
        $aPos = ControlGetPos($g_hGui, "", $idControl)
        $iSubtractX = $aInfo[0] - $aPos[0]
        $iSubtractY = $aInfo[1] - $aPos[1]

        While $aInfo[2] ; LMB pressed
            $iLoopCount += 1
            If $iLoopCount = 1 Then
                ; GUICtrlSetState($idControl, $GUI_ONTOP) ; changes wrongly the z-order of a label control, why ?
                ; _WinAPI_SetWindowPos($hControl, $HWND_TOP, 0, 0, 0, 0,  BitOr($SWP_NOMOVE, $SWP_NOSIZE, $SWP_NOACTIVATE))
            EndIf
            $aInfo = GUIGetCursorInfo($g_hGui)
            GUICtrlSetPos($idControl, $aInfo[0] - $iSubtractX, $aInfo[1] - $iSubtractY)
            Sleep(10)
        WEnd
    EndIf
EndFunc   ;==>_ControlMove

1) When you run the script "as-is" (without modifying any line) :
* Each control dragged to the right covers the controls found at its right
* Each control dragged to the left is covered by the controls found at its left.

2) Now let's uncomment the $GUI_ONTOP line :

GUICtrlSetState($idControl, $GUI_ONTOP) ; seems to change wrongly the z-order of a label control, why ?

; _WinAPI_SetWindowPos($hControl, $HWND_TOP, 0, 0, 0, 0,  BitOr($SWP_NOMOVE, $SWP_NOSIZE, $SWP_NOACTIVATE))

* Button, Checkbox, Edit : they all behave correctly, covering all controls when dragged.
* Label : on the contrary, the label control is covered by any control when dragged.

So the question is : why the label control doesn't follow the other controls behavior ?

3) Final test : please comment out the $GUI_ONTOP line and uncomment the _WinAPI_SetWindowPos line, like this :

; GUICtrlSetState($idControl, $GUI_ONTOP) ; changes wrongly the z-order of a label control, why ?

_WinAPI_SetWindowPos($hControl, $HWND_TOP, 0, 0, 0, 0,  BitOr($SWP_NOMOVE, $SWP_NOSIZE, $SWP_NOACTIVATE))

Now the label control behaves differently and covers all other controls when dragged.
So is there a bug with $GUI_ONTOP when applied to label controls ?

For the record, a track ticket #2287 concerning this question was closed by Jon 12 years ago.
But isn't the test in 2) enough to show that the label behaves differently from the other controls when $GUI_ONTOP is applied to it ?

Edit 1: no more sure of anything as the $WS_CLIPSIBLINGS style seems to interfere with all this !

Edit 2 : even if you remove the 4 $WS_CLIPSIBLINGS style at control creation, you'll notice that test 2) shows a different behavior when it comes to the label control, compared to the 3 other controls, but test 3) shows the same behavior for all controls.

That's why I prefer to use _WinAPI_SetWindowPos which behaves in the same way for the 4 controls, rather than $GUI_ONTOP which treats labels control differently, especially in this kind of script where we want the dragged control to appear above (in front of) any other control during the drag process.

Edited by pixelsearch
added Edit1 then Edit2

"I think you are searching a bug where there is no bug... don't listen to bad advice."

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...