Jump to content

Button does not show unless you move the mouse over

Recommended Posts

Sure, this can happen when you lay the GUI out with overlapping controls... For example (this creates 100 buttons, but none can be seen due to the label sitting over the top of them... until you mouse over):

#include <GUIConstantsEx.au3>
$GUI = GUICreate("App", 500, 500, @DesktopWidth / 2)
$i = 0
Dim $Button[1]
For $a = 0 To 450 Step 50
    For $b = 0 To 450 Step 50
        $i += 1
        ReDim $Button[$i]
        $Button[$i - 1] = GUICtrlCreateButton('B ' & $i, $a, $b, 50, 50)
$Label = GUICtrlCreateLabel('', 0, 0, 500, 500)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
Edited by danwilli

Share this post

Link to post
Share on other sites

Just realized the size entries for the label text was overlapping my button. Although the text itself was no where near my button, the size allocations for the label text caused problems.

Share this post

Link to post
Share on other sites

It's 2020, and although this is an old post, this was the only post that matched my exact problem. Although the information here is helpful to determine the problem, no solution is given. I researched and found out already that the problem is related to the rendering of GUI layers in Autoit, and I have been trying different solutions so fat without success. I am using Autoit with GDI+, and my intention is to have a GUI with background. I have been trying different GUI methods in Autoit, but there isn't a lot of information online about Autoit GUI layers or having textured buttons WITH a textured background. With ome of the GUI methods I tried, the buttons wouldn't even show up. Now, using GDI+, I have textured buttons and background, and even button hover and highlighting, but the buttons don't initially appear until you move the cursor over them.

Here's what I have so far:

When the window first opens...


and then when the cursor passes over..


Some online sources say it's a problem with the drawing order in AutoIt, some say that you have to show and hide the GUI controls in a certain order (including the background), and some say to use $WS_EX_LAYERED or $GUI_FOCUS to fix the problem, but so far nothing works. I do have working Autoit projects that have textured GUI's, so I just have to look in the code to see how they did it. So far, the best working example I found was from:


EDIT: I was going to put an image of the buttons on the background so that they are shown, but that would require me to set up every background first. However, I figured out the problem while writing this post.

SOLLUTION: Putting GUICtrlSetState(-1, $GUI_DISABLE) right after creating the background made the buttons show up properly. You would think that diasabling the background would hide it but in this case it doesn't. Create the background image control, then disable it.

Here's my GUI menu code using GDI+, it doesn't have the code for button highlighting yet or the resource images, but it may help someone:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <GDIPlus.au3>
#include "NoFocusLines.au3"

$fGlobal = True ; this will switch off all spots and lines for all controls

;Global Const $IMAGE_BITMAP = 0
;Global Const $STM_SETIMAGE = 0x0172

Global $img_bmp = 0
Global $stm_setimg = 0x0172

Global $msg


Func MainMenu()
    Global Const $mainWin = GUICreate("FFCC - Accumulator", 960, 565, -1, -1, $WS_EX_LAYERED) ; $WS_SIZEBOX + $WS_SYSMENU


    Global Const $idPic = GUICtrlCreatePic("Bkg1.jpg", 0, 0, 960, 544)
GUICtrlSetState($idPic, $GUI_DISABLE)

    Global Const $Button1 = GUICtrlCreateButton("GILButton", 209, 93, 95, 63, $BS_ICON)
    GUICtrlSetImage($Button1, "button_GIL3.ico")
    Global Const $Button2 = GUICtrlCreateButton("SPButtonDis", 214, 193, 90, 63, $BS_ICON)
    GUICtrlSetImage($Button2, "button_SPdisabled.ico")

    GUISetState(@SW_SHOW, $mainWin)

    ; Loop until the user exits.
    While 1
        $msg = GUIGetMsg()
    Switch $msg
            Case $GUI_EVENT_CLOSE
            Case $Button1
            Case $Button2

EndFunc   ;==>Example


*Note: I will be releasing an assistant application for AutoIt soon that will help it function more like a modern-day game engine. It will include a GUI templating system that will set up GUI menus more efficiently.It will also include project templates, 3D rendering (currently using OpenGL and also Irrlicht), resource management, video support for MP4's, etc. Basically, it will be like the Unity Hub is for the Unity engine, and it will also help AutoIt to function as a game engine for PC and a project-manager for AutoIt, that incorporates commonly used resources, scripts, API's, etc. It also tracks AutoIt projects and keeps track of what resources and scripts are included in the "project". I have seen AutoIt do some amazing things, like run OpenGL at full speed, use the Irrlicht engine, function as an videogame-emulator, loading 3D models, particles and lots more.

I am also working on a similar project for Godot, but I will try to finish the AutoIt Assistant project first and release it here and on my temporary site:


Edited by gwinter

Share this post

Link to post
Share on other sites

To Zedna, the link you posted about GUI image flickering is not related to this problem. As I said in my post it was a problem due to GUI Layers in AutoIt. The problem is fixed by putting 

GUICtrlSetState(-1, $GUI_DISABLE)

right after creating the background made the buttons show up properly.

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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...