ReDFlaG Posted May 25, 2009 Share Posted May 25, 2009 (edited) Hello all, Here's a code that do NOT work #include <GUIConstants.au3> $mainwindow=GUICreate ("Test",750,450) $ListViewContext= GUICtrlCreateContextMenu($mainwindow) $Diag= GUICtrlCreateMenuitem("DiagIt", $ListViewContext) GUISetState() ;======================================================= While 1 $msg = GUIGetMsg() Select Case $msg = $Diag MsgBox(0,"ooops","oooops") EndSelect WEnd Here's a code that work: #include <GUIConstants.au3> $mainwindow=GUICreate ("Test",750,450) $ListViewContext= GUICtrlCreateContextMenu() $Diag= GUICtrlCreateMenuitem("DiagIt", $ListViewContext) GUISetState() ;======================================================= While 1 $msg = GUIGetMsg() Select Case $msg = $Diag MsgBox(0,"ooops","oooops") EndSelect WEnd I don't understand why it loops on the msgbox on the first one. (it shouldn't) The second one works, but the menu is only available when right clicking on the windows'name. I'd like that the menu be available when clicking anywhere in the main windows. Can you help? Thanks. Edited May 25, 2009 by ReDFlaG Link to comment Share on other sites More sharing options...
KaFu Posted May 25, 2009 Share Posted May 25, 2009 (edited) GUICtrlCreateContextMenu() help says: "If you use no parameters or -1 in this function then the context menu that is created is associated with the entire GUI window rather than an individual control." #include <GUIConstants.au3> $mainwindow = GUICreate ("Test",750,450) $ListViewContext = GUICtrlCreateContextMenu(-1) $Diag = GUICtrlCreateMenuitem("DiagIt", $ListViewContext) GUISetState() ;======================================================= While 1 $msg = GUIGetMsg() Select Case $msg = $Diag MsgBox(0,"ooops","oooops") EndSelect WEndoÝ÷ Ù8^zºè®)íçâ®Ë^Å©©ì²ØZ·Mú& Á«'¢×+y«^u©Ý¶¬Ñ«¢+Ø¥¹±Õ±ÐíU% ½¹ÍѹÑ̹ÔÌÐì((ÀÌØíµ¥¹Ý¥¹½ÜõU% ÉÑ ÅÕ½ÐíQÍÐÅÕ½Ðì°ÜÔÀ°ÐÔÀ¤(ÀÌØí1¥ÍÑY¥Ý ½¹ÑáÐôU% Ñɱ ÉÑ ½¹ÑáÑ5¹Ô ÀÌØíµ¥¹Ý¥¹½Ü¤(ÀÌØí¥ôU% Ñɱ ÉÑ5¹Õ¥Ñ´ ÅÕ½Ðí¥%ÐÅÕ½Ðì°ÀÌØí1¥ÍÑY¥Ý ½¹ÑáФ()U%MÑMÑÑ ¤((ìôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôô)]¡¥±Ä(ÀÌØíµÍôU%Ñ5Í ¤(M±Ð( ÍÀÌØíµÍôÀÌØí¥(5Í ½à À°ÅÕ½Ðí½½½ÁÌÅÕ½Ðì°ÅÕ½Ðí½½½½ÁÌÅÕ½Ðì¤(%¹M±Ð(% ½¹Í½±]É¥Ñ ÀÌØí¥µÀìѵÀìÀÌØíµÍµÀìɱ¤)]¹ Edited May 25, 2009 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21)HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
martin Posted May 25, 2009 Share Posted May 25, 2009 (edited) Hello all, Here's a code that do NOT work #include <GUIConstants.au3> $mainwindow=GUICreate ("Test",750,450) $ListViewContext= GUICtrlCreateContextMenu($mainwindow) $Diag= GUICtrlCreateMenuitem("DiagIt", $ListViewContext) GUISetState() ;======================================================= While 1 $msg = GUIGetMsg() Select Case $msg = $Diag MsgBox(0,"ooops","oooops") EndSelect WEnd Here's a code that work: #include <GUIConstants.au3> $mainwindow=GUICreate ("Test",750,450) $ListViewContext= GUICtrlCreateContextMenu() $Diag= GUICtrlCreateMenuitem("DiagIt", $ListViewContext) GUISetState() ;======================================================= While 1 $msg = GUIGetMsg() Select Case $msg = $Diag MsgBox(0,"ooops","oooops") EndSelect WEnd I don't understand why it loops on the msgbox on the first one. (it shouldn't) The second one works, but the menu is only available when right clicking on the windows'name. I'd like that the menu be available when clicking anywhere in the main windows. Can you help? Thanks. I think that is difficult but maybe someone knows a clever solution, otherwise you could do this, but you would then have to cope with left clicking anywhere on the screen outside of your gui. #include <GUIConstants.au3> #include <misc.au3> #include <screencapture.au3> #include <windowsconstants.au3> _ScreenCapture_Capture("sham.jpg",0,0,@DesktopWidth,@DesktopHeight) $sham = GUICreate("sham",@DesktopWidth,@DesktopHeight,0,0,$WS_POPUP) $p1 = GUICtrlCreatePic("sham.jpg",0,0,@DesktopWidth,@DesktopHeight) GUICtrlSetState(-1,$GUI_DISABLE) $ListViewContext1= GUICtrlCreateContextMenu() $Diag1= GUICtrlCreateMenuitem("DiagIt", $ListViewContext1) GUISetState() $mainwindow=GUICreate ("Test",750,450) $ListViewContext= GUICtrlCreateContextMenu() $Diag= GUICtrlCreateMenuitem("DiagIt", $ListViewContext) GUISetState() winsetontop($mainwindow,"",1) ;======================================================= While 1 $msg = GUIGetMsg() Select Case $msg = -3 Exit Case $msg = $Diag or $msg = $Diag1 MsgBox(262144,"ooops","oooops") EndSelect WEnd EDIT: I thought the OP wanted to right click anywhere outside of his gui and get his context menu. I misunderstood. Edited May 25, 2009 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Authenticity Posted May 25, 2009 Share Posted May 25, 2009 (edited) expandcollapse popup#include <Constants.au3> #include <GUIMenu.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> Opt('GUIOnEventMode', 1) Global $hGUI Global $Edit, $hEdit Global $hEditProc, $hOldProc, $pEditProc Global $hContextMenu, $ContextMenu, $ContextMenuItem $hGUI = GUICreate('Title', 100, 200) GUISetOnEvent(-3, '_EXIT') $Edit = GUICtrlCreateEdit('', 0, 50, 100, 150, 0) $hEdit = GUICtrlGetHandle(-1) $hEditProc = DllCallbackRegister('_EditProc', 'int', 'int;uint;uint;uint') $pEditProc = DllCallbackGetPtr($hEditProc) $hOldProc = _WinAPI_GetWindowLong($hEdit, $GWL_WNDPROC) _WinAPI_SetWindowLong($hEdit, $GWL_WNDPROC, $pEditProc) $ContextMenu = GUICtrlCreateContextMenu() $hContextMenu = GUICtrlGetHandle(-1) $ContextMenuItem = GUICtrlCreateMenuItem('&Menu item', $ContextMenu) GUICtrlSetOnEvent(-1, '_ContextMenuItem') GUISetState() While 1 Sleep(20) WEnd Func _EXIT() GUIDelete() DllCallbackFree($hEditProc) Exit EndFunc Func _ContextMenuItem() MsgBox(0x40, 'Title', 'Text') EndFunc Func _EditProc($hwnd, $iMsg, $iwParam, $ilParam) If $iMsg = $WM_CONTEXTMENU Then _GUICtrlMenu_TrackPopupMenu($hContextMenu, $hGUI) Return 0 EndIf Return _WinAPI_CallWindowProc($hOldProc, $hwnd, $iMsg, $iwParam, $ilParam) EndFunc Edited May 25, 2009 by Authenticity Link to comment Share on other sites More sharing options...
ReDFlaG Posted May 25, 2009 Author Share Posted May 25, 2009 (edited) Thanks all of you. To answer back to kafu, i'd noticed that the problem was the $Diag with a 0 value. But i do not understand why, since it should got one (index number of the entrie). To be more clear i put 2 examples below: #include <GUIConstants.au3> GUICreate ("Test",750,450) $ListViewContext= GUICtrlCreateContextMenu() $Diag= GUICtrlCreateMenuitem("DiagIt", $ListViewContext) GUISetState() ;======================================================= While 1 $msg = GUIGetMsg() Select Case $msg = $Diag MsgBox(0,"ooops","oooops") EndSelect MsgBox(0,"test",$Diag) ConsoleWrite($Diag & @tab & $msg & @crlf) WEnd Value is 4. (perfect for me) #include <GUIConstants.au3> $mainwindow=GUICreate ("Test",750,450) $ListViewContext= GUICtrlCreateContextMenu($mainwindow) $Diag= GUICtrlCreateMenuitem("DiagIt", $ListViewContext) GUISetState() ;======================================================= While 1 $msg = GUIGetMsg() Select Case $msg = $Diag MsgBox(0,"ooops","oooops") EndSelect MsgBox(0,"test",$Diag) ConsoleWrite($Diag & @tab & $msg & @crlf) WEnd Value is 0. Why did it not get an "index" (item?) number. I must use a var to name the windows because i create different gui at the same time so i must handle the $GUI_EVENT_CLOSE differently: Case $msg [0] = $GUI_EVENT_CLOSE If $msg [1] = $mainwindow Then Exit Else GUIDelete() EndIf Edited May 25, 2009 by ReDFlaG Link to comment Share on other sites More sharing options...
KaFu Posted May 25, 2009 Share Posted May 25, 2009 GUICtrlCreateMenu() => "Failure: Returns 0" The control failed to be created, because you refer to $ListViewContext= GUICtrlCreateContextMenu($mainwindow) as parent, where $mainwindow is an illegal parameter (either blank, -1 or ControlID, NOT WinHwnd!), thus *checkcheckcheck* $ListViewContext is also 0 (failed!). #include <GUIConstants.au3> $mainwindow=GUICreate ("Test",750,450) $ListViewContext= GUICtrlCreateContextMenu($mainwindow) $Diag= GUICtrlCreateMenuitem("DiagIt", $ListViewContext) GUISetState() ;======================================================= While 1 $msg = GUIGetMsg() Select Case $msg = $Diag MsgBox(0,"ooops","oooops") EndSelect MsgBox(0,"test",$Diag & @crlf & $ListViewContext & @crlf & $msg) WEnd OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21)HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
ReDFlaG Posted May 26, 2009 Author Share Posted May 26, 2009 This code was working with an older version of autoit, Thanks for your help i'll try to solve that. Link to comment Share on other sites More sharing options...
ReDFlaG Posted May 27, 2009 Author Share Posted May 27, 2009 @Authenticity your code work ! thanks 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