Context menu - How?
Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=743
Printed Date: 25 December 2024 at 7:52am Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com
Topic: Context menu - How?
Posted By: Alistair
Subject: Context menu - How?
Date 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:
CWnd *pwndMain = AfxGetMainWnd() ;
CMenu *pmenu = pwndMain->GetMenu() ;
CMenu *pmenuPopup = pMenu->GetSubMenu(uiSubMenu) ;
pmenuPopup->TrackPopupMenu ( TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, this ) ;
|
--- Al.
|
Replies:
Posted By: Alistair
Date Posted: 17 May 2004 at 5:51am
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.
|
Posted By: Ark42
Date Posted: 19 May 2004 at 10:31pm
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.
|
Posted By: Alistair
Date Posted: 20 May 2004 at 8:56am
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):
CXTPControl *pCtrl ;
UINT ctrlIndex = 0 ;
while ( (pCtrl = pMenuBar->GetCtrl(ctrlIndex++)) )
{
pCtrl->SetEnabled ( MyCheckFunc(pCtrl->GetId) ) ;
}
|
where MyCheckFunc() returns whether the given resource Id should be enabled or not.
Would this work and is it a reasonable solution?
--- Al.
|
Posted By: Ark42
Date Posted: 20 May 2004 at 12:07pm
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.
|
Posted By: Kenneth
Date Posted: 23 June 2004 at 2:30pm
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!
|
Posted By: Oleg
Date Posted: 24 June 2004 at 5:04am
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
|
Posted By: Kenneth
Date Posted: 24 June 2004 at 9:01am
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?
|
Posted By: Ark42
Date Posted: 24 June 2004 at 1:15pm
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
|
Posted By: Kenneth
Date Posted: 24 June 2004 at 11:38pm
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?
|
Posted By: Ark42
Date Posted: 24 June 2004 at 11:46pm
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.
|
Posted By: Kenneth
Date Posted: 25 June 2004 at 12:18am
Is there any examples on how to do this correctly in the toolkit examples?
|
Posted By: Ark42
Date Posted: 25 June 2004 at 12:46am
I think I posted my exact code already, the 3rd post in this topic.
|
Posted By: Kenneth
Date Posted: 25 June 2004 at 12:58am
Yes, I know, but it requires the use of the "designer" editor sample. Is this this only way to do it?
|
Posted By: Ark42
Date Posted: 25 June 2004 at 1:00am
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.
|
Posted By: Kenneth
Date Posted: 25 June 2004 at 1:08am
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) { if(point.x < 0 || point.y < 0 ) { point.x = 0; point.y = 0; ClientToScreen(&point); } CMenu myMenu; myMenu.LoadMenu(IDR_NTPOPUP); CMenu* myPopup = myMenu.GetSubMenu(0); CXTPCommandBars::TrackPopupMenu(myPopup,TPM_LEFTALIGN| TPM_RIGHTBUTTON,point.x,point.y,this); }
|
Posted By: Ark42
Date Posted: 25 June 2004 at 1:17am
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.
|
Posted By: Kenneth
Date Posted: 25 June 2004 at 1:38am
I don't believe its a focus problem. If I use:
void CSecureNetTermView::OnContextMenu(CWnd* pWnd,CPoint point) { if(point.x < 0 || point.y < 0 ) { point.x = 0; point.y = 0; ClientToScreen(&point); } CMenu myMenu; myMenu.LoadMenu(IDR_NTPOPUP); CMenu* myPopup = myMenu.GetSubMenu(0); myPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON,point.x,point.y,AfxGetMainWnd(),NULL); }
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!
|
Posted By: Ark42
Date Posted: 25 June 2004 at 1:41am
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?
|
Posted By: Kenneth
Date Posted: 25 June 2004 at 1:55am
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.
|
Posted By: Ark42
Date Posted: 25 June 2004 at 2:07am
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.
|
Posted By: Kenneth
Date Posted: 25 June 2004 at 9:40am
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.
|
Posted By: Kenneth
Date Posted: 25 June 2004 at 10:03am
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?
|
Posted By: Kenneth
Date Posted: 25 June 2004 at 11:28am
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.
|
Posted By: Ark42
Date Posted: 25 June 2004 at 1:05pm
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.
|
Posted By: Kenneth
Date Posted: 25 June 2004 at 1:30pm
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.
|
Posted By: Kenneth
Date Posted: 29 June 2004 at 9:21pm
|