Sign in to follow this  
Followers 0
Laetterman

Menu Limit In Child-windows?

3 posts in this topic

The following script relates a ContextMenu to every child window, but from the 17th window on, the connected function doesn't start. Do you have an idea where teh fault is?

#include <GUIConstants.au3>
#include <Array.au3>
HotKeySet("{ESC}", "Terminate")
DIM $i, $sub [80][99], $sub_context[80][99]

AutoItSetOption ( "TrayIconDebug", 1 )
Opt("WinTitleMatchMode", 3) 
Opt("GUIOnEventMode", 1)

$parent = GUICreate("Gui" & $i, 200, 100, 50, 45)
GUISetState (@SW_SHOW)

For $i = 1 To 20
    GUICreate("Gui" & $i, 200, 100, 40*$i, 45*$i, -1, -1, $parent)
    GUISetState (@SW_SHOW)
    $contextmenu = GUICtrlCreateContextMenu ()

    $context_sub = GUICtrlCreateMenu("Play Track", $contextmenu)
    $context_verkn = GUICtrlCreateMenuItem ("Verknüpfung bearbeiten...", $contextmenu)
    GUICtrlSetOnEvent($context_verkn, "f_start_Song")
    GUICtrlCreateMenuitem ("",$contextmenu) 
    $context_entf = GUICtrlCreateMenuitem ("Delete", $contextmenu)
    GUICtrlSetOnEvent($context_entf,  "Terminate")
    $z = 0
    While $z<12
        $z = $z + 1
        $sub[$i][$z] = GUICtrlCreateMenuitem ('Title ' & $z, $context_sub)
        GUICtrlSetOnEvent($sub[$i][$z], "f_Start_Song")
        $sub_context[$i][$z] = $i
    WEnd
Next

While 1
    Sleep(10)
Wend

Func f_start_Song()
        Beep(400, 10)
    EndFunc

Func Terminate()
    Exit
EndFunc

Thanx,

Laetterman

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Not a child window limit but a menu identifier limitation!

From MSDN:

"...A menu-item identifier must be a value from 0 to 65,535, even though it is a 32-bit integer. This is because the WM_COMMAND message passes a menu-item identifier as the low-order word of its wParam parameter..."

So the last child windows and menu items will get to high menu id's, cause every next child window starts with an ID of 4096 more - in WindowsNT they will be created, in Win95 there are only blank menus.

At the moment there is no chance to solve this.

Just create less windows...

I think I will implement a check - so if the internal menu ID is bigger than 65535 no menu item will be created.

Also I will make an additional info to the helpfile.

Some things in Windows are really confusing...

However, thanks for asking/info :think:

Holger

Edit:

Maybe a small workaround:

#include <GUIConstants.au3>

Opt("TrayIconDebug", 1)
Opt("WinTitleMatchMode", 3)
Opt("GUIOnEventMode", 1)

HotKeySet("{ESC}", "Terminate")

$parent = GUICreate("Gui1", 200, 100, 50, 45)
GUISetState (@SW_SHOW)

$dummy          = GUICtrlCreateDummy()
$contextmenu    = GUICtrlCreateContextMenu($dummy)

$context_sub    = GUICtrlCreateMenu("Play Track", $contextmenu)
For $z = 1 To 12
    GUICtrlCreateMenuitem('Title ' & $z, $context_sub)
    GUICtrlSetOnEvent(-1, "f_Start_Song")
Next
    
GUICtrlCreateMenuItem("Verknüpfung bearbeiten...", $contextmenu)
GUICtrlSetOnEvent(-1, "f_start_Song")
GUICtrlCreateMenuitem ("",$contextmenu)
GUICtrlCreateMenuitem ("Delete", $contextmenu)
GUICtrlSetOnEvent(-1,  "Terminate")
    
For $i = 2 To 20
    GUICreate("Gui" & $i, 200, 100, 40*$i, 45*$i, -1, -1, $parent)
    GUISetState (@SW_SHOW)
    GUISetOnEvent($GUI_EVENT_SECONDARYUP, "f_show_context")
Next

While 1
    Sleep(10)
Wend

Exit


Func f_start_Song()
    Beep(400, 10)
EndFunc


Func Terminate()
    Exit
EndFunc


Func f_show_context()
    Local $hMenu = GUICtrlGetHandle($contextmenu)
    Local $arPos = MouseGetPos()

    DllCall("user32.dll", "int", "TrackPopupMenuEx", _
                                "hwnd", $hMenu, _
                                "int", 0, _
                                "int", $arPos[0], _
                                "int", $arPos[1], _
                                "hwnd", $parent, _
                                "ptr", 0)
EndFunc
Edited by Holger

Share this post


Link to post
Share on other sites

thank you for the info! I need dynamic menu entrys, I guess the workaround only works with a static structure ... ?

Laetterman

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