如何在C#中使用IOperationsProgressDialog

时间:2016-06-24 13:42:02

标签: c# com

我正在尝试在Windows窗体桌面应用程序中使用IOperationsProgressDialog组件,但到目前为止还没有成功。我在C#...

中声明了以下COM导入类型
[ComImport]
[Guid("F8383852-FCD3-11d1-A6B9-006097DF5BD4")]
internal class ProgressDialog
{
}

[ComImport]
[Guid("0C9FB851-E5C9-43EB-A370-F0677B13874C")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IOperationsProgressDialog
{
    ...
}

[ComImport]
[Guid("EBBC7C04-315E-11d2-B62F-006097DF5BD4")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IProgressDialog
{
    ...
}

Class-和interface-id取自Windows 10 SDK中的shlobj.hshobjidl.h头文件;所以我认为他们是正确的。以下代码允许我创建,显示和更新IProgressDialog,但是......

private IProgressDialog dialog;

public void Show(
    IWin32Window owner,
    string title,
    string cancelMessage)
{
    var dialog = (IProgressDialog)(new ProgressDialog());

    dialog.SetTitle(title);
    dialog.SetCancelMsg(cancelMessage, IntPtr.Zero);

    uint dwFlags = PROGDLG_NORMAL | PROGDLG_AUTOTIME;
    int hr = dialog.StartProgressDialog(owner.Handle, IntPtr.Zero, dwFlags, IntPtr.Zero);

    this.dialog = dialog;
}

public void SetProgress(ulong value, ulong total)
{
    this.dialog?.SetProgress64(value, total);
}

...它只是不能使用IOperationsProgressDialog,它(我假设)具有相同的CLSID。我想使用IOperationsProgressDialog组件而不是IProgressDialog,因为它允许用户显示有关正在运行的操作的更多详细信息。

private IOperationsProgressDialog dialog;

public void Show(
    IWin32Window owner)
{
    var dialog = (IOperationsProgressDialog)(new ProgressDialog());

    int hr = dialog.StartProgressDialog(owner.Handle, PROGDLG_NORMAL);

    this.dialog = dialog;
}

public void SetProgress(ulong value, ulong total)
{
    this.dialog?.UpdateProgress(0, 0, value, total, 0, 0);
}

StartProgressDialog的调用似乎工作正常(该方法返回S_OK),但对话框从未显示,后续调用IOperationsProgressDialog接口定义的其他方法在OutOfMemoryException

0 个答案:

没有答案