get a window back from a tag in menuitem ?

Hi,

I’m trying to get back my window from a tag in a menu item.

I previously added a window to a menuitem’ tag using (wm is my window’s menu)

    aMenu = new MenuItem( aWindow.Title)
    aMenu.Tag = aWindow
    if wm.Count<13 then
      aMenu.KeyboardShortcut = kCommandKeyMenu+"-"+chr(asc("0")+(wm.Count-3))
    end if
    wm.Append aMenu

then later in the menuitem action I try to retrieve the window with : (me is a menuitem)

dim mywindow as Window mywindow = Window(me.Tag.WindowPtrValue)

and I get an error : “type error waiting for Ptr but got Window” when I compile.
can anybody tell me how to get back my window from the tag field of the menuitem ?

when I trace the program, I have my window I want in the Tag field of the menuitem, but I cannot get it back in a variable …
thanks.

Spot the difference:

dim mywindow as Window mywindow = Window(me.Tag).WindowPtrValue

well it works with

    dim mywindow as Window
    mywindow = Window(me.Tag.ObjectValue)

so…

MenuItem.Tag is a variant, so when you store a Window in it you can actually pull that window right out of it.

dim myWindow as Window myWindow = me.tag
** This is all in theory, I haven’t tested it.

[quote=130853:@Tim Parnell]MenuItem.Tag is a variant, so when you store a Window in it you can actually pull that window right out of it.

dim myWindow as Window myWindow = me.tag
** This is all in theory, I haven’t tested it.[/quote]

well it … works too ! and it’s so simple… thanks.

If you’re targeting OS X, I wrote a window tricks article for the XDev magazine and in there is the code to get the OS to manage the Window Menu for you, you get the tick marks and diamonds for free.