http://www.perlmonks.org?node_id=1019124


in reply to Re^5: How to get a window's menu as a Win32::GUI::Menu object?
in thread How to get a window's menu as a Win32::GUI::Menu object?

I don't know, but it certainly answers the question you asked , and I quote
"returns a menu HANDLE, not an object reference. This seems to be more or less useless -- unless there's a way to turn the handle into an object? "

Yes, but not just any old object -- THE object the handle was associated with. Sorry, but I would have thought this was obvious given the context of the question. :-/

I am actually using a global now, but I'm looking for a way around it since I'm also using threads which sometimes don't seem to play well with global Win32::GUI object variables.

Anyway, thanks for the suggestions. Storing $Menu inside $WinMain is the solution I'm looking for. I tried something like this before (on a different Win32::GUI issue), but I couldn't make it work -- it's been a while, but IIRC the stored variable refused to "stick" to the object (it was undefined when I tried to access it later). Chalk it up to my lack of understanding of perl's object handling I guess.

  • Comment on Re^6: How to get a window's menu as a Win32::GUI::Menu object?

Replies are listed 'Best First'.
Re^7: How to get a window's menu as a Win32::GUI::Menu object?
by Anonymous Monk on Feb 17, 2013 at 11:16 UTC

    Yes, but not just any old object -- THE object the handle was associated with. Sorry, but I would have thought this was obvious given the context of the question. :-/

    :) Well, sorry, it wasn't obvious to me -- Win32::GUI simply doesn't do that, its not Tk.pm or Wx.pm or some such

    There is the undocumented Win32::GUI::GetWindowObject($handle) but it doesn't work with menus

    foreget this update: http://search.cpan.org/grep?cpanid=ROBERTMAY&release=Win32-GUI-1.06&string=hmenu&i=1&n=1&C=0 reveals GetMenuFromID

    I guess you could remove the IsWindow check from GetWindowObject, recompile Win32::GUI, and try that ... but if this doesn't make you rethink choosing Win32::GUI :)