| By Aaron Brethorst | Article Rating: |
|
| June 29, 2005 04:00 PM EDT | Reads: |
50,640 |
The Visual Studio Command model is rich and powerful enough that you can create a set of commands and then add then to virtually any exposed Menu structure, whether that happens to be in the main Menu Bar, a toolbar in the IDE, or a toolbar located on a specific tool window. We use Command Table Compiler (CTC) files to control this interaction.
To get started, open PkgCmd.ctc. Look for the section marked "CMDS_SECTION." This is where we'll add new Commands to Visual Studio for use in our Package. For our purposes, there are three pieces of data that we'll have to specify right now: a new Menu, a new Menu Group, and a new Button. The relevant portions of PkgCmd.ctc are reproduced in Listing 2.
CTC Menu Section
- Menu uniquely identifies our new menu. This is the same data we'll feed to our Tool Window's Toolbar property later on.
- Relative to Group specifies what group this menu will be placed on. For example, if you wanted to create a submenu on an existing menu, you'd place the existing menu's identifier here. To see this in concrete terms look at how the Tasklist Sample command is added to the View menu.
- Priority is quite important. You should only use the top two numbers when defining the priority for a command, group, or menu. This is required by the shell to deal with the merging of items. This parameter determines where the item is to be placed in the group specified in parameter 2, 0x0000 being the highest, and 0xFF00 being the lowest.
- Menu Type specifies what type of menu you're creating. This is how you specify whether you're creating context menus, tool bars, and so forth.
- Text is the textual name of the menu if it were to appear as an item somewhere, either in the Tools.Customize dialog or on the menu itself.
- New Group defines the group you want to create. This allows you to place logically related commands together. For example: Cut, Copy, and Paste commands would all be placed in a group together.
- Parent Group defines the parent menu the group will be placed on.
- Priority defines the priority of the group in the specified parent menu.
- Command uniquely identifies the new command you're creating.
- Parent Group species the Primary group that this command belongs to. Every command MUST belong to a primary group. This is necessary for both Keyboard and Toolbar Customization modes. The command will show up in its primary location when the end user looks in either one of these dialogs.
- Priority defines the priority of the command in the specified group.
- Image defines the picture associated with this command. If you don't want an image associated with this button, pass in the value guidOfficeIcon:msotcidNoIcon.
- Button Type determines the type of button we're defining here. This could be BUTTON or SPLITDROPDOWN, for example.
- Visibility specifies how the command is shown or hidden. Leaving this blank means the command will always be visible and enabled.
- Text is the text that will show up as the button text itself, or as the button's tool tip.
We'll start by adding these to the Native project. Open PkgCmd-ID.h and add the following #defines:
#define ToolbarMenu 0x1000
#define ToolbarMenuGroup 0x1100
#define cmdidAddTask 0x110
Next, we need to add these values to the Managed project. Open PkgCmdID.cs and add the following values:
public const int cmdidAddTask = 0x110;
public const int ToolbarMenu = 0x1000;
public const int ToolbarMenuGroup = 0x1100;
Last, but certainly not least, we need to tell our tool window about the new Toolbar we have created. Open TasklistToolwindow.cs and add the following code to the constructor:
this.ToolBar = new System.ComponentModel.Design.CommandID(
GuidList.guidTasklist_SampleCmdSet,
PkgCmdIDList.ToolbarMenu);
Detailed Task Entry UI
Now that we have a functional Toolbar with a button in our tool window, let's make it do something useful. What we're going to do is add a Windows Form to our Package that will be displayed upon clicking the Add Task button in our tool bar.
First, add a new Windows Form named AddTaskDialog.cs to your C# project (see Figure 10).
Add a label with the Text property "&Description:" and make sure you get the ampersand added. The ampersand will give the label a mnemonic, which allows your users to select the next control in the tab order by pressing Alt+D, in this case. Now, add a multiline TextBox named txtDescription.
Drag another label onto the Form and name it "&Priority:" which results in a mnemonic invokable through the key combination Alt+P. Next, add a combo box named cmbPriority with the following Items:
- High
- Medium
- Low
Published June 29, 2005 Reads 50,640
Copyright © 2005 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Aaron Brethorst
Aaron Brethorst is a program manager on the Visual Studio Core team, where he is responsible for Accessibility and User Experience across the Visual Studio IDE. Aaron joined Microsoft in 2003 after graduating from the University of Minnesota with a degree in Computer Science. When he's not developing software, you can usually find him in a Seattle coffee shop with a good book.
- Kindle 2 vs Nook
- Confessions of a Ulitzer Addict
- IBM Hardware Chief, Intel VC Exec Arrested in Insider Trading Scam
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- Infrastructure-as-a-Service Will Mature in 2010: Microsoft's David Chou
- Windows 7 – Microsoft’s First Step to the Cloud
- Cloud Expo and the End of Tech Recession
- Jill Tummler Singer, Deputy CIO of CIA, Keynotes at GovIT Expo
- Reality Check at the Cloud Computing Expo
- Visual Studio 2010 Is Cloud Friendly
- Fired SCO CEO Fires Back
- Kindle 2 vs Nook
- The Difference Between Web Hosting and Cloud Computing
- Ajax in RichFaces 3.3, JSF 2 and RichFaces 4
- Confessions of a Ulitzer Addict
- Wave on Ulitzer: Confessions of a Google Wave Fanboy
- IBM Hardware Chief, Intel VC Exec Arrested in Insider Trading Scam
- Cloud Computing Best Practices
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- Infrastructure-as-a-Service Will Mature in 2010: Microsoft's David Chou
- Eval JavaScript in a Global Context
- Windows 7 – Microsoft’s First Step to the Cloud
- Google Maps and ASP.NET
- Crystal Reports XI & How It Has Changed
- Converting VB6 to VB.NET, Part I
- Creating Controls for.NET Compact Framework in Visual Studio 2005
- Where Are RIA Technologies Headed in 2008?
- How to Write High-Performance C# Code
- AJAX World RIA Conference & Expo Kicks Off in New York City
- Implementing Tab Navigation with ASP.NET 2.0
- i-Technology Photo Exclusive: Bill Gates & Steve Jobs In "Nerds"
- .NET Archives: Getting Reacquainted with the Father of C#
- i-Technology Viewpoint: "SOA Sucks"
- Programmatically Posting Data to ASP .NET Web Applications



























