Sign in to follow this  
Followers 0
goldenix

[Solved]_How to create Submenu ?

3 posts in this topic

#1 ·  Posted (edited)

Question 1:

If I remove = 1000 = 2000 = 3000 It does not work anymore Why do I need those 1000 2000 3000 ?

Local $item1 = 1000
    Local $item2 = 2000
    Local $item3 = 3000

Question 2, How to make the Submenu item, I saw it once in the help file, but since the help file is becoming more & more like the sh*tty microsoft Vb helpfile ( With no relations ) where you can search for days & still find nothing, I cant find it anymore. I know it was Only 1 line of code & it contained numbers like 0x...something. Help me please. I even know what line I need to change:

_GUICtrlMenu_InsertMenuItem($hMenu, 0, "Visible")oÝ÷ Ù³à¨uïÛjëh×6 Local $item1 = 1000
    Local $item2 = 2000
    Local $item3 = 3000

    Local $hMenu

    $hMenu = _GUICtrlMenu_CreatePopup()
    _GUICtrlMenu_AddMenuItem($hMenu, "$item1", $item1)
    _GUICtrlMenu_AddMenuItem($hMenu, "$item2", $item2)
    _GUICtrlMenu_AddMenuItem($hMenu, "$item3", $item3)
    
;~  Create subitem menu
    $hItem1 = _GUICtrlMenu_CreateMenu()
    _GUICtrlMenu_InsertMenuItem($hMenu, 0, "Visible")   

    Switch _GUICtrlMenu_TrackPopupMenu($hMenu, $hListView, -1, -1, 1, 1, 2)
        Case $item1
            ConsoleWrite($INDEX & ' $item1 ' & $SELECTED_ITEM & @CRLF)          
        Case $item2         
            ConsoleWrite($INDEX & ' $item2 ' & $SELECTED_ITEM & @CRLF)
        Case $item3     
            ConsoleWrite($INDEX & ' $item3 ' & $SELECTED_ITEM & @CRLF)      
    EndSwitch
 
    _GUICtrlMenu_DestroyMenu($hMenu)oÝ÷ Ù±n[^
^N°k(­Â䲸 ÙèÃöÚºÚ"µÍÚ[ÛYH ÑÕRPÛÛÝ[Ñ^]LÉÝÂÚ[ÛYH ÑÝZSY[K]LÉÝÂÚ[ÛYH    ÑÝZSÝY]Ë]LÉÝÂÚ[ÛYH ÕÚ[ÝÜÐÛÛÝ[Ë]LÉÝÂÛØ[   ÌÍÚÝY]È    ÌÍÚR[^   ÌÍÑÜLB  ÌÍÑÜLHHÕRPÜX]J    ][ÝÊQÜX]Y
HÝY]ÈÜX]I][ÝË
Ì
BBIÌÍÚÝY]ÈHÑÕRPÝÝY]×ÐÜX]H
    ÌÍÑÜLK  ][ÝÉ][ÝËÌMÌÌ
HÈQKÕÔKÒQKÒRQÒBHÑÕRPÝÝY]×ÔÙ]^[YÝY]ÔÝ[H
    ÌÍÚÝY]Ë]Ô ÌÍÓ×ÐUUÐTSÑH ÌÍÓ×ÑVÐÒPÒÐÖTË   ÌÍÓ×ÑVÑSÕÔÑSPÕ    ÌÍÓ×ÑVÑÕPPQTJBBÈYÛÛ[[ÂÑÕRPÝÝY]×Ò[ÙÛÛ[[  ÌÍÚÝY]Ë    ][ÝÐÛÛ[[I][ÝËL
BÈY][ÂÑÕRPÝÝY]×ÐY][J    ÌÍÚÝY]Ë    ][ÝÔÝÈNÛÛI][ÝË
BÑÕRPÝÝY]×ÐY][J   ÌÍÚÝY]Ë    ][ÝÔÝÈÛÛI][ÝËJBÑÕRPÝÝY]×ÐY][J ÌÍÚÝY]Ë    ][ÝÔÝÈÎÛÛI][ÝËBBQÕRTÙ]Ý]JÕ×ÔÒÕÊBQÕRTYÚÝÙÊ    ÌÍÕÓWÓÕQK ][ÝÕÓWÓÕQI][ÝÊBBÂ[[ÕRQÙ]ÙÊ
HH  ÌÍÑÕRWÑUSÐÓÔÑBÕRQ[]J
BßOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOBßÛÛ^Y[BßOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOB[ÈÐÛÛ^Y[J    ÌÍÒSV    ÌÍÔÑSPÕQÒUSJBBSØØ[  ÌÍÚ][LHHLSØØ[  ÌÍÚ][LHSØØ[    ÌÍÚ][LÈHÌSØØ[    ÌÍÚY[B   ÌÍÚY[HHÑÕRPÝY[WÐÜX]TÜ

BWÑÕRPÝY[WÐYY[R][J  ÌÍÚY[K   ][ÝÉÌÍÚ][LI][ÝË  ÌÍÚ][LJBÑÕRPÝY[WÐYY[R][J ÌÍÚY[K   ][ÝÉÌÍÚ][L][ÝË   ÌÍÚ][LBWÑÕRPÝY[WÐYY[R][J ÌÍÚY[K   ][ÝÉÌÍÚ][LÉ][ÝË ÌÍÚ][LÊBBßPÜX]HÝX][HY[B  ÌÍÚ][LHHÑÕRPÝY[WÐÜX]SY[J
BÑÕRPÝY[WÒ[ÙY[R][J ÌÍÚY[K   ][ÝÕÚXI][ÝÊBBÝÚ]ÚÑÕRPÝY[WÕXÚÔÜY[J    ÌÍÚY[K   ÌÍÚÝY]ËLKLKKKBBPØÙH  ÌÍÚ][LBBBPÛÛÛÛUÜ]J  ÌÍÒSV    [È ÌÎNÈ ÌÍÚ][LH  ÌÎNÈ [È ÌÍÔÑSPÕQÒUSH  [ÈÔBBBBBPØÙH    ÌÍÚ][LBBBPÛÛÛÛUÜ]J  ÌÍÒSV    [È ÌÎNÈ ÌÍÚ][L   ÌÎNÈ [È ÌÍÔÑSPÕQÒUSH  [ÈÔBBPØÙH   ÌÍÚ][LÈBBBPÛÛÛÛUÜ]J    ÌÍÒSV    [È ÌÎNÈ ÌÍÚ][LÈ ÌÎNÈ [È ÌÍÔÑSPÕQÒUSH  [ÈÔBBB[ÝÚ]ÚÑÕRPÝY[WÑÝÞSY[J   ÌÍÚY[JB[[ÎÏOIÝ×ÐÛÛ^Y[B[ÈÓWÓÕQJ    ÌÍÚÛ    ÌÍÚSÙË ÌÍÚ]Ô[K ÌÍÚ[[JBØØ[ ÌÍÚÛÛK ÌÍÚPÛÙK    ÌÍÝR ÌÍÚÛÝY]Ë  ÌÍÝ[ÂßØØ[    ÌÍÝY ÌÍÚÛÝY]ÈH ÌÍÚÝY]ÂYÝÒÛ
    ÌÍÚÝY]ÊH[  ÌÍÚÛÝY]ÈHÕRPÝÙ][J  ÌÍÚÝY]ÊB   ÌÍÝRHÝXÝÜX]J  ÌÍÝYÓR  ÌÍÚ[[JB  ÌÍÚÛÛHHÛ
ÝXÝÙ]]J  ÌÍÝR ][ÝÚÛÛI][ÝÊJB ÌÍÚPÛÙHHÝXÝÙ]]J ÌÍÝR ][ÝÐÛÙI][ÝÊBÝÚ]Ú   ÌÍÚÛÛBØÙH    ÌÍÚÛÝY]ÂÝÚ]Ú   ÌÍÚPÛÙBØÙH   ÌÍÓWÔÓPÒÈÈÙ[HHÝ]Y]ÈÛÛÛÚ[HÙÛXÚÜÈ[][HÚ]HYÚ[ÝÙH]Û ÌÍÝ[ÈHÝXÝÜX]J    ÌÍÝYÓRUSPPÕUUK ÌÍÚ[[JBBBBBBBBBBBIÌÍÚR[^HÝXÝÙ]]J   ÌÍÝ[Ë   ][ÝÒ[^    ][ÝÊBBBBBBBBBBBBRY    ÌÍÚR[^   ÉÝÈLH[BBBBBBWÐÛÛ^Y[J  ÌÍÚR[^ÑÕRPÝÝY]×ÑÙ]][U^Ý[Ê   ÌÍÚÝY]Ë    ÌÍÚR[^
JBBBBBBQ[Y[ÝÚ]Ú[ÝÚ]Ú] ÌÍÑÕRWÔSQTÑÂ[[ÈÏOIÝÕÓWÓÕQ
Edited by goldenix

My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]

Share this post


Link to post
Share on other sites



I am not sure why you need this all, but here is an example with built-in functions (for Context Menu):

#include <GUIConstantsEx.au3>
#include <GuiMenu.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>

Global $hListView , $iLast_LV_Index, $Form1

$Form1 = GUICreate("(UDF Created) ListView Create", 400, 300)

$DummyMenu = GUICtrlCreateDummy()
$ContextMenu = GUICtrlCreateContextMenu($DummyMenu)

$SubMenu = GUICtrlCreateMenu("Submenu", $ContextMenu)
$SB_Item = GUICtrlCreateMenuItem("Item in submenu", $SubMenu)

GUICtrlCreateMenuItem("", $ContextMenu)

$Some_Item = GUICtrlCreateMenuItem("Some Item", $ContextMenu)
$Exit_Item = GUICtrlCreateMenuItem("Exit", $ContextMenu)

$hListView = _GUICtrlListView_Create ($Form1, "", 32, 16, 340, 260) ; LEFT],[TOP],WIDTH],[HEIGHT]
_GUICtrlListView_SetExtendedListViewStyle ($hListView, _
    BitOR($LVS_AUTOARRANGE ,$LVS_EX_CHECKBOXES,$LVS_EX_FULLROWSELECT,$LVS_EX_DOUBLEBUFFER)) 

; Add columns
_GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100)

; Add items
_GUICtrlListView_AddItem($hListView, "Row 1: Col 1", 0)
_GUICtrlListView_AddItem($hListView, "Row 2: Col 1", 1)
_GUICtrlListView_AddItem($hListView, "Row 3: Col 1", 2)

GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $SB_Item To $Exit_Item
            Local $sMenu_Item_Text = GUICtrlRead($nMsg, 1)
            Local $sLV_Item_Text = _GUICtrlListView_GetItemTextString($hListView, $iLast_LV_Index)
            
            MsgBox(64, 'Context Menu', _
                StringFormat('Menu Item Clicked: %s\nLV Item Index: %s\nLV Item Text: %s', _
                    $sMenu_Item_Text, $iLast_LV_Index, $sLV_Item_Text), 0, $Form1)
            
            If $nMsg = $Exit_Item Then Exit
    EndSwitch
WEnd

; Show a menu in a given GUI window which belongs to a given GUI ctrl
Func ShowMenu($hWnd, $nContextID, $nContextControlID, $iMouse=0)
    Local $hMenu = GUICtrlGetHandle($nContextID)
    Local $iCtrlPos = ControlGetPos($hWnd, "", $nContextControlID)
    
    Local $X = $iCtrlPos[0]
    Local $Y = $iCtrlPos[1] + $iCtrlPos[3]
    
    ClientToScreen($hWnd, $X, $Y)
    
    If $iMouse Then
        $X = MouseGetPos(0)
        $Y = MouseGetPos(1)
    EndIf
    
    DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $X, "int", $Y, "hwnd", $hWnd, "ptr", 0)
EndFunc

; Convert the client (GUI) coordinates to screen (desktop) coordinates
Func ClientToScreen($hWnd, ByRef $x, ByRef $y)
    Local $stPoint = DllStructCreate("int;int")
    
    DllStructSetData($stPoint, 1, $x)
    DllStructSetData($stPoint, 2, $y)

    DllCall("user32.dll", "int", "ClientToScreen", "hwnd", $hWnd, "ptr", DllStructGetPtr($stPoint))
    
    $x = DllStructGetData($stPoint, 1)
    $y = DllStructGetData($stPoint, 2)
    ; release Struct not really needed as it is a local 
    $stPoint = 0
EndFunc

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom,  $iCode, $tNMHDR, $hWndListView, $tInfo
    
    $hWndListView = $hListView
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_RCLICK ; Sent by a list-view control when the user clicks an item with the right mouse button
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                    $iIndex = DllStructGetData($tInfo, "Index")
                    
                    If $iIndex <> -1 Then
                        $iLast_LV_Index = $iIndex
                        ShowMenu($hWnd, $ContextMenu, $hListView, 1)
                    EndIf
            EndSwitch
    EndSwitch
    
    Return $GUI_RUNDEFMSG
EndFunc

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Posted Image You want to know why I need this? take a look at this pic, its almost ready, all it needs now is for me to build in Group management & menu.

thanx I think i got it to work: Hire is simplified version Guioneventmode 1

#include <GUIConstantsEx.au3>
#include <GuiMenu.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode <<<<<<<<<<<<<<<<<

Global $hListView , $iLast_LV_Index, $Form1

$Form1 = GUICreate("(UDF Created) ListView Create", 400, 300)

$DummyMenu = GUICtrlCreateDummy()
$ContextMenu = GUICtrlCreateContextMenu($DummyMenu)

$SubMenu = GUICtrlCreateMenu("Submenu", $ContextMenu)
$SB_Item = GUICtrlCreateMenuItem("Item in submenu", $SubMenu)

GUICtrlCreateMenuItem("", $ContextMenu)

$Some_Item = GUICtrlCreateMenuItem("Some Item", $ContextMenu)
$Exit_Item = GUICtrlCreateMenuItem("Exit", $ContextMenu)

$hListView = _GUICtrlListView_Create ($Form1, "", 32, 16, 340, 260) ; LEFT],[TOP],WIDTH],[HEIGHT]
_GUICtrlListView_SetExtendedListViewStyle ($hListView, _
    BitOR($LVS_AUTOARRANGE ,$LVS_EX_CHECKBOXES,$LVS_EX_FULLROWSELECT,$LVS_EX_DOUBLEBUFFER))

; Add columns
_GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100)

; Add items
_GUICtrlListView_AddItem($hListView, "Row 1: Col 1", 0)
_GUICtrlListView_AddItem($hListView, "Row 2: Col 1", 1)
_GUICtrlListView_AddItem($hListView, "Row 3: Col 1", 2)

GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")


GUICtrlSetOnEvent($Exit_Item, "_MeOntopFunc");<<<<<<<<<<<<<<<<<


    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()

Func _MeOntopFunc();<<<<<<<<<<<<<<<<<
Exit;<<<<<<<<<<<<<<<<<
EndFunc;<<<<<<<<<<<<<<<<<


; Show a menu in a given GUI window which belongs to a given GUI ctrl
Func _ShowMenu($hWnd, $nContextID, $nContextControlID, $iMouse=0)
    Local $hMenu = GUICtrlGetHandle($nContextID)
    Local $iCtrlPos = ControlGetPos($hWnd, "", $nContextControlID)
   
    Local $X = $iCtrlPos[0]
    Local $Y = $iCtrlPos[1] + $iCtrlPos[3]
   
    ClientToScreen($hWnd, $X, $Y)
   
    If $iMouse Then
        $X = MouseGetPos(0)
        $Y = MouseGetPos(1)
    EndIf
   
    DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $X, "int", $Y, "hwnd", $hWnd, "ptr", 0)
EndFunc

; Convert the client (GUI) coordinates to screen (desktop) coordinates
Func ClientToScreen($hWnd, ByRef $x, ByRef $y)
    Local $stPoint = DllStructCreate("int;int")
   
    DllStructSetData($stPoint, 1, $x)
    DllStructSetData($stPoint, 2, $y)

    DllCall("user32.dll", "int", "ClientToScreen", "hwnd", $hWnd, "ptr", DllStructGetPtr($stPoint))
   
    $x = DllStructGetData($stPoint, 1)
    $y = DllStructGetData($stPoint, 2)
    ; release Struct not really needed as it is a local
    $stPoint = 0
EndFunc

; Show a menu in a given GUI window which belongs to a given GUI ctrl
Func ShowMenu($hWnd, $nContextID, $nContextControlID, $iMouse=0)
    Local $hMenu = GUICtrlGetHandle($nContextID)
    Local $iCtrlPos = ControlGetPos($hWnd, "", $nContextControlID)
   
    Local $X = $iCtrlPos[0]
    Local $Y = $iCtrlPos[1] + $iCtrlPos[3]
   
    ClientToScreen($hWnd, $X, $Y)
   
    If $iMouse Then
        $X = MouseGetPos(0)
        $Y = MouseGetPos(1)
    EndIf
   
    DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $X, "int", $Y, "hwnd", $hWnd, "ptr", 0)
EndFunc

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom,  $iCode, $tNMHDR, $hWndListView, $tInfo
   
    $hWndListView = $hListView
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
   
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_RCLICK ; Sent by a list-view control when the user clicks an item with the right mouse button
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                    $iIndex = DllStructGetData($tInfo, "Index")
                   
                    If $iIndex <> -1 Then
                        $iLast_LV_Index = $iIndex
                        ShowMenu($hWnd, $ContextMenu, $hListView, 1)
                    EndIf
            EndSwitch
    EndSwitch
   
    Return $GUI_RUNDEFMSG
EndFunc
Edited by goldenix

My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]

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  
Followers 0