HELP - CreatePopupMenu sub-menus? |
Author: |
Message: |
whiz
Senior Member
Posts: 568 Reputation: 8
– / – /
Joined: Nov 2008
|
O.P. HELP - CreatePopupMenu sub-menus?
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?
This post was edited on 10-08-2009 at 07:17 PM by whiz.
|
|
10-08-2009 07:07 PM |
|
|
Matti
Elite Member
Script Developer and Helper
Posts: 1646 Reputation: 39
32 / /
Joined: Apr 2004
|
RE: HELP - CreatePopupMenu sub-menus?
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>
Attachment: Menu.js.txt (27.96 KB)
This file has been downloaded 169 time(s).
|
|
10-08-2009 07:36 PM |
|
|
whiz
Senior Member
Posts: 568 Reputation: 8
– / – /
Joined: Nov 2008
|
O.P. RE: HELP - CreatePopupMenu sub-menus?
Sounds good, thanks!
|
|
10-08-2009 07:48 PM |
|
|
Spunky
Former Super Mod
Posts: 3658 Reputation: 61
36 / /
Joined: Aug 2006
|
RE: HELP - CreatePopupMenu sub-menus?
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.
<Eljay> "Problems encountered: shit blew up"
|
|
10-08-2009 07:54 PM |
|
|
whiz
Senior Member
Posts: 568 Reputation: 8
– / – /
Joined: Nov 2008
|
O.P. RE: HELP - CreatePopupMenu sub-menus?
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!
This post was edited on 10-09-2009 at 06:14 PM by whiz.
|
|
10-09-2009 06:08 PM |
|
|
|
|