Well, i have a little problem with handling popup menu childs. The parent menu handle i can get easy with FindWindow, as i know the class of menu, that is #32768. Of course we have a nice api like FindWindowEx, but its doesnt help, its doesnt find any childs menu in my menu. Other solution it to use SetWindowsHoookExA, but i want to do it without hooks. And now the question -- how easy to get handles of menu childs without any hooking?!
Posted on 2003-09-07 10:33:38 by lightus
Posted on 2003-09-07 22:05:45 by P2M
Sub-menu windows are not created as child windows of the main menu, but of the window that is the parent of the entire menu. What do you need the menu window handle for?
Posted on 2003-09-08 11:36:17 by Sephiroth3
Why not use the API's that were meant for the purpose ?

GetMenu <- You need the Window handle for this one
GetSubMenu <- you need the main menu handle

BTW menus are not children of the main window, if they were they could not be displayed outside of the window rect. They are necessarily children of the desktop in the same way that the listbox potion in a drop-down combo box is a child of the desktop.
Posted on 2003-09-08 11:42:54 by donkey
I thought he wanted to know the handle of the window where the opened menu is displayed?
Posted on 2003-09-08 11:45:02 by Sephiroth3
Hi Sephiroth3,

I may have misunderstood. I thought he had a basic misconception about menus. They are in reality a specialized dialog box of their own which is a child of the desktop that has been redirected. No child window can be displayed outside of the bounding rectangle of it's parent, it will be clipped. In order to allow a menu that is longer than the window it is attached to to fully drop down it has to be a child of the desktop.
Posted on 2003-09-08 11:50:59 by donkey
hello again!
Well, i needed to get a real window handle of menu for changing menu style and make menu custom owner draw. As u know, menu is window too, buts at every click on icon, windows creates this window again, and then kill it. My problem is get a real window handles of all childs in my menu, for making it owner draw, when menu is inited with WM_INITMENUPOPUP. As u saw, i can get a real window handle with FindowWindow, but i dont know how to get window handles of other childs of menu. Any ideas?

p.s. i will get solution that works without any hook. ;)
Posted on 2003-09-09 13:05:13 by lightus
Menu belongs to your program?
Posted on 2003-09-09 19:09:22 by P2M
I don't quite understand what the problem is here. The menu handle that you get when you ask the main window is the handle to the menu bar it is usable in all menu functions. All submenus are derivable from that menu and all handles returned are usable in menu functions. If you have a window you find the handle to it's menu bar using GetMenu then you can enumerate the submenus using GetSubMenu and the rest of the menu functions. I am completely at a loss as to why you would need to use FindWindow in order to obtain a menu handle. Maybe if you expalined what you are trying to do it would be easier to answer your question but "I need the sub menu handle" begs the answer GetSubMenu and nothing else.

invoke GetMenu,hWnd
mov hMenuBar,eax
invoke GetSubMenu,hMenuBar,0; returns null if item is not a dropdown menu
mov hSubMenu1,eax

Get the handle to the first dropdown menu.
Posted on 2003-09-09 19:34:11 by donkey
I think lightus want hwnd.
Posted on 2003-09-09 20:14:06 by P2M
That's not what he asked "how easy to get handles of menu childs without any hooking?!". He expects a menu to react like a window just because it has a dialog class. It is technically a dialog but it does not handle the same set of messages as a normal window. In the same way that an Edit control does not react like a combo box, both are technically windows but they respond to a different set of messages. Instead of using FindWindow to find the handle to the menu he should be finding the applications window and working from that.
Posted on 2003-09-09 20:47:52 by donkey
When i wrote -- "i want to get a real window handle", i mean of course HWND. Of course my menu belongs my program. With using FindWindow and param the class name i will get the FIRST HWND of my menu, not (!) a hwnd of window, where used this menu. As i wrote i have a submenu (childs), and this ones have others hwnd's, but i dont know how to get this hwnd's.
Posted on 2003-09-10 08:02:30 by lightus

With using FindWindow and param the class name i will get the FIRST HWND of my menu, not (!) a hwnd of window, where used this menu. <snip confusing part>


It's still a little confusing I'm afraid whether you're actually trying to deal with windows or with menus, but my initial thought was that EnumChildWindows was needed. FindWindowEx by itself won't find all the child windows (of any kind) but it can be used in a callback proc to go through ALL child windows to find *where* your popup menu was initiated from, IF this is what you're looking for(?). If you're looking to handle submenu items per se, then donkey's info is what you need.

This is a very flexible idea, but as a quick example, in your WM_INITMENUPOPUP or WM_COMMAND handler for your popup menu you can find the HWND of the control from *where* the popup was created by invoking EnumChildWindows with an initial Parent hwnd to start with and the address of the Callback proc:

invoke EnumChildWindows, hDialog, ADDR Find_Correct_Listview, NULL

And the callback:

;=======Find_Correct_Listview Proc========
Find_Correct_Listview proc hwnd:HWND, lparam:DWORD

invoke FindWindowEx, hwnd, NULL, CTEXT ("SysListView32"), NULL
.IF eax
mov hListView1, eax ; found it!
return FALSE ; stop now
return TRUE ; else keep searching, hwnd is updated internally

Find_Correct_Listview endp
;======End Find_Correct_Listview===========

Again, I don't know if this is what you need, you are dealing with "window" handles here, not menu or submenu handles. That should be enough to add to the confusion...;)

Posted on 2003-09-10 10:24:00 by Kayaker
i needed to get a real window handle of menu for changing menu style and make menu custom owner draw ...Of course my menu belongs my program

imho You have chosen wrong way.
When making menu use flag MF_OWNERDRAW and process messages WM_MEASUREITEM and M_DRAWITEM.
Posted on 2003-09-10 18:55:52 by P2M