Sign in to follow this  
Followers 0
nekkutta

$WS_EX_TOPMOST set after GUI Creation

4 posts in this topic

OK, I have a problem, I'm trying to set up a "Always on top" menu item, and it is not staying on top after clicking

$progressGui[0] is the hwnd from the guicreate, and $progressGui[5] is the always on top menuitem

Func mnuOnTopClick()
    If BitAnd(GUICtrlRead($progressGui[5]),$GUI_CHECKED) Then
        ;uncheck, remove always on top
        GUISetStyle(-1,-1,$progressGui[0])
        GUICtrlSetState($progressGui[5],$GUI_UNCHECKED)
    Else
        ;check, set always on top
        GUISetStyle(-1,$WS_EX_TOPMOST,$progressGui[0])
        GUICtrlSetState($progressGui[5],$GUI_CHECKED)
    EndIf

EndFunc

anyone know why this wouldn't be working


[size="2"] "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." - Brian Kernighan[/size]

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Setting the style itself is the hard way, better use the provided function WinSetOnTop().

Func mnuOnTopClick()
    If BitAND(GUICtrlRead($c_Checkbox), $GUI_CHECKED) Then
        WinSetOnTop($hGUI,"",1)
    Else
        WinSetOnTop($hGUI,"",0)
    EndIf
EndFunc   ;==>mnuOnTopClick

Edit: Imho you could achieve the same with GUIGetStyle(), but you have to read the current style with GUIGetStyle() first, then subtract or add the $WS_EX_TOPMOST style flag and finally hide and show the gui again to apply the style change. So better stick to solution provided above :).

Edited by KaFu

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Setting the style itself is the hard way, better use the provided function WinSetOnTop().

D'oh!!!! I didn't even notice that. I keep forgetting about the Win... functions. Thank you! maybe one of these days I actually remember that the Win... functions aren't just for controlling Other programs' windows.

Thanks again.

EDIT, Would It be possible to use that on the builtin ProgressOn() window?

Edited by nekkutta

[size="2"] "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." - Brian Kernighan[/size]

Share this post


Link to post
Share on other sites

Sure, try something like this:

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

$hGUI = GUICreate("My GUI") ; will create a dialog box that when displayed is centered
$c_Checkbox = GUICtrlCreateCheckbox("OnTop", 10, 10)
GUISetState(@SW_SHOW) ; will display an empty dialog box

ProgressOn("Progress Window", "Test")
Global $hWnd_Progress = _hWnd_Progress("Progress Window")
mnuOnTopClick()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $c_Checkbox
            mnuOnTopClick()
    EndSwitch
WEnd


Func mnuOnTopClick()
    If BitAND(GUICtrlRead($c_Checkbox), $GUI_CHECKED) Then
        WinSetOnTop($hGUI, "", 1)
        WinSetOnTop($hWnd_Progress, "", 1)
    Else
        WinSetOnTop($hGUI, "", 0)
        WinSetOnTop($hWnd_Progress, "", 0)
    EndIf
EndFunc   ;==>mnuOnTopClick


Func _hWnd_Progress($sTitle = "")
    If Not $sTitle Then Return SetError(1)
    Local $aWinlist = WinList($sTitle)
    For $i = 1 To $aWinlist[0][0]
        If WinGetProcess($aWinlist[$i][1]) = @AutoItPID Then Return $aWinlist[$i][1]
    Next
    Return SetError(2)
EndFunc   ;==>_hWnd_Progress

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