Sign in to follow this  
Followers 0
jmon

[SOLVED] Change Z-ordering of controls

11 posts in this topic

#1 ·  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

Share this post


Link to post
Share on other sites



#2 ·  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

#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), $HWND_TOP, $aPos[0], $aPos[1], $aPos[2], $aPos[3], $SWP_NOMOVE)

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

[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

Share this post


Link to post
Share on other sites

#3 ·  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

Share this post


Link to post
Share on other sites

#4 ·  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
1 person likes this

Share this post


Link to post
Share on other sites

I actually need to check the information I posted above. I'm glad you managed to find a solution anyway. :)

Share this post


Link to post
Share on other sites

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?

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

If this is the case then report to Trac.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

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

  • Similar Content

    • WoodGrain
      By WoodGrain
      Hi All,
      I'd like to move a window to the top of the stack without it being active.
      I think it's called z-order in programming?
      I've tried these 2 options (commenting out 1 at a time obviously), but the 1st doesn't seem to do anything, and the 2nd prevents it from being moved behind the other programs even after clicking on it and then clicking on another window behind it:
      Local $hWnd = WinGetHandle("[CLASS:MSPaintApp]")
      _WinAPI_SetWindowPos($hWnd, $HWND_TOP, 0, 0, 0, 0, BitOR($SWP_FRAMECHANGED, $SWP_NOMOVE, $SWP_NOSIZE))
      _WinAPI_SetWindowPos($hWnd, $HWND_TOPMOST, 0, 0, 0, 0, BitOR($SWP_FRAMECHANGED, $SWP_NOMOVE, $SWP_NOSIZE))
      What can I do to move something to the top of the z-order while allowing it to be manually moved back in the z-order?
      Thanks!
    • AndreyS
      By AndreyS
      How to make so that the Label control is always on top of all other controls(including pictures and RTF), regardless of their moves, and changes?
      Function GUICtrlSetState($Label, $GUI_ONTOP) does not work.
      Thanks!
    • GordonFreeman
      By GordonFreeman
      The values are:
      eg.

      10 - 6 - 56 - 37 - 21

      And i need transform the array in:

      6 - 10 - 21 - 37 - 56

      I try but return:

      10 - 21 - 37 - 56 - 6

      Note: I need the ascending.

      That is, 6 can not be greater than 56