Jump to content

Context Menu


Go to solution Solved by BrewManNH,

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • Solution

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.

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

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

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

×
×
  • Create New...