Shoutbox

HELP - CreatePopupMenu sub-menus? - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: HELP - CreatePopupMenu sub-menus? (/showthread.php?tid=92513)

HELP - CreatePopupMenu sub-menus? by whiz on 10-08-2009 at 07:07 PM

Javascript code:
var MF_CHECKED = 0x8;
var MF_APPEND = 0x100;
var MF_GRAYED = 0x1;
var MF_SEPARATOR = 0x800;
var MF_STRING = 0x0;
// don't need the rest...
var MCOWMnu = Interop.Call("user32", "CreatePopupMenu");
Interop.Call("user32", "AppendMenuW", MCOWMnu, MF_GRAYED, 0, "Normal");
Interop.Call("user32", "AppendMenuW", MCOWMnu, MF_CHECKED, 0, "Checked");
Interop.Call("user32", "AppendMenuW", MCOWMnu, MF_SEPARATOR, 0, 0);
Interop.Call("user32", "AppendMenuW", MCOWMnu, MF_STRING, 0, "Disabled");

But is there a way to make a sub-menu?

quote:
Originally posted by MSDN
MF_POPUP: Specifies that the menu item opens a drop-down menu or submenu. The uIDNewItem parameter specifies a handle to the drop-down menu or submenu. This flag is used to add a menu name to a menu bar, or a menu item that opens a submenu to a drop-down menu, submenu, or shortcut menu.
Does that open a menu, close a menu, insert an existing menu or what?

EDIT: seems that MF_POPUP is 0x10, but now what?
RE: HELP - CreatePopupMenu sub-menus? by Matti on 10-08-2009 at 07:36 PM

You create a submenu with CreatePopupMenu, add items to it and then pass the handle to AppendMenuW to add it to your main menu.

However, if you prefer to avoid all this hassle, you can simply go and get the Menu class I made for Countdown Live. The only required change is that you must change this line:

Javascript code:
var subclass = MsgPlus.CreateWnd('Interfaces\\WndSubclass.xml', 'WndSubclass', 2);

to your own subclass creation code.

Example usage:
Javascript code:
// Menu callback
var MenuCallback = function(ItemId) {
    Debug.Trace("Item "+ItemId+" was clicked");
};
 
// Create main menu
var MainMenu = new Menu(MenuCallback);
MainMenu.AddMenuItem("ItemOne", "Hello world!");
MainMenu.AddMenuItem("ItemTwo", "Lorem ipsum");
 
// Create and add a submenu
var SubMenu = MainMenu.CreateSubMenu();
SubMenu.AddMenuItem("SubitemOne", "Sub item 1");
SubMenu.AddMenuItem("SubitemTwo", "Sub item 2");
MainMenu.AddSubMenu(SubMenu, "A sub menu");
 
// Open the menu on the current cursor position
MainMenu.Open();


Example subclass window code:
XML code:
<?xml version="1.0" encoding="UTF-16"?>
<Interfaces xmlns="urn:msgplus:interface" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:msgplus:interface PlusInterface.xsd">
    <!-- SUBCLASS WINDOW -->
    <Window Id="WndSubclass" Version="1">
        <Attributes>
            <ShowInTaskbar>false</ShowInTaskbar>
        </Attributes>
        <Position Width="0" Height="0"/>
        <DialogTmpl/>
    </Window>
</Interfaces>


RE: HELP - CreatePopupMenu sub-menus? by whiz on 10-08-2009 at 07:48 PM

Sounds good, thanks!  :P


RE: HELP - CreatePopupMenu sub-menus? by Spunky on 10-08-2009 at 07:54 PM

I lost my example from the RPG script I was making (ages ago), but if you want to do it without the class, goto MSDN and take a look at the"Remarks section".

So create a new menu (different var name obvoiusly), and then append a new item to the main menu, but pass the MF_POPUP param and pass it the handle to the new menu.

If that makes sense lol.

I think you have to finish the popup menu before "attaching" it to the main menu though.


RE: HELP - CreatePopupMenu sub-menus? by whiz on 10-09-2009 at 06:08 PM

That's better - I'll use that.

Javascript code:
var MCOWMnu = Interop.Call("user32", "CreatePopupMenu");
Interop.Call("user32", "AppendMenuW", MCOWMnu, MF_STRING, 0, "Normal");
Interop.Call("user32", "AppendMenuW", MCOWMnu, MF_CHECKED, 0, "Checked");
Interop.Call("user32", "AppendMenuW", MCOWMnu, MF_SEPARATOR, 0, 0);
Interop.Call("user32", "AppendMenuW", MCOWMnu, MF_GRAYED, 0, "Disabled");
var MCOWSubMnu = Interop.Call("user32", "CreatePopupMenu");
Interop.Call("user32", "AppendMenuW", MCOWSubMnu, MF_STRING, 0, "Sub-option");
Interop.Call("user32", "AppendMenuW", MCOWMnu, MF_POPUP, MCOWSubMnu, "Sub-menu");

It works!  :P