Jump to content

Popup context menu not broadcasting control with multiple widows


lbsl
 Share

Recommended Posts

Greetings fellows,

 

I have an issue that is bothering me for quite some time now (Since Autoit3 V3.3.8.0 and still not solved in 3.3.14.0) and i have not found any clue how to solve this particular problem regarding the control of popup-menus for specific controls. I have been searching using many keywords in the hope to find a similar posted issue either on the internet or here on this forum but did not yet stumbled upon it so i have no other option than to post the question (Sorry if there would exist an earlier topic).

Below is an example that demonstrates the issue very clearly if you follow the steps to reproduce:

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

$TestWindow1 = GUICreate("TestWindow1", 353, 277, 100, 80)
$ListView1 = GUICtrlCreateListView("", 8, 8, 338, 262)
$ListView1_0 = GUICtrlCreateListViewItem("TestItem1", $ListView1)
$ListView1_1 = GUICtrlCreateListViewItem("TestItem2", $ListView1)
$ListView1_2 = GUICtrlCreateListViewItem("TestItem3", $ListView1)
GUISetState(@SW_SHOW)

$TestWindow2 = GUICreate("TestWindow2", 353, 277, 100 + 400, 80)
$ListView2 = GUICtrlCreateListView("", 8, 8, 338, 262)
$ListView2_0 = GUICtrlCreateListViewItem("TestItem1", $ListView2)
$ListView2_1 = GUICtrlCreateListViewItem("TestItem2", $ListView2)
$ListView2_2 = GUICtrlCreateListViewItem("TestItem3", $ListView2)
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

Local $MenuContext, $MenuContext2
Local $ahLVMenu[3]
Local $ahLVMenu2[3]



For $i = 0 To 2
    $ahLVMenu[$i] = GUICtrlCreateDummy()
    $ahLVMenu2[$i] = GUICtrlCreateDummy()
Next



While 1
    Local $nMsg = GUIGetMsg(1)

    Switch $nMsg[0]
        Case $GUI_EVENT_CLOSE
            If $nMsg[1] == $TestWindow2 Then
                GUISetState(@SW_HIDE, $nMsg[1])
            Else
                Exit
            EndIf

        Case $ahLVMenu[0]
            ConsoleWrite("Dialog 1, Item 1" & @CRLF)

        Case $ahLVMenu[1]
            ConsoleWrite("Dialog 1, Item 2" & @CRLF)

        Case $ahLVMenu[2]
            ConsoleWrite("Dialog 1, Item 3" & @CRLF)

        Case $ahLVMenu2[0]
            ConsoleWrite("Dialog 2, Item 1" & @CRLF)

        Case $ahLVMenu2[1]
            ConsoleWrite("Dialog 2, Item 2" & @CRLF)

        Case $ahLVMenu2[2]
            ConsoleWrite("Dialog 2, Item 3" & @CRLF)

    EndSwitch
WEnd



Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    #forceref $hWnd, $Msg, $wParam
    Local $hWndFrom, $iIDFrom, $event, $tNMHDR, $hWndListView, $hWndListView2, $tInfo
    $hWndListView = $ListView1
    $hWndListView2 = $ListView2
    Local $tMsgFilter, $hMenu
    If Not IsHWnd($ListView1) Then $hWndListView = GUICtrlGetHandle($ListView1)
    If Not IsHWnd($ListView2) Then $hWndListView2 = GUICtrlGetHandle($ListView2)

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $event = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView2

            Switch $event
                Case $NM_RCLICK ; Sent by a list-view control when the user clicks an item with the right mouse button
                    _LV_PopUpMenu2() ; Show popup context menu in Pharmacist article list

            EndSwitch

        Case $hWndListView
            Switch $event
                Case $NM_RCLICK ; Sent by a list-view control when the user clicks an item with the right mouse button
                    _LV_PopUpMenu() ; Show popup context menu in Pharmacist article list

            EndSwitch

    EndSwitch
    $hWndFrom = 0
    $iIDFrom = 0
    $tNMHDR = 0
    $hWndListView = 0
    $hWndListView2 = 0
    $tInfo = 0
    $tMsgFilter = 0
    $hMenu = 0
    Return $GUI_RUNDEFMSG

EndFunc   ;==>WM_NOTIFY



Func _LV_PopUpMenu()

    $MenuContext = _GUICtrlMenu_CreatePopup(40)
    _GUICtrlMenu_InsertMenuItem($MenuContext, 0, "Dialog 1, item 1", $ahLVMenu[0])
    _GUICtrlMenu_InsertMenuItem($MenuContext, 1, "Dialog 1, item 2", $ahLVMenu[1])
    _GUICtrlMenu_InsertMenuItem($MenuContext, 2, "Dialog 1, item 3", $ahLVMenu[2])
    _GUICtrlMenu_TrackPopupMenu($MenuContext, $TestWindow1)
    _GUICtrlMenu_DestroyMenu($MenuContext)
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_LV_PopUpMenu



Func _LV_PopUpMenu2()

    $MenuContext2 = _GUICtrlMenu_CreatePopup(40)
    _GUICtrlMenu_InsertMenuItem($MenuContext2, 0, "Dialog 2, item 1", $ahLVMenu2[0])
    _GUICtrlMenu_InsertMenuItem($MenuContext2, 1, "Dialog 2, item 2", $ahLVMenu2[1])
    _GUICtrlMenu_InsertMenuItem($MenuContext2, 2, "Dialog 2, item 3", $ahLVMenu2[2])
    _GUICtrlMenu_TrackPopupMenu($MenuContext2, $TestWindow2)
    _GUICtrlMenu_DestroyMenu($MenuContext2)
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_LV_PopUpMenu2


I have two window dialogs and two listview controls defined.

Each listview control has its own popup menu and menu items.

The code above works fine as long as both window dialogs are visible.

You can right-click on each listview control and you get the designated menu popped up and if you select an item, the message for the specific item is being written into the console frame for it.

However, if you close window 2, and attempt to trigger the options in the popup menu for window 1, you will notice that the notification messages are no longer being triggered at all.

The popup menu becomes visible if you right-click the area and disappears if you select an option, but the control item no longer sends a notification which means that the attached events for the trapping are no longer being executed.

Now if you switch the code snippets of the window frames being generated, you will notice you can achieve the same issue the other way round, which means that context menu item notifications are being received and trigger an event routine as long as window 1 would then in that case remain open.

So it seems that whichever window is generated the last, that window somehow seems to get attached to the notification messages that are being send by the dummy controls for the context menu items.

Do i misinterpret something here, is there a fix for this issue or did i encountered some kind of bug inside Autoit3?

 

Edited by lbsl
Minor issue in code resolved to prevent distraction from real issue
Link to comment
Share on other sites

Hi

you create all dummy on GUI2

its a dummy place problem, this one works for me :

 

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

$TestWindow1 = GUICreate("TestWindow1", 353, 277, 100, 80)
$ListView1 = GUICtrlCreateListView("", 8, 8, 338, 262)
$ListView1_0 = GUICtrlCreateListViewItem("TestItem1", $ListView1)
$ListView1_1 = GUICtrlCreateListViewItem("TestItem2", $ListView1)
$ListView1_2 = GUICtrlCreateListViewItem("TestItem3", $ListView1)
GUISetState(@SW_SHOW)

;Change here <=================================================
Local $ahLVMenu[3]
For $i = 0 To 2
    $ahLVMenu[$i] = GUICtrlCreateDummy()
Next
;Change end <=================================================

$TestWindow2 = GUICreate("TestWindow2", 353, 277, 100 + 400, 80)
$ListView2 = GUICtrlCreateListView("", 8, 8, 338, 262)
$ListView2_0 = GUICtrlCreateListViewItem("TestItem1", $ListView2)
$ListView2_1 = GUICtrlCreateListViewItem("TestItem2", $ListView2)
$ListView2_2 = GUICtrlCreateListViewItem("TestItem3", $ListView2)
GUISetState(@SW_SHOW)

;Change here <=================================================
Local $ahLVMenu2[3]
For $i = 0 To 2
    $ahLVMenu2[$i] = GUICtrlCreateDummy()
Next
;Change end <=================================================

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

Local $MenuContext, $MenuContext2

;Wrong part <=================================================
;~ Local $ahLVMenu[3]
;~ Local $ahLVMenu2[3]

;Wrong part <=================================================
;~ For $i = 0 To 2
;~     $ahLVMenu[$i] = GUICtrlCreateDummy()
;~     $ahLVMenu2[$i] = GUICtrlCreateDummy()
;~ Next

While 1
    Local $nMsg = GUIGetMsg(1)

    Switch $nMsg[0]
        Case $GUI_EVENT_CLOSE
            If $nMsg[1] == $TestWindow2 Then
                GUISetState(@SW_HIDE, $nMsg[1])
            Else
                Exit
            EndIf

        Case $ahLVMenu[0]
            ConsoleWrite("Dialog 1, Item 1" & @CRLF)

        Case $ahLVMenu[1]
            ConsoleWrite("Dialog 1, Item 2" & @CRLF)

        Case $ahLVMenu[2]
            ConsoleWrite("Dialog 1, Item 3" & @CRLF)

        Case $ahLVMenu2[0]
            ConsoleWrite("Dialog 2, Item 1" & @CRLF)

        Case $ahLVMenu2[1]
            ConsoleWrite("Dialog 2, Item 2" & @CRLF)

        Case $ahLVMenu2[2]
            ConsoleWrite("Dialog 2, Item 3" & @CRLF)

    EndSwitch
WEnd



Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    #forceref $hWnd, $Msg, $wParam
    Local $hWndFrom, $iIDFrom, $event, $tNMHDR, $hWndListView, $hWndListView2, $tInfo
    $hWndListView = $ListView1
    $hWndListView2 = $ListView2
    Local $tMsgFilter, $hMenu
    If Not IsHWnd($ListView1) Then $hWndListView = GUICtrlGetHandle($ListView1)
    If Not IsHWnd($ListView2) Then $hWndListView2 = GUICtrlGetHandle($ListView2)

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $event = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView2

            Switch $event
                Case $NM_RCLICK ; Sent by a list-view control when the user clicks an item with the right mouse button
                    _LV_PopUpMenu2() ; Show popup context menu in Pharmacist article list

            EndSwitch

        Case $hWndListView
            Switch $event
                Case $NM_RCLICK ; Sent by a list-view control when the user clicks an item with the right mouse button
                    _LV_PopUpMenu() ; Show popup context menu in Pharmacist article list

            EndSwitch

    EndSwitch
    $hWndFrom = 0
    $iIDFrom = 0
    $tNMHDR = 0
    $hWndListView = 0
    $hWndListView2 = 0
    $tInfo = 0
    $tMsgFilter = 0
    $hMenu = 0
    Return $GUI_RUNDEFMSG

EndFunc   ;==>WM_NOTIFY



Func _LV_PopUpMenu()

    $MenuContext = _GUICtrlMenu_CreatePopup(40)
    _GUICtrlMenu_InsertMenuItem($MenuContext, 0, "Dialog 1, item 1", $ahLVMenu[0])
    _GUICtrlMenu_InsertMenuItem($MenuContext, 1, "Dialog 1, item 2", $ahLVMenu[1])
    _GUICtrlMenu_InsertMenuItem($MenuContext, 2, "Dialog 1, item 3", $ahLVMenu[2])
    _GUICtrlMenu_TrackPopupMenu($MenuContext, $TestWindow1)
    _GUICtrlMenu_DestroyMenu($MenuContext)
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_LV_PopUpMenu



Func _LV_PopUpMenu2()

    $MenuContext2 = _GUICtrlMenu_CreatePopup(40)
    _GUICtrlMenu_InsertMenuItem($MenuContext2, 0, "Dialog 2, item 1", $ahLVMenu2[0])
    _GUICtrlMenu_InsertMenuItem($MenuContext2, 1, "Dialog 2, item 2", $ahLVMenu2[1])
    _GUICtrlMenu_InsertMenuItem($MenuContext2, 2, "Dialog 2, item 3", $ahLVMenu2[2])
    _GUICtrlMenu_TrackPopupMenu($MenuContext2, $TestWindow2)
    _GUICtrlMenu_DestroyMenu($MenuContext2)
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_LV_PopUpMenu2

Edit: for clarify :

 

Quote

GUICtrlCreateDummy : Creates a Dummy control for the GUI.

=

GUICtrlCreateDummy : Creates a Dummy control for the last GUICreate

 

Edited by Synapsee
Link to comment
Share on other sites

53 minutes ago, Synapsee said:

Hi

you create all dummy on GUI2

its a dummy place problem, this one works for me :

expandpopup

GUICtrlCreateDummy : Creates a Dummy control for the GUI.

=

GUICtrlCreateDummy : Creates a Dummy control for the last GUICreate

 

 

Thanks a million!!

This seems logic, but was not obvious for me on the surface.

 

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