Article

From:
To:
Lorne Anderson
Subject:
Re: TrackPopupMenuEx and owner draw
Newsgroup:
embarcadero.public.delphi.language.delphi.general

Re: TrackPopupMenuEx and owner draw

"Lorne Anderson" <✉hotmail.com> wrote in message 
news:✉forums.codegear.com...

> The owner draw code is not processed if I launch the popup with 
> TrackPopupMenuEx - even with a simple test procedure like this:

That is because you are passing the wrong HWND to TrackPopupMenuEx(), so all 
of the menu-related window messages get sent to the wrong window and are not 
dispatched to the TMenuItem objects correctly.  VCL menus that are based on 
TMenu and TMenuItem use a dedicated window that is provided by the 
TPopupList class in the Menus unit.  You need to pass that window to 
TrackPopupMenu/Ex(), ie:

{code:delphi} uses   Menus; .... Selected := Ord(TrackPopupMenuEx(test.Handle, TPM_LEFTALIGN or TPM_BOTTOMALIGN or TPM_RETURNCMD, pt.X, pt.Y, PopupList.Window, nil)); .... {code}
BTW, when you use the TPM_RETURNCMD flag, TrackPopupMenuEx() returns a menu ID, not an index. To translate that ID into a TMenuItem correctly, you have to loop through the items of your menu one at a time until you find the one whose ID property matches the value that TrackPopupMenuEx() returned. But since all you are doing is triggering the menu item's OnClick event, you should just remove the TPM_RETURNCMD flag altogether and let the TMenuItem handle that natively (which it will be able to correctly once you start passing the TPopupList window to TrackPopupMenuEx()).
-- Remy Lebeau (TeamB)
FYI: Phrase searches are enclosed in either single or double quotes
 
 
Originally created by
Tamarack Associates
Sat, 23 Nov 2024 19:42:16 UTC
Copyright © 2009-2024
HREF Tools Corp.