Jump to content

Recommended Posts

Posted

I have a gui with a simple gdi plus test button. I added context menu to gui. The context menu works only when you right click over the gui upper border, but when you click in the middle of the gui, context menu doesnt work. How can I change this?

 

#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
#AutoIt3Wrapper_Run_AU3Check=n
;Opt('MustDeclareVars', 1)

_Main()

Func _Main()
    Local $hGUI, $hGraphic, $hBrush
    Local $hFormat, $hFamily, $hFont, $tLayout
    Local $sString = "Hello world", $aInfo, $label, $msg
    ; Create GUI
    $hGUI = GUICreate("GDI+", 400, 300)

    $ContextMenu = GUICtrlCreateContextMenu()

$MenuItem1 = GUICtrlCreateMenuItem("Menu Item1", $ContextMenu, 1)
GUICtrlSetState($MenuItem1, $GUI_CHECKED)
GUICtrlSetOnEvent($MenuItem1, "FuncMenuItem1")

$separator1 = GUICtrlCreateMenuItem("", $ContextMenu) ; create a separator line
$MenuItem2 = GUICtrlCreateMenuItem("Menu Item2", $ContextMenu)
GUICtrlSetOnEvent($MenuItem2, "FuncMenuItem2")

$separator1 = GUICtrlCreateMenuItem("", $ContextMenu) ; create a separator line

$MenuItemExit = GUICtrlCreateMenuItem("Exit", $ContextMenu)
GUICtrlSetOnEvent($MenuItemExit, "quitclk")

GUISetState(@SW_SHOW)




    GUISetState()

    ; Fill a rectangle
    _GDIPlus_Startup ()
    $hBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hGUI)
    $label = GUICtrlCreateLabel("", 0, 0, 400,300)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    _GDIPlus_GraphicsFillRect($hGraphic, 10, 10, 100, 25,$hBrush)

    $hFormat = _GDIPlus_StringFormatCreate ()
    $hFamily = _GDIPlus_FontFamilyCreate ("Arial")
    $hFont = _GDIPlus_FontCreate ($hFamily, 10, 0)
    $tLayout = _GDIPlus_RectFCreate (10, 10, 0, 0)
    $aInfo = _GDIPlus_GraphicsMeasureString ($hGraphic, $sString, $hFont, $tLayout, $hFormat)
    $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000)
    _GDIPlus_GraphicsDrawStringEx ($hGraphic, $sString, $hFont, $aInfo[0], $hFormat, $hBrush)


    ; Loop until user exits
    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $GUI_EVENT_CLOSE
            _GDIPlus_FontDispose ($hFont)
            _GDIPlus_FontFamilyDispose ($hFamily)
            _GDIPlus_StringFormatDispose ($hFormat)
            _GDIPlus_BrushDispose($hBrush)
            _GDIPlus_GraphicsDispose ($hGraphic)
            _GDIPlus_Shutdown ()
                Exit
            Case $label
                MsgBox(0, "Test", "Clicked on GFX")
        EndSwitch
    WEnd

    ; Clean up resources

EndFunc   ;==>_Main

 

Great thanx in advance

Posted

Create context menu after you create label that occupies the space of entire GUI, and then use control ID of that label as parameter to GUICtrlCreateContextMenu().

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
  • Recently Browsing   0 members

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