.NET Forum / Visual Studio.NET / Extensibility / June 2004
Trouble with CTC files
|
|
Thread rating:  |
msnews.microsoft.com - 28 Jun 2004 22:40 GMT I am trying to customize my package's context menus from the defaults provided by VSIP. It seems that no matter what I do, when I call ShowContextMenu for my custom menus it always returns E_FAIL. I have included a very simple example below in hopes someone can point out what I'm missing. It creates a new context menu consisting of just the IDG_VS_CTXT_ITEM_OPEN group. I would expect this to display a context menu containing only the "Open" and "Open With..." options. Are other modifications necessary in order for the context menu to appear? Perhaps something in the RC file (other than the CTMENU stmnt) or something in the source? I've done countless comparisons with my code and the example VSIP projects and can see no differences in the implementation. I expect my problem is something very simple, but I've stared at this far too long to spot it myself. Is there documentation somewhere on the CTC file?
// Same guid as my package's guid. #define guidInstrumentPrj { 0xE59935A1, 0x6156, 0x11d1, { 0x87, 0xA6, 0x00, 0xA0, 0xC9, 0x1E, 0x2A, 0x46 } }
// Created specifically for the context menus. #define guidInstrumentCtx { 0x0a51838c, 0xceb0, 0x4d46, { 0x8c, 0x82, 0x94, 0xa6, 0xfd, 0x95, 0x4a, 0x65 } }
CMDS_SECTION guidInstrumentPrj MENUS_BEGIN guidInstrumentCtx:IDM_CTXT_DEFNODE, guidInstrumentCtx:0, 0x0000, CONTEXT, "Definition", "Definition"; MENUS_END
NEWGROUPS_BEGIN guidSHLMainMenu:IDG_VS_CTXT_ITEM_OPEN, guidInstrumentCtx:IDM_CTXT_DEFNODE, 0x0100; NEWGROUPS_END
BUTTONS_BEGIN BUTTONS_END CMDS_END
HRESULT CFileVwDefNode::DisplayContextMenu() { HRESULT hr = NOERROR;
CComPtr<IOleComponentUIManager> srpUIManager; hr = _VxModule.QueryService(SID_SOleComponentUIManager, IID_IOleComponentUIManager, (void **)&srpUIManager); ASSERT(srpUIManager != NULL);
if (srpUIManager != NULL) { POINT pnt; ::GetCursorPos(&pnt); POINTS pnts = { (SHORT)pnt.x, (SHORT)pnt.y };
hr = srpUIManager->ShowContextMenu(0, guidInstrumentPrj, IDM_CTXT_DEFNODE, pnts, NULL); }
return hr; }
Jack Peters - 29 Jun 2004 18:49 GMT If you want to define your own context menu it has to be defined first in the MENU_BEGIN MENU_END section. It has to be repeated like this.
> MENUS_BEGIN > guidInstrumentCtx:IDM_CTXT_DEFNODE, guidInstrumentCtx:IDM_CTXT_DEFNODE,
> 0x0000, CONTEXT, "Definition", "Definition"; > MENUS_END It also depends where you want your context menu to appear. Do you owe a window in which you want to display your context menu or do you want your context menu items to be added to an existing context menu that appears in a predefined window (such as editor)?
If you are in first case, define your Context menu as described above and attach groups to that menu and then menu items to your groups. Groups mainly separate menu items from each other.
If it is second case, you should find which context menu is called when right clicking on the window, then add your own group in the MENUGROUP section to the existing menu (they can be found in the include directory in one of ctc files and in .h related files). Then you should add your menu items to the menugroup that you have created.
In any case it is the other way around, your command group is in first position and then you have the menu and then the priority
> NEWGROUPS_BEGIN > guidInstrumentCtx:MyGroup, guidSHLMainMenu:IDG_VS_CTXT_ITEM_OPEN, 0x0100;
> NEWGROUPS_END The documentation is really misleading in that area
Then define your menu items in the BUTTONS section
> BUTTONS_BEGIN guidInstrumentCtx:MyCommand, guidInstrumentCtx:MyGroup, 0x1000, guidMyBitmap:MyBitmap, BUTTON, , "Description"
> BUTTONS_END Then you should also define your bitmaps in the BITMAP section (if you don't want bitmaps and just text, replace guidMyBitmap:MyBitmap with guidOfficeIcon:msotcidNoIcon)
BITMAPS_BEGIN guidMyBitmap:IDB_MY_IMAGES, MyBitmap, MyBitmap2, ....,MyBitmapX; BITMAPS_END
where MyBitmapX is the index of your icon in the IDB_MY_IMAGES image resource (16pixels height and Xx16pixels width). Indexes start at 1.
> I am trying to customize my package's context menus from the defaults > provided by VSIP. It seems that no matter what I do, when I call [quoted text clipped - 54 lines] > return hr; > } Jim Shaffer - 30 Jun 2004 14:50 GMT Thanks Jack for the response.
I tried as you suggested but had no success. Under the MENUS_BEGIN, it made no difference whether the PARENT GROUP was specified as guidInstrumentCtx:IDM_CTXT_DEFNODE or as guidInstrumentCtx:0. I noticed in the CTC files that are included with the VSIP examples that the parent group of CONTEXT menus seem to always use 0. Under the NEWGROUPS_BEGIN, swapping the order of the GROUPID and the PARENT MENU made no difference. In the example CTC files it seems pretty clear that the order is expected to be the menu group followed by the parent menu.
Do you think the problem might be in my C++ code and not in the CTC file? In my original post included the code that calls ShowContextMenu. Is there something wrong or missing with it? Is there documentation on the CTC file anywhere that would explain how to use it?
Thanks.
"Ed Dore [MSFT]" - 30 Jun 2004 16:49 GMT Hi Jim,
I had some problems myself attempting to implement a context menu on a simple toolwindow package. The problem was I deferred to the documentation when I probably should have modeled my .CTC file after one of the sample projects. The documentation indicates that you can directly assign the buttons to a specific menu, but I was never able to actually make that work.
To get this working, you'll need to assign them to a group, and then assign the group to the menu. And contrary to the documentation, you do not need to add the group to the CMDPLACEMENT_SECTION of the .CTC. When I did this, the commands were duplicated in the context menu.
My CTC file looked something like the following:
// Package Command Bar Definition //
#include "stdidcmd.h" #include "vsshlids.h" #include "msobtnid.h" #include "virtkeys.h" #include "PkgCmdID.h" #include "Resource.h"
#define _CTC_GUIDS_ #include "Guids.h"
// shorthand macros for a more compact and manageable table
#define OI_NOID guidOfficeIcon:msotcidNoIcon #define DIS_DEF DEFAULTDISABLED | DEFAULTINVISIBLE | DYNAMICVISIBILITY #define VIS_DEF COMMANDWELLONLY
CMDS_SECTION guidSimpSharpToolPkg
MENUS_BEGIN // NewMenu Relative to Group Priority Type Name Text guidSimpSharpCtxMenu:SimpSharpCtxMenu, guidSimpSharpCtxMenu:0, 0x0000, CONTEXT, "SimpSharp Context Menu", "SimpSharpContext";
MENUS_END
NEWGROUPS_BEGIN // NewGroup Parent Group Priority guidSimpSharpToolCmdSet:MyMenuGroup, guidSHLMainMenu:IDM_VS_MENU_TOOLS, 0x0600;
guidSimpSharpCtxMenu:CtxMenuCommands, guidSimpSharpCtxMenu:SimpSharpCtxMenu, 0x0100;
NEWGROUPS_END
BUTTONS_BEGIN // Command Parent Group Priority Image Type Flags Text guidSimpSharpCtxMenu:cmdidCtxMenu1, guidSimpSharpCtxMenu:CtxMenuCommands, 0x100, OI_NOID, BUTTON, , "Menu Item &1" ; guidSimpSharpCtxMenu:cmdidCtxMenu2, guidSimpSharpCtxMenu:CtxMenuCommands, 0x101, OI_NOID, BUTTON, , "Menu Item &2" ; guidSimpSharpCtxMenu:cmdidCtxMenu3, guidSimpSharpCtxMenu:CtxMenuCommands, 0x102, OI_NOID, BUTTON, , "Menu Item &3" ; guidSimpSharpCtxMenu:cmdidCtxMenu4, guidSimpSharpCtxMenu:CtxMenuCommands, 0x103, OI_NOID, BUTTON, , "Menu Item &4" ; guidSimpSharpCtxMenu:cmdidCtxMenu5, guidSimpSharpCtxMenu:CtxMenuCommands, 0x104, OI_NOID, BUTTON, , "Menu Item &5" ;
guidSimpSharpToolCmdSet:cmdidCSharpToolWindow, guidSHLMainMenu:IDG_VS_WNDO_OTRWNDWS1, 0x0100, guidSimpSharpToolCmdSet:bmpPic2, BUTTON, , "My CSharp Tool Window";
BUTTONS_END
BITMAPS_BEGIN // Bitmap Bitmap Index, Bitmap Index, ... guidSimpSharpToolCmdSet:IDB_MENU_IMAGES, bmpPic1, bmpPic2, bmpPicSmile, bmpPicX, bmpPicArrows; BITMAPS_END
CMDS_END
CMDUSED_SECTION CMDUSED_END
CMDPLACEMENT_SECTION // Command Group Priority CMDPLACEMENT_END
VISIBILITY_SECTION // Command GUID when visible VISIBILITY_END
KEYBINDINGS_SECTION // Command when available emulation keystate KEYBINDINGS_END
And the code to invoke display the menu from my WM_MOUSEUP handler is below:
private void MyToolWindow_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { if (e.Button == MouseButtons.Right) { ServiceProvider sp = new ServiceProvider(vsServiceProvider); IVsUIShell pUIShell = (IVsUIShell) sp.GetService(typeof(IVsUIShell)); POINTS[] pts = new POINTS[1]; Point pt = Control.MousePosition; pts[0].x = (short)pt.X; pts[0].y = (short)pt.Y; Guid tmpGuid = GuidList.guidSimpSharpCtxMenu; pUIShell.ShowContextMenu(0, ref tmpGuid, (int)MenuGroups.SimpSharpCtxMenu, pts, this); } }
Also, you ned to handle the IOleCommandTarget.QueryStatus for the various commands, setting the OLECMDF argument to OLECMDF_SUPPORTED| OLECMDF_ENABLED.
Jim, if you're still having problems, feel free to ping me via email. Just remove the "online." from the address listed on the from line. I'd be more than happy to send you the whole C# VSIP project.
Sincerely, Ed Dore [MSFT]
This post is 'AS IS' with no warranties, and confers no rights.
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|