Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Command Bars
  New Posts New Posts RSS Feed - How to add menu item in OnInitCommandsPopup()
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

How to add menu item in OnInitCommandsPopup()

 Post Reply Post Reply
Author
Message
MichaelN View Drop Down
Senior Member
Senior Member


Joined: 19 September 2006
Status: Offline
Points: 112
Post Options Post Options   Thanks (0) Thanks(0)   Quote MichaelN Quote  Post ReplyReply Direct Link To This Post Topic: How to add menu item in OnInitCommandsPopup()
    Posted: 15 January 2007 at 4:47pm
I want to add specific menu items to a menu at run time, so I am handling OnInitCommandsPopup() in place of the MFC OnInitmenupopup(). I don;t see hpow this can be done. There's a Remove method but no Add method that I can see doing the job.
 
I've looked in the source and samples and I just cannot find an example or docs on this anywhere.
 
Michael
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: 16 January 2007 at 6:26am

hi,

See Notfications sample and CXTPControls methods.
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
MichaelN View Drop Down
Senior Member
Senior Member


Joined: 19 September 2006
Status: Offline
Points: 112
Post Options Post Options   Thanks (0) Thanks(0)   Quote MichaelN Quote  Post ReplyReply Direct Link To This Post Posted: 16 January 2007 at 10:06am
Oleg,
 
Of course, the first place I looked for the answer was in the Notifications example. It does not show how to ADD a menu item. It shows how to remove and rename menu items. I wasnt to add *new* items with name and message ID to be determined.
 
Thanks,
 
Michael
 
Back to Top
MichaelN View Drop Down
Senior Member
Senior Member


Joined: 19 September 2006
Status: Offline
Points: 112
Post Options Post Options   Thanks (0) Thanks(0)   Quote MichaelN Quote  Post ReplyReply Direct Link To This Post Posted: 16 January 2007 at 4:23pm
OK, I solved it.  Rather arcane, but it works.
 
Thanks,
 
Michael
Back to Top
jjwalters View Drop Down
Newbie
Newbie
Avatar

Joined: 26 January 2007
Location: United Kingdom
Status: Offline
Points: 3
Post Options Post Options   Thanks (0) Thanks(0)   Quote jjwalters Quote  Post ReplyReply Direct Link To This Post Posted: 26 January 2007 at 7:57am
Hi Mike
I'd love to know how you added a menu item - no matter how inappropriate.  CodeJock's docs are rather useless, and the Admin's comments above are unhelpful and unprofessional.......and we're paying a licence fee!!???
Back to Top
MichaelN View Drop Down
Senior Member
Senior Member


Joined: 19 September 2006
Status: Offline
Points: 112
Post Options Post Options   Thanks (0) Thanks(0)   Quote MichaelN Quote  Post ReplyReply Direct Link To This Post Posted: 26 January 2007 at 8:44am
Solution sent From CodeJock Support:
 
Hello,
 
Call GetCommandBars()->GetActiveDocTemplate() method instead.
Back to Top
MichaelN View Drop Down
Senior Member
Senior Member


Joined: 19 September 2006
Status: Offline
Points: 112
Post Options Post Options   Thanks (0) Thanks(0)   Quote MichaelN Quote  Post ReplyReply Direct Link To This Post Posted: 26 January 2007 at 9:48am
Dear JJ,
 
Below, is the solution that I had cooked up before Oleg showed me the simpler solution. This is a standard technique I've used before to access protected members. And you are right: The Codejock code is great but the docs really could use some improvement for showing a developer how to implement it.
 
Michael
 
--------------------
 
#include "C:\Program Files\Codejock Software\MFC\Xtreme ToolkitPro v10.3.1\Source\CommandBars\XTPCommandBar.h"
 
class CXTPCommandBarSpoof : public CXTPCommandBar 
{
public:
  CXTPCommandBarSpoof( CXTPCommandBar* pOldCommandBar );
  virtual ~CXTPCommandBarSpoof();
public:
  UINT GetDocTemplate();
};
 
// use Copy constructor to load class info
CXTPCommandBarSpoof::CXTPCommandBarSpoof( CXTPCommandBar* pOldCommandBar )
{
  Copy( pOldCommandBar );
}
CXTPCommandBarSpoof::~CXTPCommandBarSpoof() {}
 
// return the protected data as public
UINT CXTPCommandBarSpoof::GetDocTemplate() { return GetActiveDocTemplate(); }
 
// implement spoof class in CMainFrame popup handler
void CMainFrame::OnInitCommandsPopup(CXTPPopupBar* pCommandBar)
{
  if ( ! sPopup.CompareNoCase(_T("PopupName")) ) // caption of popup menu to change
  {
    CXTPControls* pCommandList = pCommandBar->GetControls();
    if ( pCommandList )
    {
      CXTPCommandBarSpoof CB( pCommandBar ); // spoof class to get the DocTemplate
      switch( CB.GetDocTemplate() )
      {
      case IDR_MYDOC_TYPE: // ID of document template that owns popup
        // change menu items here
        break;
      }
    }
  }
}
Back to Top
jjwalters View Drop Down
Newbie
Newbie
Avatar

Joined: 26 January 2007
Location: United Kingdom
Status: Offline
Points: 3
Post Options Post Options   Thanks (0) Thanks(0)   Quote jjwalters Quote  Post ReplyReply Direct Link To This Post Posted: 26 January 2007 at 10:58am
I ended up looking at their DynamicPopups example, and this does exactly what I want.
It is a real shame that there are no docs to explain all this, or at least to advise on which sample to look at.
Thanks for your time Mike.
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.156 seconds.