Jump to content
Sign in to follow this  
=sinister=

WinSetOnTop with ContextMenu

Recommended Posts

=sinister=

alright i have a context menu:

$ContextMenu = GUICtrlCreateContextMenu()
$SetOnTop = GUICtrlCreateMenuItem("Set OnTop", $ContextMenu)
$Transparent = GUICtrlCreateMenuItem("Transparent", $ContextMenu)

but, I try using this with the context menu:

Case $SetOnTop
        If BitAnd(GUICtrlRead($SetOnTop),$GUI_CHECKED) = $GUI_CHECKED Then
            GUICtrlSetState($SetOnTop,$GUI_UNCHECKED)
            WinSetOnTop("WoW!Bobber", "", 0)
        Else
            GUICtrlSetState($SetOnTop,$GUI_CHECKED)
            WinSetOnTop("WoW!Bobber", "", 1)
        EndIf

and it won't work on its first try. Any ideas?

Share this post


Link to post
Share on other sites
PsaltyDS

alright i have a context menu:

$ContextMenu = GUICtrlCreateContextMenu()
$SetOnTop = GUICtrlCreateMenuItem("Set OnTop", $ContextMenu)
$Transparent = GUICtrlCreateMenuItem("Transparent", $ContextMenu)

but, I try using this with the context menu:

Case $SetOnTop
        If BitAnd(GUICtrlRead($SetOnTop),$GUI_CHECKED) = $GUI_CHECKED Then
            GUICtrlSetState($SetOnTop,$GUI_UNCHECKED)
            WinSetOnTop("WoW!Bobber", "", 0)
        Else
            GUICtrlSetState($SetOnTop,$GUI_CHECKED)
            WinSetOnTop("WoW!Bobber", "", 1)
        EndIf

and it won't work on its first try. Any ideas?

You can only work with Checked/UnChecked if you use the MenuRadioItem option in GuiCtrlCreateMenuItem. I created a demo with two items (and a separator between them) in the GUI's context menu, but with the MenuRadioItem option, I could only set it the first time it was selected, could never clear it by selecting again, and could not get any of several methods to give me current checked state of the item.

So I gave up on it and went with external global variables to hold the state of the items:

#include <guiconstants.au3>
#include <A3LMenu.au3>

Global $SetOnTopState = False, $TransparentState = False

$hGUI = GUICreate("Test", 300, 100)
$Label_1 = GUICtrlCreateLabel("SetOnTop = " & $SetOnTopState, 10, 20, 200, 20, $SS_CENTER)
$Label_2 = GUICtrlCreateLabel("Transparent = " & $TransparentState, 10, 60, 200, 20, $SS_CENTER)
$ContextMenu = GUICtrlCreateContextMenu()
$hContextMenu = GUICtrlGetHandle(-1)
$SetOnTop = GUICtrlCreateMenuItem("Set OnTop", $ContextMenu)
$Transparent = GUICtrlCreateMenuItem("Transparent", $ContextMenu)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $SetOnTop
            $SetOnTopState = Not $SetOnTopState
            GUICtrlSetData($Label_1, "SetOnTop = " & $SetOnTopState)
        Case $Transparent
            $TransparentState = Not $TransparentState
            GUICtrlSetData($Label_2, "Transparent = " & $TransparentState)
    EndSwitch
WEnd

That doesn't mean it can't be done, but I couldn't make it work in the time I have to try... :)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.