gpt4 book ai didi

c# - IProgressDialog 立即启动

转载 作者:太空狗 更新时间:2023-10-30 01:32:23 25 4
gpt4 key购买 nike

我按正常使用 IProgressDialog 界面,一切正常,但进度对话框仅在确定操作确实冗长后几秒钟后出现。尽管这在任何地方都没有记录,但它似乎是有意为之的行为,而且在许多情况下还不错。但是,在这个特定的应用程序中,我需要立即显示它。

我找到了一个 single reference在整个网络上承认这一点并提出解决方法。然而,也许是因为在那九年中有相当多的新 Windows 版本,它今天似乎不起作用:

IProgressDialog dialog;
dialog.StartProgressDialog(owner, null, flags, IntPtr.Zero);
...
IntPtr DialogHWnd;
((IOleWindow)dialog).GetWindow(out DialogHWnd);
SendMessage(DialogHWnd, WM_TIMER, new IntPtr(1), IntPtr.Zero);

窗口句柄没问题,我检查过,没有错误,只是行为没有变化。该对话框仅在几秒钟后出现。

除了在 C# 中重新创建相同的对话框和功能之外,是否有人有任何建议?当然,这并非不可能,但除了用户非常熟悉之外,库存对话框还具有动画和取消行为等不错的功能。

最佳答案

StartProgressDialog 之前或之后立即调用 dialog.Timer(PDTIMER_RESUME, null)。这是一个最小的示例:

using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace WindowsFormsApplication1 {

[Flags]
public enum IPD_Flags: uint {
Normal = 0x00000000,
Modal = 0x00000001,
AutoTime = 0x00000002,
NoTime = 0x00000004,
NoMinimize = 0x00000008,
NoProgressBar = 0x00000010
}

[Flags]
public enum IPDTIMER_Flags: uint {
Reset = 0x00000001,
Pause = 0x00000002,
Resume = 0x00000003
}

[ComImport]
[Guid("F8383852-FCD3-11d1-A6B9-006097DF5BD4")]
internal class ProgressDialog {
}

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

[PreserveSig]
void StartProgressDialog(IntPtr hwndParent
, [MarshalAs(UnmanagedType.IUnknown)] object punkEnableModless
, uint dwFlags
, IntPtr pvResevered);

[PreserveSig]
void StopProgressDialog();

[PreserveSig]
void SetTitle([MarshalAs(UnmanagedType.LPWStr)] string pwzTitle);

[PreserveSig]
void SetAnimation(IntPtr hInstAnimation, ushort idAnimation);

[PreserveSig]
[return: MarshalAs(UnmanagedType.Bool)]
bool HasUserCancelled();

[PreserveSig]
void SetProgress(uint dwCompleted, uint dwTotal);

[PreserveSig]
void SetProgress64(ulong ullCompleted, ulong ullTotal );

[PreserveSig]
void SetLine(uint dwLineNum
, [MarshalAs(UnmanagedType.LPWStr)] string pwzString
, [MarshalAs(UnmanagedType.VariantBool)] bool fCompactPath
, IntPtr pvResevered);

[PreserveSig]
void SetCancelMsg([MarshalAs(UnmanagedType.LPWStr)]string pwzCancelMsg, object pvResevered);

[PreserveSig]
void Timer(uint dwTimerAction, object pvResevered);

}


public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e) {
ProgressDialog progressDialog = new ProgressDialog();
IProgressDialog iProgressDialog = (IProgressDialog)progressDialog;

iProgressDialog.Timer((uint) IPDTIMER_Flags.Resume, null);
iProgressDialog.StartProgressDialog(this.Handle
, null
, (uint)(IPD_Flags.Normal | IPD_Flags.NoMinimize)
, IntPtr.Zero);
}
}

关于c# - IProgressDialog 立即启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37374110/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com