Jump to content

Context Menu


LYRRAD
 Share

Recommended Posts

I am trying to create a small mapping program where the user can put marks on a picture/map by right clicking on it and choosing from the menu. I can get it to bring up the context menu but I cannot select anything...please help. The code I got so far is as follows:

#include <GUIConstantsEx.au3>

GUICreate("Site Check",800,600)

GUICtrlCreatePic("C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\blue hills.jpg",-1,-1,0,0)

GUICtrlSetState(-1,$GUI_DISABLE)

$input=GUICtrlCreateInput("",50,200,200,20)

$button=GUICtrlCreateButton("Test",100,250,100,30)

$contextmenu=GuiCtrlCreateContextMenu()

$aboutitem=GuiCtrlCreateMenuitem("About",$contextmenu)

$testitem=GUICtrlCreateMenuItem("Test",$contextmenu)

GuiCtrlCreateMenuitem("",$contextmenu)

$exititem=GuiCtrlCreateMenuitem("Exit",$contextmenu)

GUISetState()

While 1

Switch GUIGetMsg()

Case $GUI_EVENT_CLOSE

Exit

Case $button

MsgBox(64,"Test","You typed..."&GUICtrlRead($input),3)

Case $contextmenu

While 1

Switch $msg=GuiGetMsg()

Case $msg=$exititem

ExitLoop

Case $msg=$aboutitem

Msgbox(0,"About","A simple example with a context menu!")

EndSwitch

WEnd

EndSwitch

WEnd

Link to comment
Share on other sites

  • Moderators

LYRRAD,

Welcome to the AutoIt forum. :mellow:

You were getting too complicated! :party:

#include <GUIConstantsEx.au3>

GUICreate("Site Check", 800, 600)
GUICtrlCreatePic("C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\blue hills.jpg", -1, -1, 0, 0)
GUICtrlSetState(-1, $GUI_DISABLE)
$input = GUICtrlCreateInput("", 50, 200, 200, 20)
$button = GUICtrlCreateButton("Test", 100, 250, 100, 30)

$contextmenu = GUICtrlCreateContextMenu()
$aboutitem = GUICtrlCreateMenuItem("About", $contextmenu)
$testitem = GUICtrlCreateMenuItem("Test", $contextmenu)
GUICtrlCreateMenuItem("", $contextmenu)
$exititem = GUICtrlCreateMenuItem("Exit", $contextmenu)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $button
            MsgBox(64, "Test", "You typed..." & GUICtrlRead($input), 3)
        Case $exititem
            ExitLoop
        Case $aboutitem
            MsgBox(0, "About", "A simple example with a context menu!")
    EndSwitch
WEnd

M23

Edit: When you post code please use Code tags. Put [autoit ] before and [/autoit ] after your posted code (but omit the trailing space - it is only there so the tags display here). Or press the blue button just under the BOLD toolbar button. :P

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I am now trying to record the coordinates of the mouse position where the context menu was brought up. I have it when 'TEST' is clicked in the context menu the coordinates of the mouse is shown but only depending on where you clicked on the 'TEST' context menu item. Again...help is greatly appreciated. Thank you in advance.

#include <GUIConstantsEx.au3>
Opt("MouseCoordMode",0)

GUICreate("Site Check",800,600)
GUICtrlCreatePic("C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\blue hills.jpg",-1,-1,0,0)
GUICtrlSetState(-1,$GUI_DISABLE)
$input=GUICtrlCreateInput("",50,200,200,20)
$button=GUICtrlCreateButton("Test",100,250,100,30)

$contextmenu=GuiCtrlCreateContextMenu()
$aboutitem=GuiCtrlCreateMenuitem("About",$contextmenu)
$testitem=GUICtrlCreateMenuItem("Test",$contextmenu)
GuiCtrlCreateMenuitem("",$contextmenu)
$exititem=GuiCtrlCreateMenuitem("Exit",$contextmenu)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $button
            MsgBox(64,"Test","You typed..."&GUICtrlRead($input),3)
        Case $aboutitem
            Msgbox(0,"About","A simple example with a context menu!")
        Case $testitem
            $mousepos=MouseGetPos()
            MsgBox(0,"Mouse x,y:",$mousepos[0]&","&$mousepos[1])
        Case $exititem
            ExitLoop
    EndSwitch
WEnd
Link to comment
Share on other sites

I solved my problem. I used the '_IsPressed' command and checked for the right click. Later I will modify it to change the clicking method to accomodate people that have there mouse buttons switched within Windows. Again thank you all. I have posted my code to so others can see what I did and possibly assist others. I am still open to any other suggestions on how to do this...its just that this is working so I will stick with this solution for now.

#include <GUIConstantsEx.au3>
#Include <Misc.au3>
Opt("MouseCoordMode",0)

GUICreate("Site Check",800,600)
GUICtrlCreatePic("C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\blue hills.jpg",-1,-1,0,0)
GUICtrlSetState(-1,$GUI_DISABLE)
$input=GUICtrlCreateInput("",50,200,200,20)
$button=GUICtrlCreateButton("Test",100,250,100,30)

$contextmenu=GuiCtrlCreateContextMenu()
$aboutitem=GuiCtrlCreateMenuitem("About",$contextmenu)
$testitem=GUICtrlCreateMenuItem("Test",$contextmenu)
GuiCtrlCreateMenuitem("",$contextmenu)
$exititem=GuiCtrlCreateMenuitem("Exit",$contextmenu)

GUISetState()

While 1
    If _IsPressed("02") Then
        $mousepos=GUIGetCursorInfo()
    EndIf
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $button
            MsgBox(64,"Test","You typed..."&GUICtrlRead($input),3)
        Case $aboutitem
            Msgbox(0,"About","A simple example with a context menu!")
        Case $testitem
            MsgBox(0,"Mouse x,y:",$mousepos[0]&","&$mousepos[1])
        Case $exititem
            ExitLoop
    EndSwitch
WEnd
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...