AndreyS

How to make so that the Label control is always on top?

15 posts in this topic

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!

Share this post


Link to post
Share on other sites



try GUICtrlSetState($Label, "",$GUI_ONTOP)

$GUI_ONTOP is an extended style

GUICtrlCreateLabel ( "text", left, top [, width [, height [, style = -1 [, exStyle = -1]]]] )

REB


MEASURE TWICE - CUT ONCE

Share this post


Link to post
Share on other sites

try GUICtrlSetState($Label, "",$GUI_ONTOP)

 

error: GUICtrlSetState() [built-in] called with wrong number of args.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

You need GUICtrlSetStyle and not GUICtrlSetState.

Edit: And $WS_EX_TOPMOST

Edited by funkey

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Share this post


Link to post
Share on other sites

 

You need GUICtrlSetStyle 

 
It does not help! Tested initially.
When I create a control picture it becomes a on top of label.

Share this post


Link to post
Share on other sites

You should post what you've tried. Some of these guys could spot your problem in their sleep, but not without posted code.

#include <GUIConstantSex.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 615, 438, 192, 124)
;$Input1 = GUICtrlCreateInput("Input1", 168, 144, 73, 21); >>>>>>>>>>>>>>>>>picture is on top if you use this one
$Pic1 = GUICtrlCreatePic("C:\Users\Public\Pictures\Sample Pictures\Desert.jpg", 96, 88, 257, 129);change filepath to suit
GUICtrlSetState($Pic1, $GUI_DISABLE)
$Input1 = GUICtrlCreateInput("Input1", 168, 144, 73, 21); >>>>>>>>>>>>>>>>>>input is on top if you use this one
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Share this post


Link to post
Share on other sites

Ok! Please: 

#include <GuiRichEdit.au3>
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Dim $left=10, $top=10

$hGUI = GUICreate("", 600, 400)

;Sequence of creation controls can not be changed!

$Label1 = GUICtrlCreateLabel("Test", $left, $top)
$RTF=_GUICtrlRichEdit_Create($hGUI,"", 70, 10 , 100 , 100)
$Pic = GUICtrlCreatePic("C:\Program Files\AutoIt3\Examples\GUI\logo4.gif", 200, 10, 100, 50)

HotKeySet("^{Right}","Move")

GUISetState()

While 1
    $iMsg = GUIGetMsg()
        Select
            Case $iMsg = $GUI_EVENT_CLOSE
                _GUICtrlRichEdit_Destroy($RTF)
                Exit
        EndSelect
WEnd

Func Move()
    $left+=5
    GUICtrlSetPos($Label1, $left)
EndFunc
How to make that label was always visible when moving over all control?

Share this post


Link to post
Share on other sites

Try this:

#include <GuiRichEdit.au3>
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>



Dim $left = 10, $top = 10

$hGUI = GUICreate("", 600, 400)

;Sequence of creation controls can not be changed!

$Label1 = GUICtrlCreateLabel("Test", $left, $top, 20, 20, -1, $WS_EX_TOPMOST)
$hLabel = GUICtrlGetHandle($Label1)
$RTF = _GUICtrlRichEdit_Create($hGUI, "", 70, 10, 100, 100)
$Pic = GUICtrlCreatePic("C:\Users\Bob\SkyDrive\Beta\AutoIt3\Examples\GUI\logo4.gif", 200, 10, 100, 50)
GUICtrlSetState(-1, $GUI_DISABLE)
HotKeySet("^{Right}", "Move")

GUISetState()

While 1
    $iMsg = GUIGetMsg()
    Select
        Case $iMsg = $GUI_EVENT_CLOSE
            _GUICtrlRichEdit_Destroy($RTF)
            Exit
    EndSelect
WEnd

Func Move()
    $left += 5
    _WinAPI_SetWindowPos($hLabel, $HWND_TOPMOST, $left, $top, 20, 20, $SWP_NOZORDER)
;~     GUICtrlSetPos($Label1, $left)
EndFunc   ;==>Move

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

This worked for me. WinXP, AutoIt Version: 3.3.9.22 (Beta)

Edit: granted it's a hack & others can point you in a better direction; but it works.

#include <GuiRichEdit.au3>
#include <Constants.au3>
#include <GUIConstantSex.au3>
#include <WindowsConstants.au3>

Global $left = 10, $top = 10;the term "Dim" is on the outs. Global is the way. Ask BrewmanNH
$hGUI = GUICreate("", 600, 400, -1, -1, $WS_SIZEBOX, $WS_EX_COMPOSITED);$WS_SIZEBOX, $WS_EX_COMPOSITED did it. with other styles, first created is on top.
;Makes no sense (to me) but it is so.

;Sequence of creation controls can not be changed!
$Label1 = GUICtrlCreateLabel("Test", $left, $top)
$RTF = _GUICtrlRichEdit_Create($hGUI, "", 70, 10, 100, 100)
$Pic = GUICtrlCreatePic("C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Water lilies.jpg", 200, 10, 100, 50);always a nice picture

HotKeySet("^{Right}", "Move")
GUISetState()
While 1
    $iMsg = GUIGetMsg()
    Select
        Case $iMsg = $GUI_EVENT_CLOSE
            _GUICtrlRichEdit_Destroy($RTF)
            Exit
    EndSelect
WEnd

Func Move()
    $left += 5
    GUICtrlSetPos($Label1, $left)
EndFunc   ;==>Move
Edited by lorenkinzel

Share this post


Link to post
Share on other sites
Wow! Thank you very much for the feedback and examples!  :rolleyes:
The second method is very simple and I have works well in my program. It took just add a property form: $WS_EX_COMPOSITED.
The first method is also good, but for some reason it does not work with transparency: GUICtrlSetBkColor($Label1, $GUI_BKCOLOR_TRANSPARENT).

Share this post


Link to post
Share on other sites

The "first method" that BrewmanNH showed you deals with the actual problem.

My little hack only deals with the symptoms.

Whenever possible, it's good to learn the how & why of coding rather than little tricks that somehow make it work.

Share this post


Link to post
Share on other sites

Just a word of warning about using a transparent label. If you do that and the label starts over another control, it totally screws up your label. Change the $left = 10 to $left = 200 and then move the label and you'll see what I mean.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Aah! Yes, an interesting effect! )) The background of the label to become a background that is underneath.

And how to fix it in your code so that the background was always transparent?

Share this post


Link to post
Share on other sites

Native Windows controls don't seem to permit true transparency, so you're probably not going to be able to achieve what you want that way. You might have to use a GDI+ image with transparency as your label.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Yeah like that ?!

Yes, it is more difficult way! Well that found an easier option.

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

  • Similar Content

    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning community!
      I was working on a script which read the content of a .ini file to retrieve the file that has to open, and, based on the value of a second key stored in the .ini file, set the window on top, minimized or maximized...
      I did something like this, but seems to not work properly...
      Could anyone please tell me what I'm doing wrong?
      Thank you  
       
      #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile_x64=prova.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <AutoItConstants.au3> ;#include <WinAPIEx.au3> #include <Array.au3> Local $sFileConfigurazione = @ScriptDir & "\configurazione_exe.ini" If(FileExists($sFileConfigurazione)) Then Local $aSezioneIni = IniReadSection($sFileConfigurazione, "CONFIGURAZIONE_EXE") If @error Then MsgBox($MB_ICONERROR, "Errore!", "Errore durante l'apertura del file: " & @CRLF & $sFileConfigurazione & @CRLF & "Errore: " & @error) Else ; Lancio dell'applicativo indicato nel file di configurazione Local $iPID = ShellExecute($aSezioneIni[1][1]) Local $hWnd If($iPID <> 0) Then Local $aWinList = WinList() For $i = 1 To $aWinList[0][0] If(WinGetProcess($aWinList[$i][1] = $iPID)) Then $hWnd = $aWinList[$i][1] EndIf Next Switch($aSezioneIni[2][1]) Case $aSezioneIni[2][1] = "MIN" ToolTip("MIN", 0, 0) WinSetState($hWnd, WinGetTitle($hWnd), @SW_MINIMIZE) Case $aSezioneIni[2][1] = "MAX" ToolTip("MAX", 0, 0) WinSetState($hWnd, WinGetTitle($hWnd), @SW_MAXIMIZE) Case $aSezioneIni[2][1] = "TOP" ToolTip("TOP", 0, 0) WinSetOnTop($hWnd, WinGetTitle($hWnd), $WINDOWS_ONTOP) EndSwitch EndIf EndIf EndIf And the .ini file is like this:
       
      [CONFIGURAZIONE_EXE] PercorsoExe=Here goes the path and the .exe to execute ModalitaAperturaExe=Here goes one of the value below /* TOP Shows the windows on top */ /* MIN Shows the window minimized */ /* MAX Shows the window maximized */  
    • algiuxas
      By algiuxas
      Hello,
      I'm trying to make cursor for my program, and I need to make it on top but not active when pressed on start menu, taskbar or etc. (cursor appears behind taskbar/start menu).
      Somebody could help me with this problem?
      ; A bit of my script #include <GUIConstants.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include <GDIPlus.au3> #include <GuiListBox.au3> Global $Bitmap_Mouse_Pic_Dir = @ScriptDir&"\Cursor.png" Global $Bitmap_Mouse_Pic = _GetWHI($Bitmap_Mouse_Pic_Dir) Global $Bitmap_Mouse_PicSel_Dir = @ScriptDir&"\Selection.png" Global $Bitmap_Mouse_PicSel = _GetWHI($Bitmap_Mouse_PicSel_Dir) Global $Bitmap_Mouse_Opt = 255 ; ... For $i = 0 to 0 $GP_guicur[$i] = GUICreate("GP Cursor", 64, 64, $POS[$i][0], $POS[$i][1], $WS_POPUP, $WS_EX_LAYERED, $GUI) WinSetOnTop($GP_curgui[$i],"",1) SetBitmap($GP_curgui[$i], $Bitmap_Mouse_Pic, $Bitmap_Mouse_Opt) GUISetState(@SW_SHOW) Next ; ... For ; ... Sleep(1000) MouseClick("left",5,@DesktopHeight-5) ; ... Next Exit ;______________________________________________________________________; ; Original program by Ejoc ; ; Improved by Adam1213 (autoit 3.2 compatiblity + improved labels; ;______________________________________________________________________; ; $sImage = Path to your image ; Returns = Array[3] ; $Array[0] = Width ; $Array[1] = Height ; $Array[2] = handle to a HBITMAP ; when the image is no longer needed use _WinAPI_DeleteObject($Array[2]) Func _GetWHI($sImage) Local $hImage, $aBitmap[3] _GDIPlus_Startup() $hImage = _GDIPlus_ImageLoadFromFile($sImage) $aBitmap[0] = _GDIPlus_ImageGetWidth($hImage) $aBitmap[1] = _GDIPlus_ImageGetHeight($hImage) $aBitmap[2] = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) _GDIPlus_ImageDispose($hImage) _GDIPlus_Shutdown() Return $aBitmap EndFunc ;==>_GetWHI ; I changed this so I could shutdown gdiplus once an image has been loaded by _GetWHI() ; just pass it the array returned by _GetWHI() Func SetBitmap($hGUI, $aBitmap, $iOpacity) Local Const $AC_SRC_ALPHA = 1 Local $hScrDC, $hMemDC, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend $hScrDC = _WinAPI_GetDC(0) $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC) $hOld = _WinAPI_SelectObject($hMemDC, $aBitmap[2]) $tSize = DllStructCreate($tagSIZE) $pSize = DllStructGetPtr($tSize) DllStructSetData($tSize, "X", $aBitmap[0]) DllStructSetData($tSize, "Y", $aBitmap[1]) $tSource = DllStructCreate($tagPOINT) $pSource = DllStructGetPtr($tSource) $tBlend = DllStructCreate($tagBLENDFUNCTION) $pBlend = DllStructGetPtr($tBlend) DllStructSetData($tBlend, "Alpha", $iOpacity) DllStructSetData($tBlend, "Format", $AC_SRC_ALPHA) _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA) _WinAPI_ReleaseDC(0, $hScrDC) _WinAPI_SelectObject($hMemDC, $hOld) _WinAPI_DeleteDC($hMemDC) EndFunc ;==>SetBitmap
      Thanks
    • 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!
    • jmon
      By jmon
      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
    • zvvyt
      By zvvyt
      Hello there.
      I'm currently trying to solve a problem I'm having with the GUIExtender-UDF by Melba23, but I can't relly get the hang of it and I think I need someone to straightening this out for me.
      What I'm trying to achieve is a "menu-ish" GUI with buttons that takes you deeper and further into the menues, and aswell to have a back-button which lets you return to the previously extended section. I've done this before with the use of multiple child GUIs being hidden/shown, but that was taking too much out of the computer as I'll be working with 20+ windows/sections.

      What I've been testing so far is the following:

      #include "GUIExtender.au3" #include <GUIConstantsEx.au3> $GUI = GUICreate("Test",500,300,-1,-1) _GUIExtender_Init($GUI, 1) $Back = GUICtrlCreateButton("Back",50,20,50,25) $Window1 = _GUIExtender_Section_Start(50, 500) _GUIExtender_Section_Action($Window1) $Button1 = GUICtrlCreateButton("Button1",100,100,100,30) _GUIExtender_Section_End() $Window2 = _GUIExtender_Section_Start(50, 500) _GUIExtender_Section_Action($Window2) $Button2 = GUICtrlCreateButton("Button2",150,100,100,30) _GUIExtender_Section_End() $Window3 = _GUIExtender_Section_Start(50, 500) _GUIExtender_Section_Action($Window3) $Button3 = GUICtrlCreateButton("Button3",250,100,100,30) _GUIExtender_Section_End() _GUIExtender_Section_Extend(0, False,0) _GUIExtender_Section_Extend($Window1, True,0) GUISetState() while 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit case $Button1 _GUIExtender_Section_Extend(0, False,0) _GUIExtender_Section_Extend($Window2, True,0) case $Button2 _GUIExtender_Section_Extend(0, False,0) _GUIExtender_Section_Extend($Window3, True,0) case $Button3 _GUIExtender_Section_Extend(0, False,0) _GUIExtender_Section_Extend($Window1, True,0) case $Back EndSwitch WEnd
      When I just had 2 sections created the extend/retract worked as I think it should, which is hideing one and showing the other. But as I added the 3rd section by using the same terms as the precious 2 it's now having both section 2 & 3 extended at same time and somewhat linking them togeather, idk.
      I've tried to get the hang of this by the examples provided by Melba and by the UDF itself, but it seem like I got something wrong..

      Best regards,
      zvvyt