使用Visual Studio 2013内置的消息框通过DTE对象

时间:2015-07-22 08:53:47

标签: visual-studio

我正在开发visual studio项目模板。
在模板安装期间,我执行了一些我想让用户知道的长操作。
我已经看过DTE状态栏进度方法,但我更喜欢在Visual Studio内置的消息框中输出消息。
有可能吗?

1 个答案:

答案 0 :(得分:0)

好的,我想我明白了。

集会:

 Microsoft.VisualStudio.OLE.Interop
 Microsoft.VisualStudio.Shell.12.0
 Microsoft.VisualStudio.Shell.Interop.10.0

在使用声明中:

  using IOleServiceProvider = Microsoft.VisualStudio.OLE.Interop.IServiceProvider;

代码:

 private IVsThreadedWaitDialog2 _progressDialog = null;

 private void StartProgressDialog(string operation, string statusBarText, int total)
    {
        if (_progressDialog == null)
        {
            IOleServiceProvider oleServiceProvider = _dte as IOleServiceProvider;
            IVsThreadedWaitDialogFactory dialogFactory = new ServiceProvider(oleServiceProvider).GetService(
                        typeof(SVsThreadedWaitDialogFactory)) as IVsThreadedWaitDialogFactory;
            IVsThreadedWaitDialog2 dialog = null;
            if (dialogFactory != null)
            {
                dialogFactory.CreateInstance(out dialog);
                _progressDialog = dialog;
            }
        }

        if(_progressDialog != null)
        {
            _progressDialog.StartWaitDialogWithPercentageProgress("Wait Dialogue", operation, null, null, statusBarText, false, 0, total, 0);
        }
    }

    private void TerminatePreogressDialog()
    {
        if (_progressDialog != null)
        {
            int canceled;
            _progressDialog.EndWaitDialog(out canceled);
        }
    }

    private void UpdateLongOperationMessage(string operation, string progressMessage, int step, int total)
    {
        if (_progressDialog != null)
        {
            bool canceled;
            _progressDialog.UpdateProgress(operation, progressMessage, progressMessage, step, total, true, out canceled);
        }
    }