Gaston Milano's WebLog

About something...

Sponsors

News

General

Usability

VS Automation

VSIP

VSIP Extras: How to change the menu text for a command

Sometimes is necessary to change the text for a menu item depending on the selection.  In order to do that you have to do 2 things:

1) If it is a command defined in your package you have to set the flag TEXTCHANGES in the ctc file. For example

guidProjectCmdSet:mycmdCompile , guidProjectCmdSet:MyMenuGroup, 0x0100, guidProjectCmdSet:bmpPic1, BUTTON, TEXTCHANGES , "&Compile";

2) You have to return the text in the querystatus method of your IOleCommandTarget implementation

Then you should do something like this:

....

case mycmdCompile:

{

                  string s = "Hello, I have changed this text";

                 OLECMDTEXT cmdText = (OLECMDTEXT) Marshal.PtrToStructure(pCmdText, typeof(OLECMDTEXT));

                 if (cmdText.cmdtextf == 1 /* OLECMDTEXTF_NAME */ )

               {

                     NativeMethods.OLECMDTEXT.SetText(pCmdText, s);

                }

....

}
Posted: May 21 2004, 10:06 AM by GMilano | with no comments
Filed under:

Comments

No Comments

Leave a Comment

(required) 

(required) 

(optional)

(required)