我有同样的问题。此外,我无法使用 .NET 将对话框直接挂接到外部窗口。因此,我提供了一种解决方法来将对话框挂接到给定窗口句柄的父级:
public class CHelpWindow : Form
{ // this class hooks to a foreign window handle and then it starts a
// modal dialog to this form; .NET seems not to be able to hook a dialog
// to a foreign window handle directly: therefore this solution
// retrieves the parent window of the passed child
[DllImport("user32.dll")]
private static extern IntPtr GetParent (IntPtr hWndChild);
// changes the parent window of the passed child
[DllImport("user32.dll")]
private static extern IntPtr SetParent
(IntPtr hWndChild, IntPtr hWndNewParent);
// --------------------------------------------------------------------
public CHelpWindow (long liHandle)
// this constructor initializes this form and hooks this form to the parent
// of the passed window handle; then it prepares the call to create the
// dialog after this form window is first shown in the screen.
{
// removing the system title of the window
FormBorderStyle = FormBorderStyle.None;
// the dialog will be created when this form is first shown
Shown += new EventHandler (HelpWindow_Shown);
// hooking to the parent of the passed handle: that is the control, not
// the tab of the screen saver dialog
IntPtr oParent = GetParent (new IntPtr (liHandle));
SetParent (Handle, oParent);
}
// --------------------------------------------------------------------
private void HelpWindow_Shown (object oSender, EventArgs oEventArgs)
// this function is called when the form is first shown; now is the right
// time to start our configuration dialog
{
// positioning this window outside the parent area
Location = new Point (-100, -100);
// reducing the size
Size = new Size (1, 1);
ClientSize = new Size (1, 1);
// creating the dialog
CKonfiguration oConfiguration = new CKonfiguration ();
// starting this dialog with the owner of this object; because this
// form is hooked to the screen saver dialog, the startet dialog is
// then indirectly hooked to that dialog
oConfiguration.ShowDialog (this);
// we don not need this object any longer
Close ();
}
}
从命令行提取句柄后
/c:####
你创建你的对话框
CHelpWindow oHelpWindow = new CHelpWindow (liHandle);
oHelpWindow.ShowDialog ();
赖默