Context menu - How? |
Post Reply |
Author | |
Alistair
Newbie Joined: 14 May 2004 Status: Offline Points: 15 |
Post Options
Thanks(0)
Posted: 17 May 2004 at 3:55am |
In my MDI application, I currently display a context menu on the right mouse button (it's actually a submenu of the main window menu). How would I do this using Xtreme Toolkit Pro (the help, as people have discussed, is not much help)? Here is the normal MFC version:
--- Al. |
|
Alistair
Newbie Joined: 14 May 2004 Status: Offline Points: 15 |
Post Options
Thanks(0)
|
Ok, I've solved that one (a search of the forum revealed I should have called CXTPCommandBars::TrackPopupMenu()) but now I have a related question: Another forum search has suggested that I cannot get a pointer to a CMenu from a CXTPMenuBar. Is this correct and I have to re-write all my CMenu handling code (enabling/disabling menu items depending on context) in terms of the XT classes or is there a way to get to the underlying CMenu object? The forum message saying that you can't was from a newbie user so I'm after the official word, just to be sure. Al.
|
|
Ark42
Senior Member Joined: 20 October 2003 Status: Offline Points: 291 |
Post Options
Thanks(0)
|
One option, if you use the designer editor and loaddesignerbars, is to do this, which is what I do: void CYOURView::OnContextMenu(CWnd* pWnd, CPoint point) { if( point.x < 0 || point.y < 0 ) { point.x = 0; point.y = 0; ClientToScreen(&point); } CXTPCommandBars *pCommandBars = static_cast<CXTPMDIFrameWnd *>(AfxGetMainWnd())->GetCommandBars(); CXTPControlPopup *pControlPopup = reinterpret_cast<CXTPControlPopup *>(pCommandBars- >m_pDesignerControls->FindControl(IDR_YOURPOPUPMENU)); CXTPPopupBar *pPopupBar = reinterpret_cast<CXTPPopupBar *>(pControlPopup->GetCommandBar()); CXTPCommandBars::TrackPopupMenu(pPopupBar, TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, this); } To set this up, in the designer, you put a menu on your menu bar just like your File, Edit, View, Window, Help, etc menus, put all your menu options on it, then just remove it from the menu bar and leave it in the control list, and assign it an ID there. |
|
Alistair
Newbie Joined: 14 May 2004 Status: Offline Points: 15 |
Post Options
Thanks(0)
|
Sadly, I didn't really understand that reply!
What I want to do now is enable / disable menu items individually, given a pointer to a CXTPMenuBar. For example (and this is very rough psuedocode):
where MyCheckFunc() returns whether the given resource Id should be enabled or not. Would this work and is it a reasonable solution? --- Al. |
|
Ark42
Senior Member Joined: 20 October 2003 Status: Offline Points: 291 |
Post Options
Thanks(0)
|
I think thats possible somehow, if you set the controls to be manually updated and stuff, but its not really a good way to do things. You can use ON_UPDATE_COMMAND_UI handlers and they affect the popup menu items just the same. |
|
Kenneth
Senior Member Joined: 23 May 2004 Location: United States Status: Offline Points: 256 |
Post Options
Thanks(0)
|
What is the proper way to get rid of a popup context menu? On windows xp I can left mouse click anyplace in the view and the menu will go away. However on Windows 98 and ME, this will not work! |
|
Oleg
Admin Group Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
|
Your main form is CXTPFrameWnd derived and has InitCommandBars call, isn't it? if it is Dialog Box application, you must add code from DialogSample. |
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
Kenneth
Senior Member Joined: 23 May 2004 Location: United States Status: Offline Points: 256 |
Post Options
Thanks(0)
|
Yes, the main form is CXTPFrameWnd and does have the InitCommandBars call. So how does a user get rid of the popup context menu on Windows 98/ME?
|
|
Ark42
Senior Member Joined: 20 October 2003 Status: Offline Points: 291 |
Post Options
Thanks(0)
|
You just click anywhere, and it works fine, as long as your window has focus, which is only ever an issue if you are putting the context menu on a system tray icon, in which case you have to steal window focus right before displaying the menu. If your context menu is in a normal window, you just click anywhere and it goes away, in any OS, if not, you screwed something up bigtime |
|
Kenneth
Senior Member Joined: 23 May 2004 Location: United States Status: Offline Points: 256 |
Post Options
Thanks(0)
|
Well, it could be I screwed it up bigtime, but the simple fact is it works on XP and not on Windows 98 or Windows Me. Have you tried it on these two systems?
|
|
Ark42
Senior Member Joined: 20 October 2003 Status: Offline Points: 291 |
Post Options
Thanks(0)
|
Yes, my context menus work fine on 95, 95b, 98, SE, ME, NT4, 2000, and XP. I regularly test my programs on all 8 OSes. |
|
Kenneth
Senior Member Joined: 23 May 2004 Location: United States Status: Offline Points: 256 |
Post Options
Thanks(0)
|
Is there any examples on how to do this correctly in the toolkit examples? |
|
Ark42
Senior Member Joined: 20 October 2003 Status: Offline Points: 291 |
Post Options
Thanks(0)
|
I think I posted my exact code already, the 3rd post in this topic. |
|
Kenneth
Senior Member Joined: 23 May 2004 Location: United States Status: Offline Points: 256 |
Post Options
Thanks(0)
|
Yes, I know, but it requires the use of the "designer" editor sample. Is this this only way to do it?
|
|
Ark42
Senior Member Joined: 20 October 2003 Status: Offline Points: 291 |
Post Options
Thanks(0)
|
No, it doesn't require the use of the designer, you just need to call CXTPCommandBars::TrackPopupMenu - it takes a CMenu or a CXTPPopupBar, but you can get those objects anywhere you want. |
|
Kenneth
Senior Member Joined: 23 May 2004 Location: United States Status: Offline Points: 256 |
Post Options
Thanks(0)
|
Here's exactly what I do, and the code works fine on XP, but not Windows 98 or ME. void CMyView::OnContextMenu(CWnd* pWnd,CPoint point)
|
|
Ark42
Senior Member Joined: 20 October 2003 Status: Offline Points: 291 |
Post Options
Thanks(0)
|
So just for the heck of it, I tested that exact code, and it works fine, all OSes. I bet you have a focus problem someplace else in your program. Try doing that in a blank project and it will work fine. |
|
Kenneth
Senior Member Joined: 23 May 2004 Location: United States Status: Offline Points: 256 |
Post Options
Thanks(0)
|
I don't believe its a focus problem. If I use: void CSecureNetTermView::OnContextMenu(CWnd* pWnd,CPoint point) Then everything works fine on all systems. However I get the old style menu instead of the toolkitpro style menu. Just another one of those strange ToolKitPro things like the CXTToolBar with the flag set not to display the customization bar, but the space is still there for the customization bar. Strange stuff indeed!
|
|
Ark42
Senior Member Joined: 20 October 2003 Status: Offline Points: 291 |
Post Options
Thanks(0)
|
I don't have that problem either (I have show expand button always set to false as well as customizable set to false in one of my programs) You can drag the toolbar all the way flush against the right edge without any problems. Maybe you need to upgrade? What version are you using? |
|
Kenneth
Senior Member Joined: 23 May 2004 Location: United States Status: Offline Points: 256 |
Post Options
Thanks(0)
|
The latest version. I used the code exactly as shown by I guess the one and only codejock developer. In this case I am using his example code to turn off the customizable dropdown on only one toolbar. The rest have the customizable dropdown enabled. It works with the exception that I cannot drag the toolbar flush against the right edge of the window. Also, on this problem, by view is a CFormView. Perhaps that is the difference that is causing the problem.
|
|
Ark42
Senior Member Joined: 20 October 2003 Status: Offline Points: 291 |
Post Options
Thanks(0)
|
You will likely need to do some extra work for CFormViews because they trap a lot of messages for dialog functions, and that could easily break the menus/toolbars. If you route the proper msgs in OnCmdMsg and such, I'm sure you could get it to work, you would just need to do some discovering and digging through the MFC source to find out what messages you need to pass. |
|
Kenneth
Senior Member Joined: 23 May 2004 Location: United States Status: Offline Points: 256 |
Post Options
Thanks(0)
|
I added the code within the DialogSample suggested by Oleg, but it has no affect. That sample does have the general menubar logic, but not a contextmenu popup. Perhaps there is very good reason for contextmenu popup samples not being shown anywhere.
|
|
Kenneth
Senior Member Joined: 23 May 2004 Location: United States Status: Offline Points: 256 |
Post Options
Thanks(0)
|
Found the reason. If I compile the application in ANSI mode, with no UNICOWS support, everything works perfect on all systems. If I compile with UNICODE and UNICOWS support, it works fine on Windows XP, but not on Windows 95, 98 or ME. In addition to the right popup context menu not releasing on a left mouse click, the same holds true for the menubar. The only way to release any menu popup is to use the escape key or left mouse click on the title bar! All the problems seen related to the left mouse click, when UNICOWS supported is added. Ark42, do you use UNICOWS at all? |
|
Kenneth
Senior Member Joined: 23 May 2004 Location: United States Status: Offline Points: 256 |
Post Options
Thanks(0)
|
Ark41, On the toolbar issue: This problem can be seen in the ToolKitPro examples, CommonControls when you add the following to the MainFrm OnCreate function: GetCommandBars()->GetCommandBarsOptions()->bShow ExpandButtonAlways = FALSE; Try to move the Animation, slider and the one with the words "Opened Documents" toolbars to the far right of the window and you can see it will stop exactly one dropdown button width from the right side.
|
|
Ark42
Senior Member Joined: 20 October 2003 Status: Offline Points: 291 |
Post Options
Thanks(0)
|
No, I compile strictly ANSI versions and rely on the user setting their code page if they really care about any amount of localization support. It eliminates a lot of hassle to only program for what Win95 has available. I also use GetCommandBars()->GetCommandBarsOptions()->bShowE xpandButtonAlways = FALSE; and like I said, my toolbars go flush against the right edge if I drag them over. |
|
Kenneth
Senior Member Joined: 23 May 2004 Location: United States Status: Offline Points: 256 |
Post Options
Thanks(0)
|
Maybe its my system. Would you try adding the line: GetCommandBars()->GetCommandBarsOptions()->bShow ExpandButtonAlways = FALSE; in the OnCreate function of the CommonControls sample and see if the animation, slider and static control aligns with the right border correct. |
|
Kenneth
Senior Member Joined: 23 May 2004 Location: United States Status: Offline Points: 256 |
Post Options
Thanks(0)
|
Fixed.
|
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |