Visual Studio. VS Style ToolWindow, . VS ToolWindow TreeView, . ++ CLI, , , # VB.Net.
- - > - > - > - > - > VS
- :
public ref class Connect : public IDTExtensibility2, public IDTCommandTarget
{
public:
...
private:
literal String^ VSToolWinGuid = "{6CCD0EE9-20DB-4636-9149-665A958D8A9A}";
DTE2^ appObject;
AddIn^ addInInstance;
Window^ MainWindow;
TreeView^ FormTreeView;
CommandBarButton^ StdCommandBarButton;
void InitializeToolBarButton();
void ShowAddInWindow();
...
};
void Connect::OnConnection(...)
{
appObject = dynamic_cast<DTE2^>(Application);
addInInstance = dynamic_cast<AddIn^>(AddInInst);
if (ext_ConnectMode::ext_cm_UISetup==ConnectMode)
InitializeToolBarButton();
}
void Connect::Exec(...)
{
handled = false;
if (vsCommandExecOption::vsCommandExecOptionDoDefault == ExecuteOption)
{
if (!CmdName->CompareTo("FormBrowserAddIn.Connect.FormBrowser"))
{
ShowAddInWindow();
handled = true;
return;
}
}
}
void Connect::InitializeToolBarButton()
{
try
{
Command^ command = nullptr;
try
{
command = appObject->Commands->Item(addInInstance->ProgID + "." + AddInName, -1);
}
catch(Exception^){}
if (nullptr == command)
{
EnvDTE80::Commands2^ commands2 = safe_cast<EnvDTE80::Commands2^>(appObject->Commands);
Array^ contextGUIDs = Array::CreateInstance(Object::typeid, 0);
command = commands2->AddNamedCommand2(addInInstance,
AddInName, AddInCaption, AddInToolTip, true, 59, contextGUIDs,
(int)(vsCommandStatus::vsCommandStatusSupported | vsCommandStatus::vsCommandStatusEnabled),
(int)vsCommandStyle::vsCommandStylePict, vsCommandControlType::vsCommandControlTypeButton);
}
VisualStudio::CommandBars::CommandBars^ commandBars;
commandBars = (VisualStudio::CommandBars::CommandBars^)appObject->CommandBars;
CommandBar^ stdCommandBar = commandBars["Standard"];
StdCommandBarButton = (CommandBarButton^)command->AddControl(stdCommandBar, stdCommandBar->Controls->Count+1);
}
catch(Exception^ e)
{
MessageBox::Show(e->ToString());
}
}
void Connect::ShowAddInWindow()
{
try
{
if (nullptr == MainWindow)
{
String^ TreeViewFullName = "System.Windows.Forms.TreeView";
String^ assembly = Reflection::Assembly::GetAssembly(System::Windows::Forms::TreeView::typeid)->Location;
Object^ UserCtrlObject = nullptr;
EnvDTE80::Windows2^ win = (EnvDTE80::Windows2^)appObject->Windows;
MainWindow = win->CreateToolWindow2(addInInstance, assembly, TreeViewFullName, AddInCaption, VSToolWindowGuid, UserCtrlObject);
FormTreeView = (TreeView^)UserCtrlObject;
}
RefreshTreeView();
MainWindow->Visible = true;
}
catch (Exception^ e)
{
MessageBox::Show(e->ToString());
}
}
, , .
MZTools.
source
share