Jump to content

Recommended Posts

Posted (edited)

Hello,

I am trying to change the z-ordering of controls in my GUI using GUICtrlSetState. How come this example don't work? (I want $LABEL1 to be above $LABEL2)

#include <GUIConstantsEx.au3>

$GUI = GUICreate("Test", 800, 600)
GUISetState()

$LABEL1 = GUICtrlCreateLabel("under", 20, 20, 500, 300)
GUICtrlSetBkColor(-1, 0xFF0000)
$LABEL2 = GUICtrlCreateLabel("above", 40, 60, 500, 300)
GUICtrlSetBkColor(-1, 0x00FF00)

GUICtrlSetState($LABEL1, $GUI_ONTOP)

Do
Sleep(50)
Until GUIGetMsg() = -3
Exit

Is there another method to change the z ordering and the order controls receive clicks? I know that the controls should be created in the correct order, but I can't in the script I am doing now.

Thanks

[EDIT] Solution is in post #5

Edited by jmon
Posted (edited)

So I tested other options, and this one doesn't work either:

#include <GUIConstantsEx.au3>
#include <WinAPIEx.au3>

$GUI = GUICreate("Test", 800, 600)
GUISetState()

$LABEL1 = GUICtrlCreateLabel("under", 20, 20, 500, 300)
GUICtrlSetBkColor(-1, 0xFF0000)
$LABEL2 = GUICtrlCreateLabel("above", 40, 60, 500, 300)
GUICtrlSetBkColor(-1, 0x00FF00)

_WinAPI_BringWindowToTop(GUICtrlGetHandle($LABEL1))

Do
Sleep(50)
Until GUIGetMsg() = -3
Exit

[EDIT]

This one doesn't seems to work either

  Reveal hidden contents

[EDIT] Actually it works but with these parameters:

#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <APIConstants.au3>

$GUI = GUICreate("Test", 800, 600)
GUISetState()

$LABEL1 = GUICtrlCreateLabel("under", 20, 20, 500, 300)
GUICtrlSetBkColor(-1, 0xFF0000)
$LABEL2 = GUICtrlCreateLabel("above", 40, 60, 500, 300)
GUICtrlSetBkColor(-1, 0x00FF00)

$aPos = ControlGetPos(GUICtrlGetHandle($LABEL1), "", 0)
_WinAPI_SetWindowPos(GUICtrlGetHandle($LABEL1), GUICtrlGetHandle($LABEL2), $aPos[0, $aPos[1], $aPos[2], $aPos[3], $SWP_NOCOPYBITS)

Do
Sleep(50)
Until GUIGetMsg() = -3
Exit

Now, even if this works, I'm still looking for a method that wouldn't move the control and that wouldn't need to tell which control to draw over.

Edited by jmon
Posted (edited)

It's possible Microsoft changed how the z-Index can be alterred (I may have read something like that - though I'm not entirely sure). Even if this is not the case, it does not automatically follow that the GUI controls will be automatically repainted (once again - I don't know). I do think that overlapping controls is generally best avoided. Depending on what you want to achieve, there may be a work around or an alternative method. You can always destroy your controls and create them again in reverse order.

Edited by czardas
Posted (edited)

@czardas : thank you for the information

I actually found the solution:

#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <APIConstants.au3>

$GUI = GUICreate("Test", 800, 600)
GUISetState()

$LABEL1 = GUICtrlCreateLabel("under", 20, 20, 500, 300)
GUICtrlSetBkColor(-1, 0xFF0000)
$LABEL2 = GUICtrlCreateLabel("above", 40, 60, 500, 300)
GUICtrlSetBkColor(-1, 0x00FF00)

GuiCtrlSetOnTop($LABEL1)

Do
    Sleep(50)
Until GUIGetMsg() = -3
Exit

Func GuiCtrlSetOnTop($iCtrlID)
    ;Need to include <WinAPI.au3> and <APIConstants.au3>
    Local $hWnd = $iCtrlID
    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($iCtrlID)
    Return _WinAPI_SetWindowPos($hWnd, $HWND_BOTTOM, 0, 0, 0, 0, $SWP_NOMOVE + $SWP_NOSIZE + $SWP_NOCOPYBITS)
EndFunc

This method doesn't require to tell the position or the control to be drawn ontop. I made a quick snippet that you can include in your scripts.

Edited by jmon
Posted

  On 11/29/2012 at 9:15 AM, 'jmon said:

So even though I found an answer to my question, I was wondering what was

GUICtrlSetState($LABEL1, $GUI_ONTOP)

supposed to do? What is this constant for is it's not to set a control on top?

Hmm, strange. Perhaps this is a bug?

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

If this is the case then report to Trac.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

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