Jump to content
nacerbaaziz

Can we create a single context menu on more than one control?

Recommended Posts

Hello my friends
Can we create a single context menu on more than one item?
For example, a context menu includes standardized options on more than one control, such as buttons or check boxes
to Create a context menu on one item am using this function
GUICtrlCreateContextMenu ($ HWND)
How to link it with more than one element please?
or if we can't do that, please give me a solution
so i tried to add an context menus to all the controls but the script will be long, for that if their are any solutions i hope to give it to me
thanks in advanced

Edited by nacerbaaziz

Share this post


Link to post
Share on other sites
3 hours ago, nacerbaaziz said:

Can we create a single context menu on more than one item?

Yes

 

3 hours ago, nacerbaaziz said:

How to link it with more than one element please?

Possible

3 hours ago, nacerbaaziz said:

thanks

np, glad I could help

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

This is a way to create the same context menu for multiple items. Essentially create the controls on an array, then loop through them and create the context for each one that way.

; right click on gui to bring up context Menu.
; right click on the "ok" button to bring up a controll specific context menu.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
GUICreate("My GUI Context Menu", 300, 200)
;=============================================================================
Global $Controls[3]
$Controls[0] = GUICtrlCreateButton('1', 10, 10, 50, 20)
$Controls[1] = GUICtrlCreateButton('2', 10, 40, 50, 20)
$Controls[2] = GUICtrlCreateButton('3', 10, 70, 50, 20)
;=============================================================================
GUISetState(@SW_SHOW)
;=============================================================================
For $c = 0 To UBound($Controls)-1
Local $idContextmenu = GUICtrlCreateContextMenu($Controls[$c])
Local $idNewsubmenu = GUICtrlCreateMenu("new", $idContextmenu)
Local $idNewsubmenuText = GUICtrlCreateMenuItem("text", $idNewsubmenu)
Local $idMenuInfo = GUICtrlCreateMenuItem("Info", $idContextmenu)
ConsoleWrite($Controls[$c] &@CRLF)
Next
;=============================================================================
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
    GUIDelete()
EndFunc   ;==>Example

 


Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites

hi brothers

please i tried this but i did not succeed

can you show me my error

note this is just a section from an big script

please help me to add the context menu into $label and $label0

 

global $label0 = GUICtrlCreateLabel(str("title"), 150, 90, 250, 20, $WS_TABSTOP)
GUICtrlSetResizing (-1, 1)
GUICtrlSetBkColor(-1, 0x461B7E)
GUICtrlSetFont(-1, 14, 400, 0, "Arial", 0)
GUICtrlSetOnEvent(-1, "order")

GUICtrlSetState(-1, $GUI_focus)
GUIStartGroup("")

Global $listFile2 = GUICtrlCreateIcon("", -1, 10, 130, 32, 32)
GUICtrlSetResizing (-1, 1)
GUICtrlSetOnEvent(-1, "order")
_Resource_SetToCtrlID(-1, 'files', $RT_ICON, Default, True)
GUICtrlSetBkColor(-1, 0x461B7E)
GUICtrlSetColor(-1, 0x461B7E)


Global $Label = GUICtrlCreateLabel(str("noopened"), 50, 130, 420, 40, $WS_TABSTOP +  $WS_GROUP, $WS_EX_ACCEPTFILES)
;GUICtrlSetState(-1, $GUI_DROPACCEPTED)
GUICtrlSetResizing (-1, 1)
GUICtrlSetBkColor(-1, 0x461B7E)
GUICtrlSetFont(-1, 11, 400, 0, "Arial", 0)
GUICtrlSetOnEvent(-1, "order")
GUICtrlSetCursor(-1, -1)
GUIStartGroup("")
Global $Label1 = GUICtrlCreateLabel("", 100, 180, 200, 60)
GUICtrlSetResizing (-1, 1)
GUICtrlSetState(-1, $GUI_disable + $GUI_NOFOCUS + $GUI_hide)
GUICtrlSetBkColor(-1, 0x461B7E)
GUICtrlSetFont(-1, 11, 400, 0, "Arial", 0)
Global $LabelMenu = GUICtrlCreateContextMenu($Label0)
GUICtrlSetOnEvent(-1, "order")
Global $LabelOpen = GUICtrlCreateMenuItem(str("opentofolder") & "... (control+f)", $LabelMenu)
GUICtrlSetOnEvent(-1, "order")
GUICtrlSetState(-1, $GUI_disable)
Global $Labelinfo = GUICtrlCreateMenuItem(str("fileInfo") & "...", $LabelMenu)
GUICtrlSetOnEvent(-1, "order")
GUICtrlSetState(-1, $GUI_disable)
Global $LabelCopyPath = GUICtrlCreateMenuItem(str("copyPath"), $LabelMenu)
GUICtrlSetOnEvent(-1, "order")
GUICtrlSetState(-1, $GUI_disable)
Global $labelCopy = GUICtrlCreateMenuItem(str("copy") & "... (control+shift+C)", $LabelMenu)
GUICtrlSetOnEvent(-1, "order")
GUICtrlSetState(-1, $GUI_disable)
Global $LabelPaste = GUICtrlCreateMenuItem(str("paste") & "... (control+v", $LabelMenu)
GUICtrlSetOnEvent(-1, "order")
Global $labelRemove = GUICtrlCreateMenuItem(str("PLRemove") & "... (del)", $LabelMenu)
GUICtrlSetOnEvent(-1, "order")
GUICtrlSetState(-1, $GUI_disable)
Global $labelDel = GUICtrlCreateMenuItem(str("delete") & "... (shift+del)", $LabelMenu)
GUICtrlSetOnEvent(-1, "order")
GUICtrlSetState(-1, $GUI_disable)
Global $LabelRename = GUICtrlCreateMenuItem(str("rename") & "... (shift+f2)", $LabelMenu)
GUICtrlSetOnEvent(-1, "order")
GUICtrlSetState(-1, $GUI_disable)
Global $LabelProperties = GUICtrlCreateMenuItem(str("Properties") & "... (alt+enter)", $LabelMenu)
GUICtrlSetOnEvent(-1, "order")
GUICtrlSetState(-1, $GUI_disable)
_GUICtrlMenu_TrackPopupMenu($LabelMenu, $label, -1, -1, 1, 1, 1, 0)

 

Share this post


Link to post
Share on other sites

Could you post a reproducible script? One where i dont have to put all the necessary includes and so on?

Also, could you enclose your code with the <code> frame/tool? It's right next to the smiley face.

Edited by careca

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites

hi the section that i put here is just for give you an Idea about what i want to do

i have created an big window whitch have multy GUICtrls such as buttons and labels and check boxes and more

and i have a context menu that have items, and i want to link this context menu with more then one control e.g 2 labels

i dont know the right way to do that, please help me by a simple example or gid me to do it.

am sorry about my bed english

Share this post


Link to post
Share on other sites

Are you just ignoring my example? you know, the example right on top of your code.


Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites

dear @careca
 I never ignore your example.
but on this code just the items on the last Context menu can use it because the vars are the same
if you have an other suggestions please give it to me

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
Example()

Func Example()
GUICreate("My GUI Context Menu", 300, 200)
Global $Controls[3]
$Controls[0] = GUICtrlCreateButton('1', 10, 10, 50, 20)
$Controls[1] = GUICtrlCreateButton('2', 10, 40, 50, 20)
$Controls[2] = GUICtrlCreateButton('3', 10, 70, 50, 20)

GUISetState(@SW_SHOW)

For $c = 0 To UBound($Controls)-1
Local $idContextmenu = GUICtrlCreateContextMenu($Controls[$c])
Local $idNewsubmenu =  GUICtrlCreateMenu("new", $idContextmenu)
Local $idNewsubmenuText = GUICtrlCreateMenuItem("text", $idNewsubmenu)
Local $idMenuInfo = GUICtrlCreateMenuItem("Info", $idContextmenu)
Next
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
case $idMenuInfo
msgBox(0, "", "")
EndSwitch
WEnd
GUIDelete()
EndFunc

 

Edited by nacerbaaziz
Tidied the code and AutoIt3 syntax for codebox

Share this post


Link to post
Share on other sites

@nacerbaaziz, Please Tidy your code and use AutoIt3 in stead of plain text in the CodeBox when posting sourcecode. :)

Thanks Jos

Share this post


Link to post
Share on other sites
40 minutes ago, nacerbaaziz said:

...on this code just the items on the last Context menu can use it because the vars are the same

Can you clarify what you mean? Maybe i didn't understand it correctly, i got the idea that what you want to do is create the same context menu for many items.

This is what it does, puts a context menu in the 3 buttons.

I dont know what you want to do later on, but you can differentiate between the buttons.


Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites

here is a simple example

i want to show the same context menu when press right click on the all labels

please help me

local $hGUI, $HMenu, $ID_Open, $ID_save, $ID_cut, $ID_Label0, $ID_label
$hGUI = GUICreate("menu", 400, 400)
$label0 = GUICtrlCreateLabel("right click to get options", 100, 50, 200, 30)
$label = GUICtrlCreateLabel("right click to get the same options", 100, 110, 200, 30)

$hMenu = GUICtrlCreateContextMenu($label0)
$ID_Open = GUICtrlCreateMenuItem("&open", $hmenu)
$ID_save = GUICtrlCreateMenuItem("save the &file....", $hmenu)
$ID_cut = GUICtrlCreateMenuItem("move the &file....", $hmenu)
GUISetState(@sw_show, $hGUI)

while 1
switch GUIGetMSG()
case -3
exit
case $id_Open
_openFunc()
case $id_save
saveFunc()
case $id_Cut
moveFunc()

endSwitch
Wend
func OpenFunc()
;orders....
endFunc
func saveFunc()
;orders....
endFunc
func MoveFunc()
;orders....
endFunc

 

Share this post


Link to post
Share on other sites
39 minutes ago, nacerbaaziz said:

here is a simple example

50%...  Correct color coding but totally unreadable as the script isn't tidied. You need to learn to properly format code to make it soooo much easier to read and understand!

Jos

Share this post


Link to post
Share on other sites

hi dear my problem is with the code editor dialog

it isn't accessible with my screen reader for that it hard for me to put the code in the correct way

 

Share this post


Link to post
Share on other sites

Use SciTE and it is easy....   I simply move on when I see unreadable code.   your choice though... ;)

Jos

Share this post


Link to post
Share on other sites

Hi nacerbaaziz,

Here is a way to do it. You can add as many controls ID's as you wish in " >>>>>> The 'OR' line <<<<<<"

$hGUI = GUICreate("Menu", 400, 300)
$id_Label_1 = GUICtrlCreateLabel("Right click to get options in menu", 100, 50, 165)
$id_Label_2 = GUICtrlCreateLabel("Right click to get the same options", 100, 110, 165)

$id_Label_hard_to_find = GUICtrlCreateLabel("", 1, 1, 1, 1)
$id_Context = GUICtrlCreateContextMenu($id_Label_hard_to_find)
$id_Open = GUICtrlCreateMenuItem("&Open", $id_Context)
$id_Save = GUICtrlCreateMenuItem("Save the &file....", $id_Context)
$id_Cut = GUICtrlCreateMenuItem("Move the &file....", $id_Context)
$hMenu = GUICtrlGetHandle($id_Context)

GUISetState()

While 1
    $aInfo = GUIGetCursorInfo()
    If Not @error And $aInfo[3] = 1 And _
      ($aInfo[4] = $id_Label_1 Or $aInfo[4] = $id_Label_2) Then ; >>>>>> The 'OR' line <<<<<<
        $mPos = MouseGetPos()
        DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, _
            "int", 0, "int", $mPos[0], "int", $mPos[1], "hwnd", $hGUI, "ptr", 0)
    EndIf

    Switch GUIGetMSG()
        Case -3
            Exit

        Case $id_Open
            OpenFunc()

        Case $id_Save
            SaveFunc()

        Case $id_Cut
            MoveFunc()
    EndSwitch
Wend

Func OpenFunc()
    Msgbox(0, "OpenFunc", "Here we are #1")
EndFunc

Func SaveFunc()
    Msgbox(0, "SaveFunc", "Here we are #2")
EndFunc

Func MoveFunc()
    Msgbox(0, "MoveFunc", "Here we are #3")
EndFunc

Good luck :)

Share this post


Link to post
Share on other sites

@pixelsearch
thank you for your example

dear this way unfortunately   don't work with the screens readers, because Usually the screen readers have a virtual cursor.
and its work with the focus items only
i'am waiting for other solutions.
 please help me because am now making an audio player for the blinds users, for that i need to this option.
with my greetings

Edited by nacerbaaziz

Share this post


Link to post
Share on other sites

careca, If you had tested your own code you would have seen that it does not work for buttons 1 and 2. You do not save ControlIds for the corresponding context menu items and are therefore unable to detect when the menu items are clicked.

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

  • Similar Content

    • By _leo_
      Hey guys
      I'm new to autoit, so this could be a simple question. I'm trying to read the value from the currently selected cell in Excel. I read on the forum and tired to find videos, but I couldn't quite get to it. 
      This is what I have got so far:
       
      Local $oExcel_1 = _Excel_Open()
      Local $var = "C:\Users\Acer\xy"
      Local $oWorkbook = _Excel_BookOpen($oExcel_1,$var)
       
      Local $_read1 = _Excel_RangeRead($oWorkbook, Default.Application.ActiveCell.Address)
       
      Whatever I try, I either get an error or it only reads "0".
       
      Thank you very much for any helpful thoughts!
    • By nacerbaaziz
      hello sirs, please i created a tool witch get the focused control in a window and play a audio file linked with this controls
      e.g buttons, checkBoxes, radios, comboboxes, and others
      i know that their is a function that give us the control focus but it return the classNN
      i want to get the class name to use it with a switch and
      because their are more than class e.g button tbutton timagebutton tnewButton...
      please can any one help me to get the class name not the classnn
      thanks in advance
    • By 2Toes
      Hey there,
      I have a program that I'm working on, and I have a button that's supposed to stop a running function, when it's pressed.
      However, I cannot get that to work.
      I put together a sample script that is set up in the same way:
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= Opt("GUIOnEventMode", 1) Global $Form1 = GUICreate("Form1", 290, 106, 192, 124) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") Global $btnStart = GUICtrlCreateButton("Start", 24, 24, 99, 49) GUICtrlSetOnEvent($btnStart, "_Start") Global $btnStop = GUICtrlCreateButton("Stop", 152, 24, 99, 49) GUICtrlSetOnEvent($btnStop, "_Stop") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 ;~ $nMsg = GUIGetMsg() ;~ Switch $nMsg ;~ Case $GUI_EVENT_CLOSE ;~ Exit ;~ EndSwitch WEnd Func _Start() Global $bStartFlag = True $num = 1 While $bStartFlag ConsoleWrite($num & @CRLF) Sleep(1000) $num += 1 WEnd ConsoleWrite("Exited loop.." & @CRLF) EndFunc Func _Stop() Global $bStartFlag = False EndFunc Func _Exit() Exit EndFunc  
      With the code above, while the _Start() func is running, the Stop button doesn't do anything.
      I even threw a MsgBox into the _Stop() func, to see if the script was at least accessing the _Stop() func. But that showed that the _Stop() func is not being accessed at all while the _Start() func is running.
      I'm sure this is a simple solution that I'm just over looking. But I can't figure out what that solution is lol.
      Any help here would be greatly appreciated!
      Thank you in advance!  
    • By jantograaf
      Hi all,
      I'm trying to write a script that connects with a VBA/COM API to get the status of a connected phone. I've been looking up and down this forum for tips or other user's experiences, but I can't seem to find anything (even remotely) similar. It shouldn't be so hard to do, however.
      Software I'm trying to connect to
      I'm trying to integrate CallCenter by using their API, which is documented over here : JustRemotePhone API Reference
      Things I've tried
      I've tried using ObjCreate but I don't get any result, it always returns the same (negative) error.
      #Version 1 tried ObjCreate("JustRemotePhone.RemotePhoneService") #Version 2 tried ObjCreate("JustRemotePhoneCOM.RemotePhoneService") #Version 3 tried ObjCreate("JustRemotePhoneCOM.RemotePhoneService.Application") None of the three versions I tried seem to deliver any result other than a negative error value which basically says that the given class is not valid.
      I am starting to get the hang of AutoIt by now, but unmanaged programming languages and object-oriented stuff is still quite a grey zone for me. If anyone could help me 'talk' to this application, I'd be immensely grateful!
      Thanks in advance and kind regards from Belgium!
       
      Jan
    • By nooneclose
      Hello everyone, I am wondering if and how it is possible to connect my AutoIt script to a different email in my outlook. I have two different accounts when I open outlook. The first which my script always connects to is my own email while the second is a group email account. How or can I make the script connect to the second one and access its inbox instead of mine? This is all work related so no funny business here. 
      Global $oOutlook = _OL_Open() ; Store all the Unread emails into an array Global $aItems = _OL_ItemFind($oOutlook, "*\Outlook-UDF-Test", $olMail, _ "[UnRead]=True", "Subject", "Maintenance Request from Eagle's Nest", "EntryID,Subject", "", 1) ; Display the array of unRead emails If IsArray($aItems) Then ;_ArrayDisplay($aItems, "OutlookEX UDF: _OL_ItemFind - Unread mails") Else MsgBox(48, "OutlookEX UDF: _OL_ItemFind Example Script", _ "Could not find an unread mail. @error = " & @error & ", @extended: " & @extended) EndIf ; Get the number of unread emails Global $numberOfUnRead = UBound($aItems, $UBOUND_ROWS) - 1 ;MsgBox("", "Number of Unread emails", $numberOfUnRead) ConsoleWrite("Number of unread emails: " & $numberOfUnRead & @CRLF) I might be missing some code in the post but my code works It's just so long I don't want to post all 2300+ lines. 
      Thank you for the help I greatly appreciate this community. 
×
×
  • Create New...