首页 > 代码库 > WPF - 引用VS2013某.dll,打造VS2013窗口

WPF - 引用VS2013某.dll,打造VS2013窗口

本篇目的是利用VS2013的某几个.dll文件,在WPF下打造出VS2013的窗口,说白了吧,就是借微软的VS2013窗口^_^。

这几个.dll文件是Microsoft.VisualStudio.Shell.Interop.dll、Microsoft.VisualStudio.Shell.UI.Internal.dll、Microsoft.VisualStudio.Shell.ViewManager.dll可在

需要几款软件,ILSpy和XAML Spy(我是用这俩东西找到这几个.dll的,现在不需要了)

新建WPF项目

引用那三个.dll

MainWindow XAML文件如下(刚申请博客,啥都不会,很乱,见谅)

<microsoft:CustomChromeWindow x:Class="WpfApplication1.MainWindow"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        xmlns:microsoft="clr-namespace:Microsoft.VisualStudio.PlatformUI.Shell.Controls;assembly=Microsoft.VisualStudio.Shell.ViewManager"                     xmlns:microsoft1="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.UI.Internal"

        x:Name="mainwindow" CornerRadius="0"  ActiveGlowColor="Red" InactiveGlowColor="#017ACC"  NonClientFillColor="Blue"  Background="#FFD6DBE9"  Title="Temp">

    <microsoft:CustomChromeWindow.CommandBindings>

        <CommandBinding Command="microsoft:ViewCommands.MinimizeWindow" CanExecute="CommandBinding_CanExecute"  Executed="CommandBinding_Executed"/>

        <CommandBinding Command="microsoft:ViewCommands.ToggleMaximizeRestoreWindow" CanExecute="CommandBinding_CanExecute" Executed="CommandBinding_Executed_1"/>

        <CommandBinding Command="microsoft:ViewCommands.CloseWindow" CanExecute="CommandBinding_CanExecute" Executed="CommandBinding_Executed_2"/>

    </microsoft:CustomChromeWindow.CommandBindings>

    <microsoft:CustomChromeWindow.Content>

        <Grid>   

          <microsoft1:MainWindowTitleBar VerticalAlignment="Top" Background="Blue" Height="30">

                <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Top">

                    <StackPanel.Resources>

                        <Style TargetType="{x:Type microsoft:WindowTitleBarButton}">   

                          <Setter Property="GlyphForeground" Value="http://www.mamicode.com/#FF000000"/>  

                           <Setter Property="HoverBackground" Value="http://www.mamicode.com/#FFFFFCF4"/>

                            <Setter Property="HoverBorderBrush" Value="http://www.mamicode.com/#FFE5C365"/>

                            <Setter Property="HoverForeground" Value="http://www.mamicode.com/#FF000000"/>

                            <Setter Property="PressedBackground" Value="http://www.mamicode.com/#FFFFE8A6"/>

                            <Setter Property="PressedBorderBrush" Value="http://www.mamicode.com/#FFE5C365"/>

                            <Setter Property="PressedForeground" Value="http://www.mamicode.com/#FF000000"/>

                            <Setter Property="Width" Value="http://www.mamicode.com/34"/>

                            <Setter Property="Height" Value="http://www.mamicode.com/26"/>

                        </Style>  

                   </StackPanel.Resources>

                    <microsoft:WindowTitleBarButton Command="microsoft:ViewCommands.MinimizeWindow" CommandParameter="{Binding ElementName=mainwindow}"/>

                    <microsoft:WindowTitleBarButton Command="microsoft:ViewCommands.ToggleMaximizeRestoreWindow" CommandParameter="{Binding ElementName=mainwindow}"/>

                    <microsoft:WindowTitleBarButton Command="microsoft:ViewCommands.CloseWindow" CommandParameter="{Binding ElementName=mainwindow}"/>

                </StackPanel>

            </microsoft1:MainWindowTitleBar>

            <Button Content="Button" Width="75" Height="25" Click="Button_Click"/>

        </Grid>

    </microsoft:CustomChromeWindow.Content>

</microsoft:CustomChromeWindow>

 

后台隐藏代码:

 public partial class MainWindow : CustomChromeWindow

    {

        public MainWindow()

        {            

              InitializeComponent();

        }

        private static void SetDefaultRenderMode()

        {

            //IVsShell shell = GlobalServices.Shell;

            //object obj;

            //if (shell != null && ErrorHandler.Succeeded(shell.GetProperty(-9061, out obj)) && obj is int)

            //{

            //    int num = (int)obj;

            //    if ((num & 65536) == 0)

            //    {

            //        RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;

            //    }

            //}

        }        

       private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)

        {

            e.CanExecute = true;

        }

        private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)

        {

            Window _window = Window.GetWindow(this);

            SystemCommands.MinimizeWindow(_window);

        }

        private void CommandBinding_Executed_1(object sender, ExecutedRoutedEventArgs e)

        {

            if (this.WindowState == System.Windows.WindowState.Maximized)

            {

                Window _window = Window.GetWindow(this);

                SystemCommands.RestoreWindow(_window);

            }

            else

            {

                Window _window = Window.GetWindow(this);

                SystemCommands.MaximizeWindow(_window);

            }

        }

        private void CommandBinding_Executed_2(object sender, ExecutedRoutedEventArgs e)

        {

            Window _window = Window.GetWindow(this);

            SystemCommands.CloseWindow(_window);

        }

        private void Button_Click(object sender, RoutedEventArgs e)

        {

            //Microsoft.VisualStudio.PlatformUI.MainWindow m = new Microsoft.VisualStudio.PlatformUI.MainWindow();

            //m.ShowDialog();

        }

 }

这样就行了,运行就会出现VS2013的窗口框架,性能高,还好看。

这里有个问题:

当我把debug文件夹里那三个.dll删除之后,还能运行,还是VS2013的窗口,很是伤感,到底这个窗口是只依赖于这三个.dll呢,还是依赖于C:\Windows\Microsoft.NET\assembly\GAC_MSIL\....下的同名程序集呢,学的不深入,解释不了。所以说现在就是要找一台安装.net 4.5 但是没有安装VS和VS SDK的机器试试这个程序,看看到底怎么回事,若是能运行,就成功啦,不能运行的话。再接再厉

 

应届毕业生,虚心求教,拒绝恶言相讽

 

WPF - 引用VS2013某.dll,打造VS2013窗口