Thread View: borland.public.cppbuilder.nativeapi
11 messages
11 total messages
Started by Kris
Fri, 27 Jul 2007 08:50
Displaying menu after using CreatePopupMenu()
Author: Kris
Date: Fri, 27 Jul 2007 08:50
Date: Fri, 27 Jul 2007 08:50
25 lines
1661 bytes
1661 bytes
Hi, I'm attempting to create a Unicode pop-up menu but due to my lack of experience with non-VCL UI components I'm having problems with even the most basic things (note that I do not want to use a 3rd party component, but rather try it myself). I'm assuming this code creates a single menu-item in a pop-up menu. Later on, when I get things working I'll be using AppendMenuW to get Unicode support, but for now I'm concentrating on the basic stuff. HMENU MyPopUpMenu; MyPopUpMenu=CreatePopupMenu(); AppendMenu(MyPopUpMenu,MF_STRING,NULL,"Item"); However, I can't seem to figure out which function to call when I actually need to display the popup-menu I just created (and which I assume allows me to determine the coordinates of where the menu should appear). Any information you can share to get met started is much appreciated. Thanks, Kris
Re: Displaying menu after using CreatePopupMenu()
Author: Kris
Date: Fri, 27 Jul 2007 10:09
Date: Fri, 27 Jul 2007 10:09
6 lines
1090 bytes
1090 bytes
Kris wrote: > However, I can't seem to figure out which function to call when I > actually need to display the popup-menu I just created Problem solved. I completely overlooked the TrackPopupMenuEx() call.
Re: Displaying menu after using CreatePopupMenu()
Author: Remy Lebeau (TeamB)
Date: Fri, 27 Jul 2007 10:28
Date: Fri, 27 Jul 2007 10:28
12 lines
1346 bytes
1346 bytes
"Kris" <test@test.com> wrote in message news:46a9b224$1@newsgroups.borland.com... > However, I can't seem to figure out which function to > call when I actually need to display the popup-menu I just created TrackMenuPopup() or TrackMenuPopupEx(), which is clearly stated in CreatePopupMenu()'s documentation. Gambit
Re: Displaying menu after using CreatePopupMenu()
Author: Kris
Date: Fri, 27 Jul 2007 12:36
Date: Fri, 27 Jul 2007 12:36
24 lines
1880 bytes
1880 bytes
Remy Lebeau (TeamB) wrote: > > TrackMenuPopup() or TrackMenuPopupEx(), which is clearly stated in > CreatePopupMenu()'s documentation. Thanks. I can now properly display a Unicode menu and detect when menu items are clicked. However, I'm still wondering about one thing... #define IDM_MENU_ITEM1 0x00001234 AppendMenuW(MyPopUpMenu,MF_STRING,IDM_MENU_ITEM1,MyWideString); So, intercepting WM_COMMAND in WndProc when the menu item is clicked results in WParamLo containing 0x1234. Based on this value I can determine which menu item was actually clicked. This works great. But I'm wondering if my arbitrary 0x1234 WParamLo value that isn't going to potentially run into conflicts with other UI actions (e.g. menu items generated by VCL). Are there any rules as to which values I can use safely use for WParamLo ? Thanks, Kris
Re: Displaying menu after using CreatePopupMenu()
Author: Remy Lebeau (TeamB)
Date: Fri, 27 Jul 2007 17:11
Date: Fri, 27 Jul 2007 17:11
15 lines
1479 bytes
1479 bytes
"Kris" <test@test.com> wrote in message news:46a9e711$1@newsgroups.borland.com... > I'm wondering if my arbitrary 0x1234 WParamLo value > that isn't going to potentially run into conflicts with other > UI actions (e.g. menu items generated by VCL). VCL menu items use their own provide HWND to handle their actions. The WM_COMMAND for them will never go through your message handler. As for the IDs for them, they start at 0 growing sequentially, and then when an item is destroyed, its ID is reused for the next item that is created. Gambit
Re: Displaying menu after using CreatePopupMenu()
Author: Remy Lebeau (TeamB)
Date: Fri, 27 Jul 2007 17:12
Date: Fri, 27 Jul 2007 17:12
10 lines
1186 bytes
1186 bytes
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message news:46aa2786$1@newsgroups.borland.com... > As for the IDs for them, they start at 0 growing sequentially Or maybe they start at 1, I'm not sure which. Gambit
Re: Displaying menu after using CreatePopupMenu()
Author: Kris
Date: Fri, 27 Jul 2007 17:42
Date: Fri, 27 Jul 2007 17:42
30 lines
2159 bytes
2159 bytes
Remy Lebeau (TeamB) wrote: >> I'm wondering if my arbitrary 0x1234 WParamLo value >> that isn't going to potentially run into conflicts with other >> UI actions (e.g. menu items generated by VCL). > > VCL menu items use their own provide HWND to handle their actions. The > WM_COMMAND for them will never go through your message handler. However, my WndProc() does receive WM_COMMAND messages other than the one that I am explicitly generating when my pop-up menu item is clicked. My test application has, besides a button that triggers the pop-up in question, also some additional buttons that generate some output in a TMemo. Clicking on those buttons does generate several other WM_COMMAND events such as: Message=00000111 - WParam=0000064E - LParam=0004064E While clicking my Unicode Popup menu with 0x1234 WParamLo (the value is set via AppendMenuW) generates a WM_COMMAND like this: Message=00000111 - WParam=00001234 - LParam=00000000 As you can see I am going to have potential problems with distinguishing between events from my own popup menu and from other events. I am hoping you can clarify this behavior. Thanks, Kris
Re: Displaying menu after using CreatePopupMenu()
Author: Remy Lebeau (TeamB)
Date: Fri, 27 Jul 2007 18:48
Date: Fri, 27 Jul 2007 18:48
50 lines
3342 bytes
3342 bytes
"Kris" <ks@ks.com> wrote in message news:46aa2e75@newsgroups.borland.com... > However, my WndProc() does receive WM_COMMAND > messages other than the one that I am explicitly generating > when my pop-up menu item is clicked. As it should be. WM_COMMAND is used for many things besides menus. That is why you need to look at the HIWORD(wParam) and lParam values to know what the message actually relates to. > My test application has, besides a button that triggers the > pop-up in question, also some additional buttons that generate > some output in a TMemo. Clicking on those buttons does > generate several other WM_COMMAND events such as: > Message=00000111 - WParam=0000064E - LParam=0004064E That LParam contains the HWND of the button that is sending the message. In this case, the HIWORD(wParam) value is the BN_CLICKED notification. So the VCL will automatically forward the message to the appropriate button component for handling, which will then cause that button's OnClick event to be triggered. > While clicking my Unicode Popup menu with 0x1234 WParamLo > (the value is set via AppendMenuW) generates a WM_COMMAND > like this: > Message=00000111 - WParam=00001234 - LParam=00000000 That LParam does not contain an HWND, so it is a message from a menu, and the HIWORD(wParam) value contains the ID of the menu item. > As you can see I am going to have potential problems with > distinguishing between events from my own popup menu > and from other events. No, you will not. You just need to learn how to read the messages correctly. Not to mention that if you allow the VCL to do its default processing first, you can detect if a message has already been processed so you can ignore it. You only have to focus on messages that are not processed automatically. Of course, you can simplify that greatly by doing the same thing TMenu does for itself - create a separate HWND specifically for menu messages and nothing else. You don't need to send them through your TForm's message handler at all. That way, there is no way for any conflicts to occur at all, as your HWND will only need to look for the IDs of your particular menu items and discard everything else. Gambit
Re: Displaying menu after using CreatePopupMenu()
Author: Kris
Date: Sat, 28 Jul 2007 17:01
Date: Sat, 28 Jul 2007 17:01
19 lines
1923 bytes
1923 bytes
Remy Lebeau (TeamB) wrote: > "Kris" <ks@ks.com> wrote in message news:46aa2e75@newsgroups.borland.com... > >> However, my WndProc() does receive WM_COMMAND >> messages other than the one that I am explicitly generating >> when my pop-up menu item is clicked. Thanks for clarifying this. Everything is making much more sense now :-) I assume it is OK to call my event handler (the one that does some processing due to the menu click) from within WndProc() itself ? Or should I be exiting WndProc() as soon as possible ? And e.g. only set a flag that the menu-item has been clicked, exit WndProc() and call the event handler from within e.g. ApplicationEventsIdle ? Thanks, Kris
Re: Displaying menu after using CreatePopupMenu()
Author: Alan Bellingham
Date: Sat, 28 Jul 2007 17:09
Date: Sat, 28 Jul 2007 17:09
14 lines
1583 bytes
1583 bytes
Kris <ks@ks.com> wrote: >I assume it is OK to call my event handler (the one that does some >processing due to the menu click) from within WndProc() itself ? That's the way it's normally done. If the work in question is going to take so long that the UI freezes for too long, then you may wish to kick off a thread to do its work. Alan Bellingham -- Team Browns <url:http://www.borland.com/newsgroups/> Borland newsgroup descriptions <url:http://www.borland.com/newsgroups/netiquette.html> netiquette
Re: Displaying menu after using CreatePopupMenu()
Author: Kris
Date: Sat, 28 Jul 2007 18:42
Date: Sat, 28 Jul 2007 18:42
8 lines
1382 bytes
1382 bytes
Alan Bellingham wrote: > That's the way it's normally done. If the work in question is going to > take so long that the UI freezes for too long, then you may wish to kick > off a thread to do its work. Thanks for the confirmation. Kris
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads