Jump to content
Sign in to follow this  
rdwray

Label not showing on GUI background image

Recommended Posts

rdwray

There are several problems: 1) the label (text) does not show on top of the GUI image. 2) when the label is applied the GUI image is trucated on the left by 5 pixels. 3) The task bar icon disppears when the mouse is over it and closes the window. I did not finish adding the required images for the buttons because I have to create them.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <GuiButton.au3>
#include <StaticConstants.au3>
#Include <GuiEdit.au3>
#include <Misc.au3>
Opt('MustDeclareVars', 1)
Example()
Func Example()
Local $NewStyle = False, $hWnd, $hButSD, $hButRS, $hButLO, $hButLP,$hButS, $hButH, $Msg, $Style
Local $x=5, $hBut, $hTxtOper
$hWnd = GUICreate("Gui Style", 172, 101, -1, -1, $WS_POPUP)
GUICtrlCreatePic(@ScriptDir & "\BG.bmp", 0, 0, 172, 101, -1, $GUI_WS_EX_PARENTDRAG)
GUISetState(@SW_SHOW)
$hTxtOper = GUICtrlCreateLabel($hWnd, "", $x, 5, 130, 20, $SS_CENTER)
GUICtrlSetColor($hTxtOper, 0xffff00)
$hButSD = GUICtrlCreateButton("test",$x  , 25, 24, 24, $BS_BITMAP)
_GUICtrlButton_SetImage($hButSD, @ScriptDir & "\ShutDownUp.bmp")
$hButRS = GUICtrlCreateButton("", $x + 27, 25, 24, 24)
$hButLO = GUICtrlCreateButton("", $x + 54, 25, 24, 24)
$hButLP = GUICtrlCreateButton("", $x + 81, 25, 24, 24)
$hButS = GUICtrlCreateButton("", $x + 108, 25, 24, 24)
$hButH = GUICtrlCreateButton("", $x + 135, 25, 24, 24)
While 1
  $hBut = GUIGetCursorInfo()
  if  $hBut[4] = $hButSD then
   ControlSetText("Power Options", "", $hTxtOper, "Shut down PC")
   if _IsPressed(1) Then _GUICtrlButton_SetImage($hButSD, @ScriptDir & "\ShutDownDn.bmp")
  else
   ControlSetText("Power Options", "", $hTxtOper, "Select an option...")
  EndIf
  if Not _IsPressed(1) or $hBut[4] <> $hButSD Then
   _GUICtrlButton_SetImage($hButSD, @ScriptDir & "\ShutDownUp.bmp")
  EndIf
Sleep(100)
  $Msg = GUIGetMsg()
  Switch $Msg
   Case $GUI_EVENT_CLOSE
    Exit
  EndSwitch
WEnd
EndFunc

“No other God have I but Thee; born in a manger, died on a tree.” Martin Luther

Share this post


Link to post
Share on other sites
Melba23

rdwray,

- 1. It does if you use the correct syntax - the native functions do not take the GUI handle as the first parameter.

- 2. I get no truncation of the image when the label is displayed.

- 3. The tray and taskbar icons do not close the script when I put the cursor over them.

And there are several other problems:

- 1. You have already been told here that you need to disable your background image if you want the other controls to function - at present the buttons do not work. But you cannot use the $GUI_WS_EX_PARENTDRAG style then - look at the Moving and Resizing PopUp GUIs tutorial in the Wiki to find out about other ways to move the GUI.

- 2. The converse to the first answer I gave you - you need a handle if you use _GUICtrlButton_SetImage - but why do so when you can use the native GUICtrlSetImage function?

- 3. You do not need a Sleep if you use GUIGetMsg in your idle loop - it just makes the GUI less responsive. But why even look for $GUI_EVENT_CLOSE when you have a popup style GUI with no closure [X]?

- 4. Why use ControlSetText (and use a non-existent title to boot) rather than GUICtrlSetData?

- 5. If you use _IsPressed in a loop you shoudl open the DLL and use it as a parameter as explained in the Help file.

- 6. You will get terrible flashing of the label and button as you constantly reset the same text and image unless you use some form of state control to only change them when needed.

I think this goes some way to doing what you want - you will need to change the image paths of course: :bye:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiButton.au3>
#include <StaticConstants.au3>
#include <GuiEdit.au3>
#include <Misc.au3>

Opt('MustDeclareVars', 1)

HotKeySet("{ESC}", "On_Exit")

Global $hDLL

Example()

Func Example()

    Local $NewStyle = False, $hWnd, $hButSD, $hButRS, $hButLO, $hButLP, $hButS, $hButH, $Msg, $Style
    Local $x = 5, $hBut, $hTxtOper

    $hWnd = GUICreate("Gui Style", 172, 101, -1, -1, $WS_POPUP)
    GUICtrlCreatePic("M:ProgramAu3 ScriptsImagesTest.jpg", 0, 0, 172, 101)
    GUICtrlSetState(-1, $GUI_DISABLE)
    $hTxtOper = GUICtrlCreateLabel("", $x, 5, 130, 20, $SS_CENTER)
    $hButSD = GUICtrlCreateButton("test", $x, 25, 24, 24, $BS_BITMAP)
    $hButRS = GUICtrlCreateButton("", $x + 27, 25, 24, 24)
    $hButLO = GUICtrlCreateButton("", $x + 54, 25, 24, 24)
    $hButLP = GUICtrlCreateButton("", $x + 81, 25, 24, 24)
    $hButS = GUICtrlCreateButton("", $x + 108, 25, 24, 24)
    $hButH = GUICtrlCreateButton("", $x + 135, 25, 24, 24)

    GUISetState(@SW_SHOW)

    Local $fState = True
    $hDLL = DllOpen("user32.dll")

    While 1
        $hBut = GUIGetCursorInfo()
        If $hBut[4] = $hButSD And _IsPressed("01", $hDLL) And $fState = False Then
            GUICtrlSetData($hTxtOper, "Shut down PC")
            GUICtrlSetImage($hButSD, "M:ProgramAu3 ScriptsImagesStop.bmp")
            $fState = True
        ElseIf Not ($hBut[4] = $hButSD And _IsPressed("01", $hDLL)) And $fState = True Then
            GUICtrlSetData($hTxtOper, "Select an option...")
            GUICtrlSetImage($hButSD, "M:ProgramAu3 ScriptsImagesRun.bmp")
            $fState = False
        EndIf
    WEnd
EndFunc   ;==>Example

Func On_Exit()
    DllClose($hDLL)
    Exit
EndFunc

Please ask if you have any questions. :oops:

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______Open Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
rdwray

Thanks M23,

Before remarks I ran into 1 issue in that the text in the label should change when the cursor hovers over the button before it is pressed; other wise it looks works well.

-1) I looked at wiki and I have previously used mouse non-client ot move objects and thought I would try something else.

-2) These suggestions is what I am looking for.

-3) I found one of the syntax errors just after making the post.

-4) I have not added the close button yet, it is on the way.

-5) Ok, the help file does show the .dll as an option and not required. _IsPressed($sHexKey [, $vDLL = 'user32.dll'])


“No other God have I but Thee; born in a manger, died on a tree.” Martin Luther

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  

×