Jump to content

contextmenu issue


Recommended Posts

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

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

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

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

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

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...