Sign in to follow this  
Followers 0
fmen

My gui flashes

9 posts in this topic

I am trying to get a gui to show when the program, "JellyFish" is active and hide when it is not active.

The hidden part works fine but the gui flashes off and on when "JellyFish" is active.

Opt("SendKeyDelay", '.01')
Opt("WinTitleMatchMode", 2)
Opt("TrayIconDebug", 1)
#include <GUIConstants.au3>

HotKeySet("{ESC}", "Terminate")
;_______________________________________________

If Not WinExists("JellyFish") Then Run("J:\RS\JF\jfp3032.exe")
WinWaitActive("JellyFish")
WinMove("JellyFish","", 32 ,182, 981, 710)

;______________________________________________________________________________

$GuiWidth = 100
$GuiHeight = 520
$xPos = 880
$yPos = 137
$Gui = GUICreate("Jelly", 100, 100,$xpos, $yPos, $WS_POPUP,  _
BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))

$Swap = GUICtrlCreateButton ("Swap", 15, 20 ,75 ,15)
$Finish = GUICtrlCreateButton ("Finish", 15, 40 ,75 ,15)
$Manual = GUICtrlCreateButton ("Manual", 15, 60 ,75 ,15)
$Roll = GUICtrlCreateButton ("Roll", 15, 80 ,75 ,15)

GUISetState(@SW_SHOW)
;_______________________________________________________________________________

Do
    Sleep(10)
    $msg = GUIGetMsg()
   If Not WinExists("JellyFish") Then Call("Terminate")
   If Not WinActive("JellyFish") Then 
       GUISetState(@SW_HIDE)
    Else
    GUISetState(@SW_SHOW) 
    Endif
    
    Select
        Case $msg= $Swap
            WinActivate("JellyFish")
            Send("^w")
        Case $msg= $Finish
            WinActivate("JellyFish")
            Send("^a")
        Case $msg= $Manual
            WinActivate("JellyFish")
            Send("!sd")
        Case $msg= $Roll
            Run ("J:\RS\JF\Roll.exe")
            ;Terminate()
        Case $msg= $GUI_EVENT_CLOSE
            MsgBox(0,"You clicked on", "Close")
    EndSelect
Until $msg = $GUI_EVENT_CLOSE 

;_______________________________________________

Func Terminate()
    Exit 0
EndFunc

This part is obviously the part that stinks:

If Not WinActive("JellyFish") Then 
    GUISetState(@SW_HIDE)
   Else
    GUISetState(@SW_SHOW) 
   Endif

Thanks

Share this post


Link to post
Share on other sites

fmen,

It flashes because you activate the script window when you @SW_SHOW it, which means that your JellyFish window is no longer active and so the next pass hides it and reactivates the JellyFish window, which on the next pass shows the script window........... :P

You get the idea. :party:

You need to check both windows on each pass and use @SW_SHOWNOACTIVATE to get the script Window to display. Here is your script modified (I had to use Notepad rather than Jellyfish, but I am sure the principle is the same:

Opt("SendKeyDelay", '.01')
Opt("WinTitleMatchMode", 2)
Opt("TrayIconDebug", 1)

#include <GUIConstants.au3>
#include <WindowsConstants.au3>

HotKeySet("{ESC}", "Terminate")
;_______________________________________________

If Not WinExists("Untitled") Then Run("Notepad")
WinWaitActive("Untitled")
WinMove("Untitled", "", 32, 182, 981, 710)

;______________________________________________________________________________

$GuiWidth = 100
$GuiHeight = 520
$xPos = 880
$yPos = 137
$Gui = GUICreate("Jelly", 100, 100, $xPos, $yPos, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))

$Swap = GUICtrlCreateButton("Swap", 15, 20, 75, 15)
$Finish = GUICtrlCreateButton("Finish", 15, 40, 75, 15)
$Manual = GUICtrlCreateButton("Manual", 15, 60, 75, 15)
$Roll = GUICtrlCreateButton("Roll", 15, 80, 75, 15)

GUISetState(@SW_SHOW)
;_______________________________________________________________________________

Do
    If Not WinExists("Untitled") Then Terminate() ; <<<<<<<<<<<<<<<<<<<<<<<<< No need to use Call here

    If BitAND(WinGetState("Untitled"), 8) = 8 And BitAND(WinGetState($Gui), 2) <> 2 Then
        GUISetState(@SW_SHOWNOACTIVATE, $Gui)
    ElseIf BitAND(WinGetState("Untitled"), 8) <> 8 And BitAND(WinGetState($Gui), 2) = 2 Then
        GUISetState(@SW_HIDE, $Gui)
    EndIf

    $msg = GUIGetMsg()
    Select
        Case $msg = $Swap
            WinActivate("JellyFish")
            Send("^w")
        Case $msg = $Finish
            WinActivate("JellyFish")
            Send("^a")
        Case $msg = $Manual
            WinActivate("JellyFish")
            Send("!sd")
        Case $msg = $Roll
            Run("J:\RS\JF\Roll.exe")
            ;Terminate()
        ;Case $msg = $GUI_EVENT_CLOSE ; <<<<<<<<<<<<<<<< You do not have an [X] to click!
        ;   MsgBox(0, "You clicked on", "Close")
    EndSelect

Until $msg = $GUI_EVENT_CLOSE

;_______________________________________________

Func Terminate()
    Exit 0
EndFunc   ;==>Terminate

I also added in the missing #include file and made a couple of other small suggestions. :party:

I hope that now works as you want. :mellow:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

Thank you very much for that, Melba....

I would not have figured that out. The gui shows and hides appropriately now, but the gui buttons no longer function.

For example,

Case $msg = $Swap
            WinActivate("Untitled")
            Send("!fx")

will not close Notepad.

I am not sure why.

Thanks again.....

Share this post


Link to post
Share on other sites

fmen,

Sorry about that - there are many ways to stop the flashing, but you have to pick the right one to let you use the GUIs correctly. :mellow:

This version (which does not look terribly different from the other) seems to work correctly and closes Notepad when you press "Finish":

Opt("SendKeyDelay", '.01')
Opt("WinTitleMatchMode", 2)
Opt("TrayIconDebug", 1)

#include <GUIConstants.au3>
#include <WindowsConstants.au3>

HotKeySet("{ESC}", "Terminate")
;_______________________________________________

If Not WinExists("Untitled") Then Run("Notepad")
WinWaitActive("Untitled")
WinMove("Untitled", "", 32, 182, 981, 710)

;______________________________________________________________________________

$GuiWidth = 100
$GuiHeight = 520
$xPos = 880
$yPos = 137
$Gui = GUICreate("Jelly", 100, 100, $xPos, $yPos, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))

$Swap = GUICtrlCreateButton("Swap", 15, 20, 75, 15)
$Finish = GUICtrlCreateButton("Finish", 15, 40, 75, 15)
$Manual = GUICtrlCreateButton("Manual", 15, 60, 75, 15)
$Roll = GUICtrlCreateButton("Roll", 15, 80, 75, 15)

GUISetState(@SW_SHOW)
;_______________________________________________________________________________

Do
    If Not WinExists("Untitled") Then Terminate()

    If BitAND(WinGetState("Untitled"), 8) <> 8 And BitAND(WinGetState($Gui), 2) <> 2 Then
        GUISetState(@SW_HIDE, $Gui)
    ElseIf BitAND(WinGetState("Untitled"), 8) = 8 And BitAND(WinGetState($Gui), 2) = 2 Then
        GUISetState(@SW_SHOW, $Gui)
        WinActivate("Untitled")
    EndIf

    $msg = GUIGetMsg()
    Select
        Case $msg = $Swap
            WinActivate("JellyFish")
            Send("^w")
        Case $msg = $Finish
            WinActivate("Untitled")
             Send("!f")
             Sleep(100)
             Send("x")
        Case $msg = $Manual
            WinActivate("JellyFish")
            Send("!sd")
        Case $msg = $Roll
            Run("J:\RS\JF\Roll.exe")
    EndSelect

Until $msg = $GUI_EVENT_CLOSE

;_______________________________________________

Func Terminate()
    Exit 0
EndFunc   ;==>Terminate

Note that I have separated the 2 elements of the Send command - I have always found it works better that way! :party:

I hope that solves your problem. :P

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

#5 ·  Posted (edited)

Wow, I see that the small changes made to the "BitAND(WinGetState" allowed the buttons to function, but gui no longer goes to a hidden state when Notepad is inactive....

Sorry...

Edited by fmen

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

The logic for hiding is wrong.

You want to hide IF

-app(notepad/jellyfish) is not focused

AND

-GUI is not focused (don't want to hide the gui if the user is using it actively)

AND

-gui is not already hidden. ( no need to hide a hidden window )

You want to show the GUI IF

-Notepad/Jellyfish is Active (The user needs the gui again)

AND

-The GUI is currently hidden (no need to re show an already visible window)

Opt("SendKeyDelay", '.01')
Opt("WinTitleMatchMode", 2)
Opt("TrayIconDebug", 1)

#include <GUIConstants.au3>
#include <WindowsConstants.au3>

HotKeySet("{ESC}", "Terminate")
;_______________________________________________

If Not WinExists("Untitled") Then Run("Notepad")
WinWaitActive("Untitled")
WinMove("Untitled", "", 32, 182, 981, 710)

;______________________________________________________________________________

$GuiWidth = 100
$GuiHeight = 520
$xPos = 880
$yPos = 137
$Gui = GUICreate("Jelly", 100, 100, $xPos, $yPos, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))

$Swap = GUICtrlCreateButton("Swap", 15, 20, 75, 15)
$Finish = GUICtrlCreateButton("Finish", 15, 40, 75, 15)
$Manual = GUICtrlCreateButton("Manual", 15, 60, 75, 15)
$Roll = GUICtrlCreateButton("Roll", 15, 80, 75, 15)

GUISetState(@SW_SHOW)
;_______________________________________________________________________________
Do
    If Not WinExists("Untitled") Then Terminate()
    If BitAND(WinGetState("Untitled"), 8) <> 8 And BitAND(WinGetState($Gui), 8) <> 8 And BitAND(WinGetState($Gui), 2) = 2 Then
        GUISetState(@SW_HIDE, $Gui)
    ElseIf BitAND(WinGetState("Untitled"), 8) = 8 And BitAND(WinGetState($Gui), 2) <> 2 Then
        GUISetState(@SW_SHOW, $Gui)
        WinActivate("Untitled")
    EndIf

    $msg = GUIGetMsg()
    Select
        Case $msg = $Swap
            WinActivate("JellyFish")
            Send("^w")
        Case $msg = $Finish
            WinActivate("Untitled")
             Send("!f")
             Sleep(100)
             Send("x")
        Case $msg = $Manual
            WinActivate("JellyFish")
            Send("!sd")
        Case $msg = $Roll
            Run("J:\RS\JF\Roll.exe")
    EndSelect

Until $msg = $GUI_EVENT_CLOSE

;_______________________________________________

Func Terminate()
    Exit 0
EndFunc   ;==>Terminate
Edited by danwilli

Share this post


Link to post
Share on other sites

danwilli,

Thanks for that helping hand. Too much emotion after the game last evening! (Or at least that is my excuse! :mellow: )

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

Danwilli, thank you much for the fix. I understood the logic, but unfortunately could not translate it into code.

Still not sure how adding $a and $a+ accomplished the feat but I will continue trying to figure it out .

Share this post


Link to post
Share on other sites

Danwilli, thank you much for the fix. I understood the logic, but unfortunately could not translate it into code.

Still not sure how adding $a and $a+ accomplished the feat but I will continue trying to figure it out .

LMAO... sorry... foot in mouth moment here. The $a and $a+ have nothing to do with the fix. you can remove them. They were there for testing only. I have edited the above code to rid them. The fix was in the logic here:

If BitAND(WinGetState("Untitled"), 8) <> 8 And BitAND(WinGetState($Gui), 8) <> 8 And BitAND(WinGetState($Gui), 2) = 2 Then
        GUISetState(@SW_HIDE, $Gui)
    ElseIf BitAND(WinGetState("Untitled"), 8) = 8 And BitAND(WinGetState($Gui), 2) <> 2 Then
        GUISetState(@SW_SHOW, $Gui)
        WinActivate("Untitled")
    EndIf

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  
Followers 0