Jump to content

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


Recommended Posts

Let's try it another way :

$iNb_Controls = 5

Global $id_Label[$iNb_Controls], $id_Context[$iNb_Controls], _
    $id_Open[$iNb_Controls], $id_Save[$iNb_Controls], $id_Cut[$iNb_Controls]

$hGUI = GUICreate("Menu", 400, 300)
$id_Label[0] = GUICtrlCreateLabel("1 - Right click to get options in menu", 100, 30, 180)
$id_Label[1] = GUICtrlCreateLabel("2 - Right click to get the same options", 100, 80, 180)
$id_Label[2] = GUICtrlCreateLabel("3 - Right click to get the same options", 100, 130, 180)
$id_Label[3] = GUICtrlCreateLabel("4 - Right click to get the same options", 100, 180, 180)
$id_Label[4] = GUICtrlCreateLabel("5 - Right click to get the same options", 100, 230, 180)

For $i = 0 To $iNb_Controls - 1
    $id_Context[$i] = GUICtrlCreateContextMenu($id_Label[$i])
Next
For $i = 0 To $iNb_Controls - 1
    $id_Open[$i] = GUICtrlCreateMenuItem("&Open", $id_Context[$i])
Next
For $i = 0 To $iNb_Controls - 1
    $id_Save[$i] = GUICtrlCreateMenuItem("Save the &file....", $id_Context[$i])
Next
For $i = 0 To $iNb_Controls - 1
    $id_Cut[$i] = GUICtrlCreateMenuItem("Move the &file....", $id_Context[$i])
Next

GUISetState()

While 1
    Switch GUIGetMSG()
        Case -3
            Exit

        Case $id_Open[0] To $id_Open[$iNb_Controls - 1]
            OpenFunc()

        Case $id_Save[0] To $id_Save[$iNb_Controls - 1]
            SaveFunc()

        Case $id_Cut[0] To $id_Cut[$iNb_Controls - 1]
            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

There are 4 separate For... Next loops to allow the Id's to be "grouped" by category, in one interval.
This makes it easier to check during the  Case $id_Open[0] To $id_Open[$iNb_Controls - 1] etc...
I don't know if it's possible to do same with only 1 For... Next loop

Edited by pixelsearch
Link to post
Share on other sites

dear this code shows the pop-up menu but when we choos any options always go to open func

$iNb_Controls = 5
    Global $id_Label[$iNb_Controls], $id_Context[$iNb_Controls], _
$id_Open[$iNb_Controls], $id_Save[$iNb_Controls], $id_Cut[$iNb_Controls]
    $hGUI = GUICreate("Menu", 400, 300)
$id_Label[0] = GUICtrlCreateLabel("1 - Right click to get options in menu", 100, 30, 180)
$id_Label[1] = GUICtrlCreateLabel("2 - Right click to get the same options", 100, 80, 180)
$id_Label[2] = GUICtrlCreateLabel("3 - Right click to get the same options", 100, 130, 180)
$id_Label[3] = GUICtrlCreateLabel("4 - Right click to get the same options", 100, 180, 180)
$id_Label[4] = GUICtrlCreateLabel("5 - Right click to get the same options", 100, 230, 180)
    For $i = 0 To $iNb_Controls - 1
$id_Context[$i] = GUICtrlCreateContextMenu($id_Label[$i])
$id_Open[$i] = GUICtrlCreateMenuItem("Open", $id_Context[$i])
$id_Save[$i] = GUICtrlCreateMenuItem("Save the file....", $id_Context[$i])
$id_Cut[$i] = GUICtrlCreateMenuItem("Move the file....", $id_Context[$i])
Next
    
GUISetState()
    While 1
Switch GUIGetMSG()
Case -3
Exit
Case $id_Open[0] To $id_Open[$iNb_Controls - 1]
OpenFunc()
Case $id_Save[0] To $id_Save[$iNb_Controls - 1]
SaveFunc()
Case $id_Cut[0] To $id_Cut[$iNb_Controls - 1]
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

Edited by nacerbaaziz
Link to post
Share on other sites

@pixelsearch  very nice job on your first post.  May I suggest 3 small changes.  Instead of creating a hard to find label, use GUICtrlCreateDummy ().  Instead of using the dll use _GUICtrlMenu_TrackPopupMenu ($hMenu, $hGUI) that way you don't need to capture the mouse position. In that same if block, capture the label that is under the menu like : $SelItem = $aInfo[4] so it can be used later.

Very Nice Job Indeed :)

Link to post
Share on other sites

@nacerbaaziz

Well... as it works fine on my PC, it seems to be a dead end.
Here, Open goes to Open, Save goes to Save, Move goes to Move.
No need to provide screen copies, that's the best I could do :)

@Nine
Hey buddy,  thanks for the appreciation :)
If you check the function _GUICtrlMenu_TrackPopupMenu() found in the include file <GuiMenu.au3>, you'll notice that there is also a call to the dll in the UDF :

Local $aResult = DllCall("user32.dll", "bool", "TrackPopupMenu", "handle", $hMenu, "uint", $iFlags, "int", $iX, "int", $iY, "int", 0, "hwnd", $hWnd, "ptr", 0)

In fact, there a 2 similar functions at MSDN and it's a bit puzzling : TrackPopupMenu and TrackPopupMenuEx . This is what I read at this adress :

https://stackoverflow.com/questions/1546026/whats-the-difference-between-the-trackpopupmenuex-and-trackpopupmenu-windows-ap

Question :
========
What's the difference between the TrackPopupMenuEx and TrackPopupMenu windows APIs?

I tested TrackPopupMenuEx and TrackPopupMenu APIs and they do the same thing: displaying a menu at the cursor's position. The source codes are the same, you just have to add or erase the "Ex" at the end of the names of these APIs. Why two APIs for the same action?

Note: TrackPopupMenu crashes my app in runtime when used on an image control, while TrackPopupMenuEx works ok. TrackPopUpMenu seems to have no sense.

Answer 1 :
========
They are pretty similar functions but the big difference is that TrackPopupMenuEx allows you to specify a rectangle that the popup menu won't appear over (to have one that doesn't obscure what you need to see). Thats about it as far as i can see.

Answer 2 :
========
According to the documentation, there are some subtle differences:
TrackPopupMenu has a nReserved parameter
TrackPopupMenuEx takes a LPTPMPARAMS for the last parameter, but TrackPopupMenu takes a CONST RECT* (which is ignored)

So, they have a different number and type of parameters with different meanings - which would explain why your app is crashing when you change the call.

So I don't know why the "TrackPopupMenu" call found in _GUICtrlMenu_TrackPopupMenu() ends with "ptr", 0) when it seems that this last parameter could be related to TrackPopupMenuEx (?)

This is what MSDN says about the last parameter of the 2 functions :

TrackPopupMenu :
prcRect
Type: const RECT*
Ignored.
TrackPopupMenuEx :
lptpm
Type: LPTPMPARAMS
A pointer to a TPMPARAMS structure that specifies an area of the screen the menu should not overlap. This parameter can be NULL.

Concerning the GUICtrlCreateDummy(), yes I knew it could work, but I always find it funny to create a control which size is 1 pixel, very funny to find it, like an Easter egg or a kind of pixel...search :)

Nine, if you could be kind enough to run my 2nd script on your computer, does it work at your place ? It works for me but not at OP's. Thanks.

Edited by pixelsearch
Link to post
Share on other sites

This is what i wanted to post in the first place.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
Opt("GUIOnEventMode", 1)
Opt("MustDeclareVars", 0)
Opt("GUIEventOptions", 1)

Example()

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

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)
GUICtrlSetOnEvent(-1, "text")
Local $idMenuInfo = GUICtrlCreateMenuItem("Info", $idContextmenu)
GUICtrlSetOnEvent(-1, "info")
Next
EndFunc

While 1
Sleep(100)
WEnd

Func text()
    MsgBox(64 + 262144, '', 'text')
EndFunc

Func info()
    MsgBox(64 + 262144, '', 'info')
EndFunc

Func button1()
    MsgBox(64 + 262144, '', '')
EndFunc

Func Quit()
    Exit
EndFunc   ;==>Quit

 

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

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

    No registered users viewing this page.

  • Similar Content

    • By Zaoka
      HI,
      for couple of years I'm using  Jos script for sending reports, email with excel attachment. But from last week i'm getting this error when sending excel or word attachment
      message has lines too long for transport jpeg, pdf works with no problems, any sugestion ?
    • By diepfeile
      I'm using the following:
      Autoit 3.3.14.5
      newly installed Beta 3.3.15.5
      SQlite version 3380000 aka 3.38.0
      I put sqlite3.dll and sqlite3_x64.dll in C:\Windows\System32 since many scripts depend on them.


      I extended the output of _SQLite_Startup()
      with:
      ConsoleWrite("@AutoItX64 " & @AutoItX64 & @CRLF) ConsoleWrite("$sDll_Filename " & $sDll_Filename & @CRLF) ConsoleWrite("_SQLite_LibVersion=" & _SQLite_LibVersion() & @CRLF)

      Also using the script from https://www.autoitscript.com/autoit3/docs/libfunctions/_SQLite_Startup.htm for testing.

       
      >Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3.exe "R:\Download\aasdf.au3" @AutoItX64 0 $sDll_Filename sqlite3.dll _SQLite_LibVersion=0 >Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3_x64.exe "R:\Download\aasdf.au3" @AutoItX64 1 $sDll_Filename sqlite3_x64.dll _SQLite_LibVersion=3.38.0 >Running:(3.3.15.5):C:\Program Files (x86)\AutoIt3\Beta\autoit3.exe "R:\Download\aasdf.au3" @AutoItX64 0 $sDll_Filename sqlite3.dll _SQLite_LibVersion=0 >Running:(3.3.15.5):C:\Program Files (x86)\AutoIt3\Beta\autoit3_x64.exe "R:\Download\aasdf.au3" @AutoItX64 1 $sDll_Filename sqlite3_x64.dll _SQLite_LibVersion=3.38.0


      Why doesn't it work in 32bit, despite me having the 32bit sqlite.dll? Autoit urges running scripts in 32bit mode and Scite starts scripts just in 32bit mode without the flag?
      With #AutoIt3Wrapper_UseX64=Y it just works, both normal Autoit and beta!
      sqlite3.dll sqlite3_x64.dll
    • By Iraj
      Hello Team, Greetings!
      Is there any way to run any 3rd party application silently in background without the GUI getting in the front ?
      I was implementing angry-ip scanner with autoit & wanted the angry-ip application to run in background quietly as I am copying its output to other file on completion. is there any way to achieve my query?
      Below is code I tried: 
      $range = "192.168.0.1 192.168.0.255" ShellExecuteWait("C:\Windows\DDM\ipscan.exe","-f:range "&$iprange&" -q -o C:\temp\ScanResults.csv","","open",@SW_HIDE) Thanks!
    • By PeterVerbeek
      This topic give you access to an AutoIt functions library I maintain which is called PAL, Peter's AutoIt Library. The latest version 1.26 contains 214 functions divided into these topics:
      window, desktop and monitor GUI, mouse and color GUI controls including graphical buttons (jpg, png) logics and mathematics include constants string, xml string and file string dialogues and progress bars data lists: lists, stacks, shift registers and key maps (a.ka. dictionaries) miscellaneous: logging/debugging, process and system info Change log and files section  on the PAL website (SourceForge).
      A lot of these functions were created in the development of Peace, Peter's Equalizer APO Configuration Extension, which is a user interface for the system-wide audio driver called Equalizer APO.
    • By Hermes
      Hi, I am struggling in setting the value of a textarea based on the value of clipboard (that contains a long web page source codes). If I use _WD_SetElementValue, it freezes after some time, or appears to be pressing tab and goes out of focus. I can also use send keys but i need the script to run in the background.
      Here is the full script:
      #Include "Chrome.au3" #Include "wd_core.au3" #Include "wd_helper.au3" #Include "WinHttp.au3" #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <Array.au3> #include <AutoItConstants.au3> #include <WinAPIFiles.au3> #include <GDIPlus.au3> #include <Excel.au3> Local $sDesiredCapabilities, $sSession SetupChrome() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_LoadWait($sSession) _WD_Navigate($sSession, "http://demo.borland.com/testsite/stadyn_largepagewithimages.html") _WD_LoadWait($sSession) Global $sSource = _WD_GetSource($sSession) Local $Paste = ClipPut($sSource) Local $sData = ClipGet() Local $aArray = 0, _ $iOffset = 1 While 1 $aArray = StringRegExp($sData, '(?s)<p>.*</p>', $STR_REGEXPARRAYMATCH, $iOffset) If @error Then ExitLoop $iOffset = @extended For $i = 0 To UBound($aArray) - 1 Local $Paste = ClipPut($aArray[$i]) Local $sRegExData = ClipGet() ;MsgBox(0, "", "$sRegExData = " & $sRegExData) Next WEnd _WD_Navigate($sSession, "https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_textarea_placeholder") _WD_WaitElement($sSession, $_WD_LOCATOR_ByCSSSelector, "iframe#iframeResult") Local $sElement1 = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "iframe#iframeResult") _WD_FrameEnter($sSession, $sElement1) _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//html/body/textarea") $textarea = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//html/body/textarea") _WD_ElementAction($sSession, $textarea, 'click') ;WD SetElementValue(SsSession, Stextarea, $sRegExData) <-- I can do this but the focus goes out, or the browser freezes _WD_FrameLeave($sSession) sleep(2000) Send("^v") _WD_LoadWait($sSession) _WD_Shutdown() Func SetupChrome() _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["start-maximized","disable-infobars"]}}}}' EndFunc ;==>SetupChrome Can someone help me please, or re-direct me to the right path? TIA!
×
×
  • Create New...