Jump to content
Sign in to follow this  
UndefinedVar

Context Menu

Recommended Posts

UndefinedVar

Hello!

So I want a context menu in my bigger program, but I don't really know how to do it realtime so it won't cause program "lag".

What i want to do is to select item, and then pops out context menu and then if I select option it will do smt.

Please help!

Btw I started with this...

#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 314, 233, 192, 124)
$ListView1 = GUICtrlCreateListView("Test|_Test", 14, 26, 154, 188)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 50)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Local $ListViewArray[100]
Local $OptionsArray[100]


;~ Local $contextmenu = GUICtrlCreateContextMenu($ListView1_0)
;~  Local $newsubmenu = GUICtrlCreateMenu("FUN", $contextmenu)
;~          $opt1 = GUICtrlCreateMenuItem("op1", $newsubmenu)

For $i = 0 To 6
    If $ListViewArray[$i] == "" Then  $ListViewArray[$i] = GUICtrlCreateListViewItem( "test" & $i & "|" & "test" & $i * 2, $ListView1 )
Next


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    For $item In $ListViewArray
        If $item <> "" And GUICtrlRead( GUICtrlRead( $ListView1 ) ) == GUICtrlRead( $item ) Then
            $contextmenu    = GUICtrlCreateContextMenu($item)
            $submenu        = GUICtrlCreateMenu("FUNCS", $contextmenu)
            $option1        = GUICtrlCreateMenuItem("op1", $submenu)
        EndIf
    Next
    Sleep(10)
WEnd

Share this post


Link to post
Share on other sites
FireFox

Hi,

Have a look at the help file (F1 in SciTE), you will have what you're looking for ;)

Btw, for comparison it's only one equal, double equal is for string with case sensivity comparison.

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
UndefinedVar

You didn't understand me well, but thanks for response!

Maybe i just can't point out my idea...

I will try to fix it on my own, again thanks for advice.

Share this post


Link to post
Share on other sites
FireFox

Put this code :

$contextmenu    = GUICtrlCreateContextMenu($item)
$submenu        = GUICtrlCreateMenu("FUNCS", $contextmenu)
$option1        = GUICtrlCreateMenuItem("op1", $submenu)
Out of the While loop and replace $item by $ListViewArray[$i] if you put it in your for loop.

Br, FireFox.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
BrewManNH

This works.

#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GUIListView.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 314, 233, 192, 124)
$ListView1 = GUICtrlCreateListView("Test|_Test", 14, 26, 154, 188)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 50)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Local $ListViewArray[100]
Local $OptionsArray[100]



For $i = 0 To 6
    If $ListViewArray[$i] = "" Then $ListViewArray[$i] = GUICtrlCreateListViewItem("test" & $i & "|" & "test" & $i * 2, $ListView1)
Next
$contextmenu = GUICtrlCreateContextMenu($ListView1)
$submenu = GUICtrlCreateMenu("FUNCS", $contextmenu)
$option1 = GUICtrlCreateMenuItem("op1", $submenu)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $option1
            ConsoleWrite(_GUICtrlListView_GetItemTextString($ListView1, -1) & @CRLF)
    EndSwitch

    Sleep(10)
WEnd

Prints out the text of the selected row of the listview in the SciTE console.

  • Like 1

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
UndefinedVar

Big thanks, but I need each element to have the options and when i click at option in this element then it do something. Like in this pro paint xD.

Maybe this will eventually point out my plan.

http://www.mediafire.com/view/hcqef7vupveocfo/xd.png

//oh and There can be undefined numbers of items in the list.

Edited by UndefinedVar

Share this post


Link to post
Share on other sites
BrewManNH

You're not making what you want any clearer with that picture.

Perhaps if you explain exactly what is in the listview and what you're planning on doing with the information you get from the text of the items it will help a lot.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
UndefinedVar

Ok... Idk if that is good with this forum rules, but...

I am making Tool for my teacher, so he can find users in network. Next he will control students computers, so they won't play fu*cking games everyday.

This tool will search user in network, then Users list appear at ListView, right ? Then when he clicks on item in there, he will choose some options to stop some of student activity, but problem is because it's very complicated, many of arrays and loops, to make and I don't want it to lag because I want it to run stable.

So now you know what is the problem, and maybe I eventually pointed it out.

Share this post


Link to post
Share on other sites
BrewManNH

ConsoleWrite(_GUICtrlListView_GetItemTextString($ListView1, -1) & @CRLF) 

So, take this line out of the message loop and replace it with a function call that includes the text of the LV passed to it. 

Edited by BrewManNH
  • Like 1

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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  

  • Similar Content

    • RooperGee
      By RooperGee
      I had written a GUI with several buttons and I wanted one of the buttons to show its context menu regardless of the user right or left clicking the button.  The whole purpose of the button was to show the user a menu of options and a context menu fit the need just fine, but I needed it to display with either click option.  I came up with the code below to accomplish this but I feel like I might be missing some very obvious easier way to do this and I feel it's a little lame to be forcing a right click mouse action on the button as a result of the user doing a left click, but it works!
      Anyone have a suggestion of a better way to do this?  Otherwise, if this idea helps you, here you go.
      #include <GUIConstantsEx.au3> LeftClickContextTest() Func LeftClickContextTest() Local $hGUI = GUICreate("My GUI", 200, 100) Local $button = GUICtrlCreateButton("Show Context", 15, 40, 85, 25) Local $close = GUICtrlCreateButton("Close", 110, 40, 85, 25) Local $context = GUICtrlCreateContextMenu($button) GUICtrlCreateMenuItem("Test Context Item 1", $context) GUICtrlCreateMenuItem("Test Context Item 2", $context) GUICtrlCreateMenuItem("Test Context Item 3", $context) GUISetState(@SW_SHOW, $hGUI) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $close ExitLoop Case $button MouseClick("right", MouseGetPos(0), MouseGetPos(1), 1, 0) EndSwitch WEnd EndFunc  
    • Pagi
      By Pagi
       
      <a href="index.php=4143b27b41db0a40c499202865c3e24d" class="menuitem " target="\_self"> "Menu Item 1" </a>
      Can you tell me if it´s possible to click this menu button? If yes, how? Cause I have no idea, I think i should use _IETagNameGetCollection
    • nacerbaaziz
      By nacerbaaziz
      Hello
      I have an inquiry please
      when i use the control get focus
      it don't detect the menu item
      there are any Method to do that?
      i'll use that to make a custom screen reader in my program
      please help me to do that
      I am waiting for your answers
      greetings to you
      Thank you in advance
       
    • nacerbaaziz
      By nacerbaaziz

      Hello all
      I have a question please
      this  a question is about the context menu
      When i create a list box  Or combo box
      if i create a context menu for this list
      When i press the application key or the shortcut shift + f10
      the menu options is appear normally
      but When i create a List view
      if i create a context menu for this list
      When i press the application key or the shortcut shift + f10
      the menu options isn't appear
      But the right mouse button works normally
      I need a solution please because I deal with the screen readers users
      Unfortunately They can not use the mouse to navigate
      So I have to find a solution to activate keyboard shortcuts
      am waiting  for your help
×