使用visual studio 2013内置的消息框通过DTE对象



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

好的,我想我明白了。

组件:

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

在using语句中:

  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);
        }
    }

最新更新