Jump to content

Getting a window topmost by handle [solved]


Recommended Posts

Context

After playing with AutoIt for some time I'm trying to get a window topmost.

I'd like to get the same effect as AutoIt v3 Window Info with the flag Always On Top set.

The window can be put on top of all other windows with a button.

GUI

I have this window with 2 buttons on it.

The first button Set window topmost will change the style of the window to make it topmost.

The second button Set window normal will reset the style of the window.

By default he window is not topmost.

Posted Image

Source code

; --------
; Includes
; --------

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>


; ---------
; Variables
; ---------

Global $varWindow, $varButtonTopmost, $varButtonNormal, $varLoop, $varMessage


; ----
; Main
; ----

$varWindow = GUICreate("Win", 130, 75)
$varButtonTopmost = GUICtrlCreateButton("Set window topmost", 10, 10, 110)
$varButtonNormal = GUICtrlCreateButton("Set window normal", 10, 40, 110)
GUISetState(@SW_SHOW)
$varLoop = True

While $varLoop
    $varMessage = GUIGetMsg()
    Select
        Case $varMessage = $GUI_EVENT_CLOSE
            $varLoop = False
            Exit
        Case $varMessage == $varButtonTopmost
            _Button_Topmost_Clicked()
        Case $varMessage == $varButtonNormal
            _Button_Normal_Clicked()
    EndSelect
WEnd


; ---------
; Functions
; ---------

Func _Button_Topmost_Clicked()
    Local $varStyles = GUIGetStyle($varWindow)
    GUISetStyle($varStyles[0], BitOr($varStyles[1], $WS_EX_TOPMOST), $varWindow)
EndFunc


Func _Button_Normal_Clicked()
    Local $varStyles = GUIGetStyle($varWindow)
    GUISetStyle($varStyles[0], BitXor($varStyles[1], $WS_EX_TOPMOST), $varWindow)
EndFunc

Question

The source code above doesn't work.

The window just won't be placed topmost.

Could someone tell me why this code doesn't work?

As I have been browsing and searching this forum forever help would greatly be appreciated.

Edited by Psychoman
Link to comment
Share on other sites

in your functions, instead of using guictrlsetstate, have you tried WinSetOnTop?

Func _Button_Topmost_Clicked()

WinSetOnTop($varWindow,"",1)

EndFunc

Func _Button_Normal_Clicked()

WinSetOnTop($varWindow,"",0)

EndFunc

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

Would have gotten away with it too if it weren't for those meddling kids, Jabberwocky?

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

in your functions, instead of using guictrlsetstate, have you tried WinSetOnTop?

Actually I didn't.

I came across this function on the forum and in the help files.

The documentation states that the first parameter has to be the name of the window.

WinSetOnTop ( "title", "text", flag )

It's true that if you follow the link in the documentation you get a description on how to use the title parameter.

Although I took a look at that documentation I must have missed the last part, stating that the parameter title can be replaced with a handle.

Now it works like a charm.

Thanks a lot kaotkbliss :)

Link to comment
Share on other sites

Umm so if you are able to click the button, would the window not already be on top?

It changes the flag of the window

1 being always on top so no matter if you click another window afterwards the other will still be on top :)

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

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...