Jump to content

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


 Share

Recommended Posts

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!

Link to comment
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

Link to comment
Share on other sites

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.

Link to comment
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
Link to comment
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?
Link to comment
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

Link to comment
Share on other sites

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
Link to comment
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).
Link to comment
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

Link to comment
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

Link to comment
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
 Share

×
×
  • Create New...