Print Page | Close Window

How to add menu item in OnInitCommandsPopup()

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Command Bars
Forum Description: Topics Related to Codejock Command Bars
URL: http://forum.codejock.com/forum_posts.asp?TID=6129
Printed Date: 16 June 2024 at 11:11pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: How to add menu item in OnInitCommandsPopup()
Posted By: MichaelN
Subject: How to add menu item in OnInitCommandsPopup()
Date 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



Replies:
Posted By: Oleg
Date Posted: 16 January 2007 at 6:26am

hi,

See Notfications sample and CXTPControls methods.


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: MichaelN
Date 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
 


Posted By: MichaelN
Date Posted: 16 January 2007 at 4:23pm
OK, I solved it.  Rather arcane, but it works.
 
Thanks,
 
Michael


Posted By: jjwalters
Date 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!!???


Posted By: MichaelN
Date Posted: 26 January 2007 at 8:44am
Solution sent From CodeJock Support:
 
Hello,
 
Call GetCommandBars()->GetActiveDocTemplate() method instead.


Posted By: MichaelN
Date 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;
      }
    }
  }
}


Posted By: jjwalters
Date 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.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net