Jump to content

GuiFlatButton UDF : Change Colors of Regular Buttons


Recommended Posts

Thanks for chiming in.

I want to add a couple of things to this puzzle:

First, I've now used the Au3 Inspection Tool to confirm that, indeed, the buttons are completely gone from the GUI. What were (initially ) identified as "Button 1, 2, 3 ... etc., don't show anything at all, once they've disappeared.

Second, I opened the FlatButton UDF, itself, and found this ominous line of code:

OnAutoItExitRegister("GUIFlatButton_Exit")

This button exit function specifically deletes each of a GUIs defined buttons. Given that Au3's function can be triggered by any of 5 different actions, it opens the possibility (to me) of some extraneous operation within the FlatButton UDF.

So I have to ask: Do Flat Buttons require the _Exit? ... or will they be deleted by the normal Au3 GUI close processing?

Link to post
Share on other sites

After much testing, I can add a couple more findings:

OnAutoItExitRegister("GUIFlatButton_Exit")  does not appear to be a problem. I removed it and added the delete button call to my _Exit() and the buttons still disappear.

But I have now isolated a main suspect. One of the functions of my GUI creates and then deletes a $WS_POPUP overlay window that is defined as an MDI_CHILD window. After that function has been used, the flat buttons always disappear the next time I try to drag the main GUI to a new position on the desktop. Without the drag GUI action, the flat buttons are fine and work properly. But any subsequent drag causes the buttons to immediately disappear.

This is about as strange as anything I've ever encountered with Au3. I'm trying different combinations of CLIP_CHILDREN and CLIPSIBLINGS, but so far, nothing helps.

Link to post
Share on other sites

With a couple more hours of effort, I now have a workaround.

First, I've concluded that there's some deep-seated problem with the way MDI Child Windows are managed when they're deleted. I was using the MDI child method for a small overlay panel that my GUI uses. It worked well because it would overlay whatever was defined under it on the main GUI (... which happen to be Flat Buttons). As I stated, previously, the problem was that when I was finished with the overlay panel and deleted it, the Flat Buttons were deleted upon the first drag action of the Main GUI.

My workaround is this: before creating my overlay panel, I use GuiFlatButton_SetState to hide the buttons that are under the panel. I then create the panel as a simple Child window (not an MDI Child). I then delete the panel and $GUI_SHOW the hidden buttons. Everything now works fine.

Unless someone poses at clean solution, I'll use this method and consider the problem solved. (And, BTW, searches on this forum revealed there are enough fringe problems with MDI Child Windows to give one doubts about using them in any situation beyond the simplest ones.)

Link to post
Share on other sites
On 4/26/2021 at 12:57 AM, qwert said:

With a couple more hours of effort, I now have a workaround.

First, I've concluded that there's some deep-seated problem with the way MDI Child Windows are managed when they're deleted. I was using the MDI child method for a small overlay panel that my GUI uses. It worked well because it would overlay whatever was defined under it on the main GUI (... which happen to be Flat Buttons). As I stated, previously, the problem was that when I was finished with the overlay panel and deleted it, the Flat Buttons were deleted upon the first drag action of the Main GUI.

My workaround is this: before creating my overlay panel, I use GuiFlatButton_SetState to hide the buttons that are under the panel. I then create the panel as a simple Child window (not an MDI Child). I then delete the panel and $GUI_SHOW the hidden buttons. Everything now works fine.

Unless someone poses at clean solution, I'll use this method and consider the problem solved. (And, BTW, searches on this forum revealed there are enough fringe problems with MDI Child Windows to give one doubts about using them in any situation beyond the simplest ones.)

please put your sample code

Link to post
Share on other sites
  • 2 months later...
On 4/25/2021 at 10:35 AM, qwert said:

But I have now isolated a main suspect. One of the functions of my GUI creates and then deletes a $WS_POPUP overlay window that is defined as an MDI_CHILD window. After that function has been used, the flat buttons always disappear the next time I try to drag the main GUI to a new position on the desktop. Without the drag GUI action, the flat buttons are fine and work properly. But any subsequent drag causes the buttons to immediately disappear.

Sorry, just seeing this now. If you don't mind posting some example code showing the issue, I would be happy to take a look at it.

Link to post
Share on other sites
  • 1 month later...
Posted (edited)

FYI, I confirmed the issue where the buttons are deleted after a $WS_EX_MDICHILD window is deleted, but I could not figure it out yet.

I was certain I had a reproducer script, but now I can't get it to do it again!

@qwert does this example work for you?

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include "GuiFlatButton.au3"

Example()

Func Example()
    Local $hGUI, $idLabel, $mybutton1

    $hGUI = GUICreate("GuiFlatButton Ex1", 300, 600)
    GUISetBkColor(0x444444)

    ;create new button then set the colors
    $mybutton1 = GuiFlatButton_Create("Button 1", 10, 10, 140, 40)
    GuiFlatButton_SetBkColor(-1, 0x777777)
    GuiFlatButton_SetColor(-1, 0xFFFFFF)

;~     $mybutton2 = GuiFlatButton_Create("Button 1", 10, 100, 140, 40)
;~     GuiFlatButton_SetBkColor(-1, 0x777777)
;~     GuiFlatButton_SetColor(-1, 0xFFFFFF)

    GUISetState(@SW_SHOW, $hGUI)

    $hchild = GUICreate("", 150, 200, 5, 250, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)
    GUISetBkColor(0x0000FF)
    GUISetState(@SW_SHOWNOACTIVATE, $hchild)

;~  Sleep(5000)
;~  GUIDelete($hchild)

    Local $iMsg
    Local $i=0
    While 1
        $iMsg = GUIGetMsg()

        Switch $iMsg
            Case $GUI_EVENT_CLOSE
                ExitLoop

            Case $mybutton1
;~                 GUIDelete($hchild)
                ConsoleWrite($i & @CRLF)
                $i += 1

        EndSwitch

        Sleep(10)
    WEnd

    GUIDelete()
EndFunc   ;==>Example

 

Edited by kurtykurtyboy
updated test script
Link to post
Share on other sites

I only had time to make a quick test:

The GUI comes up fine ... and the elements seem to behave.

HOWEVER, clicking on the window's top bar immediately causes both buttons to disappear.

Link to post
Share on other sites

Interesting... same thing happens to me. I modified the test to increment a counter on button press. Even after the buttons disappear, I can keep hitting spacebar to keep counting. This means the buttons still exist but there must be something funky with my drawitem logic.

Link to post
Share on other sites

Well I discovered the problem, but not the cause. It appears that moving the window over the tiniest amount causes the buttons to fly way off the screen.

Here are the positions. 0 is before I moved the window. 1 is after I moved the window. Removing the $WS_EX_MDICHILD extended style makes it behave as expected. There must be something strange happening internally. I think I have a workaround but will need to test later.

0:   X:821  Y:248  W:140  H:40
1:   X:5744  Y:1676  W:140  H:40

 

Link to post
Share on other sites

First post updated with a graceful workaround to the MDI child issue. I am intercepting the $WM_WINDOWPOSCHANGING message to 'block' any position changing unless it is an intentional move by the GuiFlatButton_SetPos function.

 

@qwert It is looking like your initial guess of some deep-rooted internal AutoIt logic may be the cause. If you run this example and drag the window around, you can see the 2nd regular child window immediately disappears and the "MDI" child has a sort of shadow effect while dragging. I know the help docs say this is a simulation of MDI child, so my theory is AutoIt is continuously changing the MDI window position, trying to keep up with the parent window while dragging. Hence the shadow effect. It seems that somewhere in the logic, the other child windows are getting their positions thrown out of whack. However, my flat button does just beautifully now!

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include "GuiFlatButton.au3"

Example()

Func Example()
    Local $hGUI, $idLabel, $mybutton1

    $hGUI = GUICreate("GuiFlatButton MDI Example", 400, 600)
    GUISetBkColor(0x444444)
    ConsoleWrite("GUI Handle: " & $hGUI & @CRLF)

    ;create new button then set the colors
    $mybutton1 = GuiFlatButton_Create("Button 1", 10, 10, 140, 40)
    GuiFlatButton_SetBkColor(-1, 0x777777)
    GuiFlatButton_SetColor(-1, 0xFFFFFF)


    GUISetState(@SW_SHOW, $hGUI)

    ;create an MDI child window
    $hchild = GUICreate("", 150, 200, 5, 250, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)
    GUISetBkColor(0x0000FF)
    GUISetState(@SW_SHOWNOACTIVATE, $hchild)

    ;create a 'normal' child window
    Local $childHWND = GUICreate("", 150, 200, 210, 250, BitOR($WS_CHILD, $WS_CLIPCHILDREN, $WS_CLIPSIBLINGS), $WS_EX_CONTROLPARENT, $hGUI)
    GUISetState(@SW_SHOWNOACTIVATE, $childHWND)

    Local $iMsg
    Local $i=0
    While 1
        $iMsg = GUIGetMsg()

        Switch $iMsg
            Case $GUI_EVENT_CLOSE
                ExitLoop

            Case $mybutton1
                $aPos = GuiFlatButton_GetPos($mybutton1)
                ConsoleWrite($i & ": " & "  X:" & $aPos[0] & "  Y:" & $aPos[1] & "  W:" & $aPos[2] & "  H:" & $aPos[3] & @CRLF)
                $i += 1

        EndSwitch

        Sleep(10)
    WEnd

    GUIDelete()
EndFunc   ;==>Example

 

Link to post
Share on other sites
  • 2 weeks later...

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.

  • Similar Content

    • By Kanashius
      This UDF can be used to draw at the Desktop Wallpaper (Windows 8+) with GDI+ without using files.
      The example runs with 60-120fps at my machine, so the speed is acceptable.
      When the script exits, the original wallpaper is restored.
      Have fun :).
      PS: The UDF uses the window between the background and the icons, so it could be used to add an own child window at the desktop. Just look at the begin of __Wallpaper_Startup ($hWorkerW).
       
      Example:
       
      WallpaperUDF.au3 WallpaperUDF Example.au3
    • By sandgre
      Wondering if you can help a teacher out.  For the last few years of remote, hybrid, and in-person teaching I've been using an AutoHotKey script that creates an inking toolbar to be used during a PowerPoint presentation.  (https://www.autohotkey.com/boards/viewtopic.php?t=79163) The annotation tools available through Ppt are woefully inadequate, and, on my machine at least, jump around all over the place - sometimes on the bottom, sometimes on the left, sometimes on the right.  It's a scavenger hunt every single time.  The inking tool is always available, and recent updates allowed for the addition of lots more colors, which I used for modeling phenomena with students. One tragic day I arrived to school to find that my district IT dep't took away access to AutoHotKey.  No more tool bar. 
      I've been trying to resurrect some programming skills from a past life. I'm working through various tutorials and help files, with the goal of recreating the toolbar in AutoIt.  I'm really needing some help to move things along though.  I've been going through your PowerPoint UDF and all of your functions seem to just relate to editing the slides. Can you point me in the direction of how to create a toolbar that accesses the annotation tools that are available during the slideshow itself? 
       
    • By Hermes
      Hi, I am struggling in setting the value of a textarea based on the value of clipboard (that contains a long web page source codes). If I use _WD_SetElementValue, it freezes after some time, or appears to be pressing tab and goes out of focus. I can also use send keys but i need the script to run in the background.
      Here is the full script:
      #Include "Chrome.au3" #Include "wd_core.au3" #Include "wd_helper.au3" #Include "WinHttp.au3" #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <Array.au3> #include <AutoItConstants.au3> #include <WinAPIFiles.au3> #include <GDIPlus.au3> #include <Excel.au3> Local $sDesiredCapabilities, $sSession SetupChrome() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_LoadWait($sSession) _WD_Navigate($sSession, "http://demo.borland.com/testsite/stadyn_largepagewithimages.html") _WD_LoadWait($sSession) Global $sSource = _WD_GetSource($sSession) Local $Paste = ClipPut($sSource) Local $sData = ClipGet() Local $aArray = 0, _ $iOffset = 1 While 1 $aArray = StringRegExp($sData, '(?s)<p>.*</p>', $STR_REGEXPARRAYMATCH, $iOffset) If @error Then ExitLoop $iOffset = @extended For $i = 0 To UBound($aArray) - 1 Local $Paste = ClipPut($aArray[$i]) Local $sRegExData = ClipGet() ;MsgBox(0, "", "$sRegExData = " & $sRegExData) Next WEnd _WD_Navigate($sSession, "https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_textarea_placeholder") _WD_WaitElement($sSession, $_WD_LOCATOR_ByCSSSelector, "iframe#iframeResult") Local $sElement1 = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "iframe#iframeResult") _WD_FrameEnter($sSession, $sElement1) _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//html/body/textarea") $textarea = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//html/body/textarea") _WD_ElementAction($sSession, $textarea, 'click') ;WD SetElementValue(SsSession, Stextarea, $sRegExData) <-- I can do this but the focus goes out, or the browser freezes _WD_FrameLeave($sSession) sleep(2000) Send("^v") _WD_LoadWait($sSession) _WD_Shutdown() Func SetupChrome() _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["start-maximized","disable-infobars"]}}}}' EndFunc ;==>SetupChrome Can someone help me please, or re-direct me to the right path? TIA!
    • By Hermes
      Hi, I am trying to select elements in print page (dialog window) for a specific web page. But when trying to do so, it looks like it does not allow me to do it.
      So far, this is what I have:
      _WD_WaitElement($sSession, $_WD_LOCATOR_ByCSSSelector, "body") Local $mainpagebody = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "body") _WD_HighlightElement($sSession, $mainpagebody, 2) _WD_WaitElement($sSession, $_WD_LOCATOR_ByCSSSelector, "img.print-button") Local $printbutton = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "img.print-button") _WD_ElementAction($sSession, $printbutton, 'click') _WD_LoadWait($sSession) Sleep(3000) _WD_WaitElement($sSession, $_WD_LOCATOR_ByCSSSelector, "body") Local $printpagebody = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "body") _WD_HighlightElement($sSession, $printpagebody, 2) The script above highlights the main web page "body" element, then clicks a tag to print a specific part of the page, then it will open a print page window where i am trying to highlight the body of that print page - but it looks like it is dropping from the session because it opens up another chrome page chrome://print.
       
      Below is the output log:
      __WD_Post: URL=HTTP://127.0.0.1:9515/session/cd08704233a965ccbaf9292e8692c3e4/element; $sData={"using":"css selector","value":"body"} __WD_Post: StatusCode=200; ResponseText={"value":{"element-6066-11e4-a52e-4f735466cecf":"91a394f0-004c-480d-aedf-52e2b30233c6"}}... _WD_FindElement: {"value":{"element-6066-11e4-a52e-4f735466cecf":"91a394f0-004c-480d-aedf-52e2b30233c6"}} _WD_WaitElement ==> Success __WD_Post: URL=HTTP://127.0.0.1:9515/session/cd08704233a965ccbaf9292e8692c3e4/element; $sData={"using":"css selector","value":"body"} __WD_Post: StatusCode=200; ResponseText={"value":{"element-6066-11e4-a52e-4f735466cecf":"91a394f0-004c-480d-aedf-52e2b30233c6"}}... _WD_FindElement: {"value":{"element-6066-11e4-a52e-4f735466cecf":"91a394f0-004c-480d-aedf-52e2b30233c6"}} __WD_Post: URL=HTTP://127.0.0.1:9515/session/cd08704233a965ccbaf9292e8692c3e4/execute/sync; $sData={"script":"arguments[0].style='background: #FFFF66; border-radius: 5px; padding-left: 3px;'; return true;", "args":[{"element-6066-11e4-a52e-4f735466cecf":"91a394f0-004c-480d-aedf-52e2b30233c6"}]} __WD_Post: StatusCode=200; ResponseText={"value":true}... _WD_ExecuteScript: {"value":true}... __WD_Post: URL=HTTP://127.0.0.1:9515/session/cd08704233a965ccbaf9292e8692c3e4/element; $sData={"using":"css selector","value":"img.print-link"} __WD_Post: StatusCode=200; ResponseText={"value":{"element-6066-11e4-a52e-4f735466cecf":"eb9e4673-4dec-4d4c-be6a-b7967743394b"}}... _WD_FindElement: {"value":{"element-6066-11e4-a52e-4f735466cecf":"eb9e4673-4dec-4d4c-be6a-b7967743394b"}} _WD_WaitElement ==> Success __WD_Post: URL=HTTP://127.0.0.1:9515/session/cd08704233a965ccbaf9292e8692c3e4/element; $sData={"using":"css selector","value":"img.print-link"} __WD_Post: StatusCode=200; ResponseText={"value":{"element-6066-11e4-a52e-4f735466cecf":"eb9e4673-4dec-4d4c-be6a-b7967743394b"}}... _WD_FindElement: {"value":{"element-6066-11e4-a52e-4f735466cecf":"eb9e4673-4dec-4d4c-be6a-b7967743394b"}} __WD_Post: URL=HTTP://127.0.0.1:9515/session/cd08704233a965ccbaf9292e8692c3e4/element/eb9e4673-4dec-4d4c-be6a-b7967743394b/click; $sData={"id":"eb9e4673-4dec-4d4c-be6a-b7967743394b"} __WD_Post: StatusCode=200; ResponseText={"value":null}... _WD_ElementAction: {"value":null}... __WD_Post: URL=HTTP://127.0.0.1:9515/session/cd08704233a965ccbaf9292e8692c3e4/execute/sync; $sData={"script":"arguments[0].style='background: #FFFF66; border-radius: 5px; padding-left: 3px;'; return true;", "args":[{"element-6066-11e4-a52e-4f735466cecf":"eb9e4673-4dec-4d4c-be6a-b7967743394b"}]} __WD_Post: StatusCode=200; ResponseText={"value":true}... _WD_ExecuteScript: {"value":true}... __WD_Post: URL=HTTP://127.0.0.1:9515/session/cd08704233a965ccbaf9292e8692c3e4/execute/sync; $sData={"script":"return document.readyState", "args":[]} __WD_Post: StatusCode=500; ResponseText={"value":{"error":"script timeout","message":"script timeout\n (Session info: chrome=92.0.4515.107)... __WD_Post ==> Webdriver Exception: {"value":{"error":"script timeout","message":"script timeout\n (Session info: chrome=92.0.4515.107)","stacktrace":"Backtrace:\n\tOrdinal0 [0x00C63733+2504499]\n\tOrdinal0 [0x00BFC401+2081793]\n\tOrdinal0 [0x00B024F0+1058032]\n\tOrdinal0 [0x00B55685+1398405]\n\tOrdinal0 [0x00B45E83+1334915]\n\tOrdinal0 [0x00B54CDB+1395931]\n\tOrdinal0 [0x00B45D4B+1334603]\n\tOrdinal0 [0x00B222B4+1188532]\n\tOrdinal0 [0x00B23149+1192265]\n\tGetHandleVerifier [0x00DDFB8C+1512252]\n\tGetHandleVerifier [0x00E8B0DF+2214031]\n\tGetHandleVerifier [0x00CE4BC3+484211]\n\tGetHandleVerifier [0x00CE3E69+480793]\n\tOrdinal0 [0x00C0218D+2105741]\n\tOrdinal0 [0x00C066E8+2123496]\n\tOrdinal0 [0x00C06827+2123815]\n\tOrdinal0 [0x00C0FB73+2161523]\n\tBaseThreadInitThunk [0x75EB62C4+36]\n\tRtlSubscribeWnfStateChangeNotification [0x77C11B69+1081]\n\tRtlSubscribeWnfStateChangeNotification [0x77C11B34+1028]\n"}} _WD_ExecuteScript: {"value":{"error":"script timeout","message":"script timeout\n (Session info: chrome=92.0.4515.107)... _WD_ExecuteScript ==> Webdriver Exception: HTTP status = 500 _WD_LoadWait ==> Webdriver Exception __WD_Post: URL=HTTP://127.0.0.1:9515/session/cd08704233a965ccbaf9292e8692c3e4/element; $sData={"using":"css selector","value":"body"} __WD_Post: StatusCode=200; ResponseText={"value":{"element-6066-11e4-a52e-4f735466cecf":"91a394f0-004c-480d-aedf-52e2b30233c6"}}... _WD_FindElement: {"value":{"element-6066-11e4-a52e-4f735466cecf":"91a394f0-004c-480d-aedf-52e2b30233c6"}} _WD_WaitElement ==> Success __WD_Post: URL=HTTP://127.0.0.1:9515/session/cd08704233a965ccbaf9292e8692c3e4/element; $sData={"using":"css selector","value":"body"} __WD_Post: StatusCode=200; ResponseText={"value":{"element-6066-11e4-a52e-4f735466cecf":"91a394f0-004c-480d-aedf-52e2b30233c6"}}... _WD_FindElement: {"value":{"element-6066-11e4-a52e-4f735466cecf":"91a394f0-004c-480d-aedf-52e2b30233c6"}} __WD_Post: URL=HTTP://127.0.0.1:9515/session/cd08704233a965ccbaf9292e8692c3e4/execute/sync; $sData={"script":"arguments[0].style='background: #FFFF66; border-radius: 5px; padding-left: 3px;'; return true;", "args":[{"element-6066-11e4-a52e-4f735466cecf":"91a394f0-004c-480d-aedf-52e2b30233c6"}]} __WD_Post: StatusCode=200; ResponseText={"value":true}... _WD_ExecuteScript: {"value":true}...  
      Is it even possible to select elements in print page?

    • By walec
      Hello
      How can I export a sheet to pdf using the OOoCalc.au3 UDF?
      Thank you for any hints or possibly other solutions / functions.
×
×
  • Create New...