caleb41610 Posted October 6, 2012 Share Posted October 6, 2012 (edited) Here's a code snippet. expandcollapse popup; #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <GuiImageList.au3> #include <WindowsConstants.au3> #include <GDIPlus.au3> #include <WinAPI.au3> #include <Date.au3> #include <Array.au3> #include <Memory.au3> #include <File.au3> #include <GuiMenu.au3> Global $ini = @ScriptDir & "\" & "Settings.ini" Global $program_title = IniRead( $ini, "GUI", "title", "" ) Global $main_gui_width = 1365 Global $main_gui_height = 400 Global $server_array_size = 20 Global $background_color = 0x000000 Global $listen = -1 Global $connectedsocket = -1 Global $ws2_32 = DllOpen( "ws2_32.dll" ) Global $ntdll = DllOpen( "ntdll.dll" ) Global $cleanuptimer = TimerInit( ) Global $total_connections Global $h_server_menu Global $h_update_send_button, $h_update_url_button, $h_restart_button, $h_close_button, $h_remove_button Global $server[1][$server_array_size] $server[0][0] = 0 ;main gui Global $h_main_gui = GUICreate( $program_title, $main_gui_width, $main_gui_height, -1, -1, -1, -1 ) Global $h_list_view = GUICtrlCreateListView( "ID|Socket|IP Address", 250, 2, $main_gui_width - 250, $main_gui_height - 2 ) $testrow = GUICtrlCreateListViewItem( "1|512|127.0.0.1", $h_list_view ) GUISetBkColor( $background_color, $h_main_gui ) GUISetState( @SW_SHOW, $h_main_gui ) ;sub menus Global $h_sub_menu_1 = _GUICtrlMenu_CreateMenu( ) ;server ;server _GUICtrlMenu_InsertMenuItem( $h_sub_menu_1, 0, "Update (Send)", $h_update_send_button ) _GUICtrlMenu_InsertMenuItem( $h_sub_menu_1, 1, "Update (URL)", $h_update_url_button ) _GUICtrlMenu_InsertMenuItem( $h_sub_menu_1, 2, "Restart", $h_restart_button ) _GUICtrlMenu_InsertMenuItem( $h_sub_menu_1, 3, "Close", $h_close_button ) _GUICtrlMenu_InsertMenuItem( $h_sub_menu_1, 4, "Remove", $h_remove_button ) Global $h_control_menu = _GUICtrlMenu_CreatePopup( ) _GUICtrlMenu_InsertMenuItem( $h_control_menu, 0, "Server", $h_server_menu, $h_sub_menu_1 ) ;register messages GUIRegisterMsg( $WM_COMMAND, "WM_COMMAND" ) GUIRegisterMsg( $WM_NOTIFY, "WM_NOTIFY" ) Do Until GUIGetMsg( ) = $GUI_EVENT_CLOSE Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $iIDFrom, $iCode, $tNMHDR, $tInfo $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $iIDFrom Case $h_list_view Switch $iCode Case $NM_RCLICK $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam) If DllStructGetData($tInfo, "Item") > -1 Then _GUICtrlMenu_TrackPopupMenu( $h_control_menu, $h_main_gui) EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) Switch $iwParam Case $h_update_send_button MsgBox( 0, "1", "$h_update_send_button" ) Case $h_update_url_button MsgBox( 0, "2", "$h_update_url_button" ) Case $h_restart_button MsgBox( 0, "3", "$h_restart_button" ) Case $h_close_button MsgBox( 0, "4", "$h_close_button" ) Case $h_remove_button MsgBox( 0, "5", "$h_remove_button" ) EndSwitch EndFunc ;==>WM_COMMAND I'm trying to figure out why WM_COMMAND will always return $h_update_send_button, no matter which menu item is pushed. If I switch the order of the Cases, it will just return whichever one is first. That brings me to believe that maybe all are true, so it returns the first one and returns. Any ideas how I can return the menu item properly? I'm still quite new to this stuff and I appreciate all the support I have been getting. Edited October 7, 2012 by caleb41610 Multi-Connection TCP Server Link to comment Share on other sites More sharing options...
Danyfirex Posted October 6, 2012 Share Posted October 6, 2012 (edited) you need to enumerate the menucontext constants. expandcollapse popup; #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <GuiImageList.au3> #include <WindowsConstants.au3> #include <GDIPlus.au3> #include <WinAPI.au3> #include <Date.au3> #include <Array.au3> #include <Memory.au3> #include <File.au3> #include <GuiMenu.au3> Global $ini = @ScriptDir & "" & "Settings.ini" Global $program_title = IniRead( $ini, "GUI", "title", "" ) Global $main_gui_width = 1365 Global $main_gui_height = 400 Global $server_array_size = 20 Global $background_color = 0x000000 Global $listen = -1 Global $connectedsocket = -1 Global $ws2_32 = DllOpen( "ws2_32.dll" ) Global $ntdll = DllOpen( "ntdll.dll" ) Global $cleanuptimer = TimerInit( ) Global $total_connections Global $h_server_menu ;here Enum Global Enum $h_update_send_button=1000, $h_update_url_button, $h_restart_button, $h_close_button, $h_remove_button Global $server[1][$server_array_size] $server[0][0] = 0 ;main gui Global $h_main_gui = GUICreate( $program_title, $main_gui_width, $main_gui_height, -1, -1, -1, -1 ) Global $h_list_view = GUICtrlCreateListView( "ID|Socket|IP Address", 250, 2, $main_gui_width - 250, $main_gui_height - 2 ) $testrow = GUICtrlCreateListViewItem( "1|512|127.0.0.1", $h_list_view ) GUISetBkColor( $background_color, $h_main_gui ) GUISetState( @SW_SHOW, $h_main_gui ) ;sub menus Global $h_sub_menu_1 = _GUICtrlMenu_CreateMenu( ) ;server ;server _GUICtrlMenu_InsertMenuItem( $h_sub_menu_1, 0, "Update (Send)", $h_update_send_button ) _GUICtrlMenu_InsertMenuItem( $h_sub_menu_1, 1, "Update (URL)", $h_update_url_button ) _GUICtrlMenu_InsertMenuItem( $h_sub_menu_1, 2, "Restart", $h_restart_button ) _GUICtrlMenu_InsertMenuItem( $h_sub_menu_1, 3, "Close", $h_close_button ) _GUICtrlMenu_InsertMenuItem( $h_sub_menu_1, 4, "Remove", $h_remove_button ) Global $h_control_menu = _GUICtrlMenu_CreatePopup( ) _GUICtrlMenu_InsertMenuItem( $h_control_menu, 0, "Server", $h_server_menu, $h_sub_menu_1 ) ;register messages GUIRegisterMsg( $WM_COMMAND, "WM_COMMAND" ) GUIRegisterMsg( $WM_NOTIFY, "WM_NOTIFY" ) Do Until GUIGetMsg( ) = $GUI_EVENT_CLOSE Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $iIDFrom, $iCode, $tNMHDR, $tInfo $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $iIDFrom Case $h_list_view Switch $iCode Case $NM_RCLICK $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam) If DllStructGetData($tInfo, "Item") > -1 Then _GUICtrlMenu_TrackPopupMenu( $h_control_menu, $h_main_gui) EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) Switch $iwParam Case $h_update_send_button MsgBox( 0, "1", "$h_update_send_button" ) Case $h_update_url_button MsgBox( 0, "2", "$h_update_url_button" ) Case $h_restart_button MsgBox( 0, "3", "$h_restart_button" ) Case $h_close_button MsgBox( 0, "4", "$h_close_button" ) Case $h_remove_button MsgBox( 0, "5", "$h_remove_button" ) EndSwitch EndFunc ;==>WM_COMMAND Regards Edited October 6, 2012 by Danyfirex Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
caleb41610 Posted October 7, 2012 Author Share Posted October 7, 2012 Oh wow. Now I feel like a moron. Thanks! :-) Multi-Connection TCP Server Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now