Jump to content
Sign in to follow this  
SlowCoder74

Context menus not working on layered controls?

Recommended Posts

SlowCoder74

My sample code:

Opt("MouseCoordMode",2)

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

    $frmWallboard=GUICreate("Wallboard", 1024, 768, 1, 1)
    GUISetState(@SW_SHOW)

; ... code for a bunch of dynamically created labels all over the screen ...
$Label1 = GUICtrlCreateLabel("Label1", 0, 0, 500, 500) ;sample label


;***************************
;*** DRAW OPTIONS BUTTON ***
;***************************
    $btnOptions = GUICtrlCreateButton("Options", 8, 8, 81, 25)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0x000080)
    GUICtrlSetState(-1, $GUI_HIDE)
    GUICtrlSetState(-1,$GUI_ONTOP) ;if remarked, button is visible, but nonresponsive.  If not remarked, button works, but is invisible until clicked.

    $iOptionsBtnLeft = 8
    $iOptionsBtnTop = 8
    $iOptionsBtnWidth = 81
    $iOptionsBtnHeight = 25

    $OptionsMenu = GUICtrlCreateContextMenu($btnOptions)
    $blah = GUICtrlCreateMenuItem("Minimize to taskbar",$OptionsMenu)

;***********************
;*** MAIN EVENT LOOP ***
;***********************
    While 1
       ;GET GUI MESSAGES
       $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $btnOptions
                msgbox(0,"","You clicked the Options button")
        EndSwitch

        ;IS MOUSE OVER OPTIONS BUTTON?
        if MouseGetPos(0) >=$iOptionsBtnLeft and MouseGetPos(0) <= $iOptionsBtnLeft + $iOptionsBtnWidth and _
        MouseGetPos(1) >=$iOptionsBtnTop and MouseGetPos(1) <= $iOptionsBtnTop + $iOptionsBtnHeight Then
            if ControlCommand($frmWallboard,"",$btnOptions,"IsVisible") = 0 Then
                GUICtrlSetState($btnOptions,$GUI_SHOW)
                ;GUICtrlSetState(-1,$GUI_ONTOP)
            EndIf
            Else
            if ControlCommand($frmWallboard,"",$btnOptions,"IsVisible") = 1 Then GUICtrlSetState($btnOptions,$GUI_HIDE)
        EndIf
    WEnd

The button context menu works, as long as there is no label underneath.

There are mixed results if the label is present.

Note the comment I made about using GUICtrlSetState(-1,$GUI_ONTOP) in the code.

Thanks.

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  

×