![]() |
How to add menu item in OnInitCommandsPopup() |
Post Reply ![]() |
Author | |
MichaelN ![]() Senior Member ![]() Joined: 19 September 2006 Status: Offline Points: 112 |
![]() ![]() ![]() ![]() ![]() 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
|
|
![]() |
|
Oleg ![]() Admin Group ![]() Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
![]() ![]() ![]() ![]() ![]() |
hi, See Notfications sample and CXTPControls methods.
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
![]() |
|
MichaelN ![]() Senior Member ![]() Joined: 19 September 2006 Status: Offline Points: 112 |
![]() ![]() ![]() ![]() ![]() |
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
|
|
![]() |
|
MichaelN ![]() Senior Member ![]() Joined: 19 September 2006 Status: Offline Points: 112 |
![]() ![]() ![]() ![]() ![]() |
OK, I solved it. Rather arcane, but it works.
Thanks,
Michael
|
|
![]() |
|
jjwalters ![]() Newbie ![]() ![]() Joined: 26 January 2007 Location: United Kingdom Status: Offline Points: 3 |
![]() ![]() ![]() ![]() ![]() |
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!!???
|
|
![]() |
|
MichaelN ![]() Senior Member ![]() Joined: 19 September 2006 Status: Offline Points: 112 |
![]() ![]() ![]() ![]() ![]() |
Solution sent From CodeJock Support:
Hello,
Call GetCommandBars()->GetActiveDocTemplate() method instead. |
|
![]() |
|
MichaelN ![]() Senior Member ![]() Joined: 19 September 2006 Status: Offline Points: 112 |
![]() ![]() ![]() ![]() ![]() |
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; } } } } |
|
![]() |
|
jjwalters ![]() Newbie ![]() ![]() Joined: 26 January 2007 Location: United Kingdom Status: Offline Points: 3 |
![]() ![]() ![]() ![]() ![]() |
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.
|
|
![]() |
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 |