Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - Context menu - How?
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Context menu - How?

 Post Reply Post Reply
Author
Message
Alistair View Drop Down
Newbie
Newbie
Avatar

Joined: 14 May 2004
Status: Offline
Points: 15
Post Options Post Options   Thanks (0) Thanks(0)   Quote Alistair Quote  Post ReplyReply Direct Link To This Post Topic: Context menu - How?
    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.

Back to Top
Alistair View Drop Down
Newbie
Newbie
Avatar

Joined: 14 May 2004
Status: Offline
Points: 15
Post Options Post Options   Thanks (0) Thanks(0)   Quote Alistair Quote  Post ReplyReply Direct Link To This Post 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.

 

Back to Top
Ark42 View Drop Down
Senior Member
Senior Member
Avatar

Joined: 20 October 2003
Status: Offline
Points: 291
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ark42 Quote  Post ReplyReply Direct Link To This Post 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.


Back to Top
Alistair View Drop Down
Newbie
Newbie
Avatar

Joined: 14 May 2004
Status: Offline
Points: 15
Post Options Post Options   Thanks (0) Thanks(0)   Quote Alistair Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
Ark42 View Drop Down
Senior Member
Senior Member
Avatar

Joined: 20 October 2003
Status: Offline
Points: 291
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ark42 Quote  Post ReplyReply Direct Link To This Post 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.

Back to Top
Kenneth View Drop Down
Senior Member
Senior Member
Avatar

Joined: 23 May 2004
Location: United States
Status: Offline
Points: 256
Post Options Post Options   Thanks (0) Thanks(0)   Quote Kenneth Quote  Post ReplyReply Direct Link To This Post 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!

Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Kenneth View Drop Down
Senior Member
Senior Member
Avatar

Joined: 23 May 2004
Location: United States
Status: Offline
Points: 256
Post Options Post Options   Thanks (0) Thanks(0)   Quote Kenneth Quote  Post ReplyReply Direct Link To This Post 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?
Back to Top
Ark42 View Drop Down
Senior Member
Senior Member
Avatar

Joined: 20 October 2003
Status: Offline
Points: 291
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ark42 Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
Kenneth View Drop Down
Senior Member
Senior Member
Avatar

Joined: 23 May 2004
Location: United States
Status: Offline
Points: 256
Post Options Post Options   Thanks (0) Thanks(0)   Quote Kenneth Quote  Post ReplyReply Direct Link To This Post 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?
Back to Top
Ark42 View Drop Down
Senior Member
Senior Member
Avatar

Joined: 20 October 2003
Status: Offline
Points: 291
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ark42 Quote  Post ReplyReply Direct Link To This Post 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.

Back to Top
Kenneth View Drop Down
Senior Member
Senior Member
Avatar

Joined: 23 May 2004
Location: United States
Status: Offline
Points: 256
Post Options Post Options   Thanks (0) Thanks(0)   Quote Kenneth Quote  Post ReplyReply Direct Link To This Post Posted: 25 June 2004 at 12:18am

Is there any examples on how to do this correctly in the toolkit examples?

Back to Top
Ark42 View Drop Down
Senior Member
Senior Member
Avatar

Joined: 20 October 2003
Status: Offline
Points: 291
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ark42 Quote  Post ReplyReply Direct Link To This Post Posted: 25 June 2004 at 12:46am

I think I posted my exact code already, the 3rd post in this topic.

Back to Top
Kenneth View Drop Down
Senior Member
Senior Member
Avatar

Joined: 23 May 2004
Location: United States
Status: Offline
Points: 256
Post Options Post Options   Thanks (0) Thanks(0)   Quote Kenneth Quote  Post ReplyReply Direct Link To This Post 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? 
Back to Top
Ark42 View Drop Down
Senior Member
Senior Member
Avatar

Joined: 20 October 2003
Status: Offline
Points: 291
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ark42 Quote  Post ReplyReply Direct Link To This Post 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.

Back to Top
Kenneth View Drop Down
Senior Member
Senior Member
Avatar

Joined: 23 May 2004
Location: United States
Status: Offline
Points: 256
Post Options Post Options   Thanks (0) Thanks(0)   Quote Kenneth Quote  Post ReplyReply Direct Link To This Post 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);
 }

 

Back to Top
Ark42 View Drop Down
Senior Member
Senior Member
Avatar

Joined: 20 October 2003
Status: Offline
Points: 291
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ark42 Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
Kenneth View Drop Down
Senior Member
Senior Member
Avatar

Joined: 23 May 2004
Location: United States
Status: Offline
Points: 256
Post Options Post Options   Thanks (0) Thanks(0)   Quote Kenneth Quote  Post ReplyReply Direct Link To This Post 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!

 

 

 

Back to Top
Ark42 View Drop Down
Senior Member
Senior Member
Avatar

Joined: 20 October 2003
Status: Offline
Points: 291
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ark42 Quote  Post ReplyReply Direct Link To This Post 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?

Back to Top
Kenneth View Drop Down
Senior Member
Senior Member
Avatar

Joined: 23 May 2004
Location: United States
Status: Offline
Points: 256
Post Options Post Options   Thanks (0) Thanks(0)   Quote Kenneth Quote  Post ReplyReply Direct Link To This Post 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.

 

Back to Top
Ark42 View Drop Down
Senior Member
Senior Member
Avatar

Joined: 20 October 2003
Status: Offline
Points: 291
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ark42 Quote  Post ReplyReply Direct Link To This Post 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.

Back to Top
Kenneth View Drop Down
Senior Member
Senior Member
Avatar

Joined: 23 May 2004
Location: United States
Status: Offline
Points: 256
Post Options Post Options   Thanks (0) Thanks(0)   Quote Kenneth Quote  Post ReplyReply Direct Link To This Post 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.

 

Back to Top
Kenneth View Drop Down
Senior Member
Senior Member
Avatar

Joined: 23 May 2004
Location: United States
Status: Offline
Points: 256
Post Options Post Options   Thanks (0) Thanks(0)   Quote Kenneth Quote  Post ReplyReply Direct Link To This Post 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?

Back to Top
Kenneth View Drop Down
Senior Member
Senior Member
Avatar

Joined: 23 May 2004
Location: United States
Status: Offline
Points: 256
Post Options Post Options   Thanks (0) Thanks(0)   Quote Kenneth Quote  Post ReplyReply Direct Link To This Post 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.

 

Back to Top
Ark42 View Drop Down
Senior Member
Senior Member
Avatar

Joined: 20 October 2003
Status: Offline
Points: 291
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ark42 Quote  Post ReplyReply Direct Link To This Post 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.

Back to Top
Kenneth View Drop Down
Senior Member
Senior Member
Avatar

Joined: 23 May 2004
Location: United States
Status: Offline
Points: 256
Post Options Post Options   Thanks (0) Thanks(0)   Quote Kenneth Quote  Post ReplyReply Direct Link To This Post 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.

Back to Top
Kenneth View Drop Down
Senior Member
Senior Member
Avatar

Joined: 23 May 2004
Location: United States
Status: Offline
Points: 256
Post Options Post Options   Thanks (0) Thanks(0)   Quote Kenneth Quote  Post ReplyReply Direct Link To This Post Posted: 29 June 2004 at 9:21pm
Fixed.
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.125 seconds.