Jump to content
Sign in to follow this  
nacerbaaziz

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

Share this post


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

Share this post


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 :)

Share this post


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

Share this post


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

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By nooneclose
      Why can I not click on either of my input fields?
      #Region ### START Koda GUI section ### Form= Global $Form1 = GUICreate("Form1", 730, 437, 192, 124) ;GUISetFont(14, 800, 0, "MS Sans Serif") GUISetBkColor(0xC0DCC0) Global $Label1 = GUICtrlCreateLabel("Enter your Password. UserName is auto filled", 62, 40, 604, 41, $SS_CENTER) GUICtrlSetFont(-1, 26, 800, 0, "MS Sans Serif") Global $Label2 = GUICtrlCreateLabel("User Name:", 120, 130, 604, 31, $SS_LEFT) GUICtrlSetFont(-1, 20, 800, 0, "MS Sans Serif") Global $Label3 = GUICtrlCreateLabel("Password:", 135, 210, 604, 31, $SS_LEFT) GUICtrlSetFont(-1, 20, 800, 0, "MS Sans Serif") Global $Input1 = GUICtrlCreateInput(@UserName, 274, 130, 185, 32) GUICtrlSetFont(-1, 14, 800, 1, "MS Sans Serif") Global $Input2 = GUICtrlCreateInput("Password", 274, 210, 185, 32, $ES_PASSWORD) GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif") Global $OK = GUICtrlCreateButton("OK", 274, 270, 185, 57) GUICtrlSetFont(-1, 20, 800, 0, "MS Sans Serif") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $OK Global $UserName = GUICtrlRead($Input1) Global $PassWord = GUICtrlRead($Input2) ExitLoop EndSwitch WEnd ; Delete the GUI window GUIDelete()  
    • By cruisepandey
      Hi, 
      I have a string like this : 
      Global $Msga = "urrent directory is /send.  (Submission of file with log number 29381077284 is confirmed)";
      I want to extract the number 29381077284  from the string. I did StringSplit to split based on "(" and then use space to reach there, But it's not a good choice. 
      Can anyone help me with regular expression to find the number from String using AutoIT. TIA
    • By nooneclose
      I want wanting to run multiple tests on my company website. Sadly the process I want to automate requires opening a File Explorer to add an attachment. Is there a way in to automate a Chrome opened File Explorer?
      (I am using webdriver to automate the other 99% of the process just fine. But when I have it click on attach file and chrome opens a file explorer I do not know how to handle it.) 
      Any help would be greatly appreciated. 
    • By cruisepandey
      Hi There ! 
      I have a script here : 
       
      ;Launch CMD
      Run("C:\Windows\System32\cmd.exe")
      sleep(2000)
      $cmdHandle = WinActivate("C:\Windows\System32\cmd.exe")
      Sleep(2000)
      ;Sending document
      ControlSend($cmdHandle, "", "", "ftp" & @CRLF)
      ControlSend($cmdHandle, "", "", "open" & @CRLF)
      Sleep(2000)
      ControlSend($cmdHandle, "", "", "first command" & @CRLF)
      Sleep(2000)
      ControlSend($cmdHandle, "", "", "second-coomand" & @CRLF)
       
      first-command and second-command I can't provide cause it's internal. I have complied this .au3 file into an exe and it does the work. But I need to invoke this with Java. Java code I have tried is : 
       
          ProcessBuilder pb = new ProcessBuilder("C:\\Users\\username\\eclipse-workspace\\Examples\\src\\com\\own\\examples\\etc.exe");
          pb.start();
          Thread.sleep(5000);
       
      Through java it just launches the cmd and nothing happens after that. Please help !!
    • By FUD
      hello 
      please i need help 
      i need to open link in default browser only one windows without duplicate if i try to open the same link 
       
      thanks 
×
×
  • Create New...