Jump to content

Having a status window always on top, never active


borreo
 Share

Go to solution Solved by Lepes,

Recommended Posts

I would like to add to most of my scripts a status window that stays always on top, but never gets activated.

I wrote a sample script to show what I mean: it just keeps typing an A every 3 seconds (just as a proof of concept); the status window displays the countdown, and stops the script when the status window is closed.

I run the script, then open a blank file on a text editor (activating it) and wait for the A to appear. Everything works, except that the status window does not come to the front. I tried different parameters to GuiSetState, but no luck. What shoudl I do?

 

#include <GUIConstants.au3>
$Main = GUICreate("StatusBar GUI")
$label = GUICtrlCreateLabel("Default StatusBar Text", 0, 380, 400, 20, $SS_SUNKEN + $SS_CENTER)

;GUISetState (@SW_SHOWNOACTIVATE)

$NextPause = 3

While 1
    ;GUISetState (@SW_SHOWNOACTIVATE)
    GUISetState (@SW_SHOWNA)
    GUICtrlSetData($label, $NextPause)
    Sleep( 1000 ) ;
    If GUIGetMsg() = $GUI_EVENT_CLOSE Then ExitLoop
    $NextPause = $NextPause - 1
    If $NextPause <= 0 Then
        Send( "A" )
        $NextPause = 3
    EndIf
Wend

 

screenshot.png

Link to comment
Share on other sites

Hi @borreo,

please have a look at:

GUISetStyle(-1, $WS_EX_TOPMOST, $Main)

for your example case. This should set your status window to the top (in the foreground).
Besides that, I suggest you to refactor your code 😅 .

Best regards
Sven

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Link to comment
Share on other sites

It is not working, the windows stays behind

 

#include <GUIConstants.au3>
$Main = GUICreate("StatusBar GUI")
$label = GUICtrlCreateLabel("Default StatusBar Text", 0, 380, 400, 20, $SS_SUNKEN + $SS_CENTER)

;GUISetState (@SW_SHOWNOACTIVATE)
$NextPause = 3

While 1
    ;GUISetState (@SW_SHOWNOACTIVATE)
    GUISetState (@SW_SHOWNA)
    GUICtrlSetData($label, $NextPause)
    GUISetStyle(-1, $WS_EX_TOPMOST, $Main)
    Sleep( 1000 ) ;
    If GUIGetMsg() = $GUI_EVENT_CLOSE Then ExitLoop
    $NextPause = $NextPause - 1
    If $NextPause <= 0 Then
        Send( "A" )
        $NextPause = 3
    EndIf
Wend

 

Link to comment
Share on other sites

No, please move the line under line 2 "$Main = ...", as line 3, then it should work.

Best regards
Sven

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Link to comment
Share on other sites

  • Solution

this seems to work

 

#include <GUIConstants.au3>
$Main = GUICreate("StatusBar GUI", 380, 400,-1,-1, -1, $WS_EX_TOPMOST)
$label = GUICtrlCreateLabel("Default StatusBar Text", 0, 380, 400, 20, $SS_SUNKEN + $SS_CENTER)
GUISetState (@SW_SHOWNA, $Main)

$NextPause = 3

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then Exit
    GUICtrlSetData($label, $NextPause)
    Sleep( 1000 ) 

    $NextPause = $NextPause - 1
    If $NextPause <= 0 Then
        Send( "A" )
        $NextPause = 3
    EndIf
Wend

It is important to use @SW_SHOWNA  or @SW_SHOWNOACTIVATE, if you use anything different, it seems to loose the TopMost feature (in my test, not sure why).

Link to comment
Share on other sites

To be honest, I don't see the problem @borreo. Anyways, please try this and tell me please if this fits your expectations and requirements?
By the way: No problem with @SW_SHOW 😀 .

#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#AutoIt3Wrapper_Run_Au3Stripper=y
#Au3Stripper_Parameters=/sf /sv /mo /rm /rsln

#include <GUIConstants.au3>

HotKeySet('{ESC}', '_DisposeAndExit')

Global $hGui, $cLabel
Global $iNextPause = 3

_CreateGui()

While True
    _SetLabel()
    _WaitASecond()
    _DoSomething()
Wend

Func _CreateGui()
    $hGui   = GUICreate('StatusBar GUI', 100, 100, Default, Default, -1, $WS_EX_TOPMOST)
    $cLabel = GUICtrlCreateLabel('Default StatusBar Text', 0, 80, Default, Default, $SS_SUNKEN + $SS_CENTER)

    GUISetState(@SW_SHOW, $hGui)
EndFunc

Func _DisposeAndExit()
    GUIDelete($hGui)
    Exit
EndFunc

Func _SetLabel()
    GUICtrlSetData($cLabel, $iNextPause)
EndFunc

Func _WaitASecond()
    Sleep(1000)
EndFunc

Func _DoSomething()
    $iNextPause -= 1

    If $iNextPause <= 0 Then
        Send('A')

        $iNextPause = 3
    EndIf
EndFunc

Best regards
Sven

Edited by SOLVE-SMART

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...