1

我正在开发一个 C# XNA 屏幕保护程序套件,到目前为止,一切都已就绪,除了配置对话框必须是 Windows 提供的屏幕保护程序设置对话框的模式(“/c:<hwnd>”参数)。

我的基准是 Vistas 内置的3D 文本屏幕保护程序 - 我的代码应提供相同的功能,并且关于配置对话框,3D 文本显示完全模态到屏幕保护程序设置对话框,当单击屏幕保护程序设置对话框时,对话框会闪烁而不接受点击。

我已尝试按照Ryan Farley的建议使用 IWin32Window 包装 HWND 的方法,但即使我的对话框显示在屏幕保护程序设置对话框的顶部,仍然可以单击屏幕保护程序设置对话框中的控件。

那么我是否需要一些奇异的 Win32API 调用来通知父对话框它已被模态化或者是否存在更干净的解决方案?

4

3 回答 3

0

尝试调用SetParentAPI 函数。

于 2010-01-01T14:20:53.793 回答
0

实际上,事实证明,HWNDwindows 提供给屏幕保护程序的是设置对话框的一个子项,所以通过调用GetParentHWND我得到一个HWND代表对话框的。

今天是我在 stackoverflow.com 上写下我的第一个问题并回答第一个问题的日子。

于 2010-01-01T14:28:15.963 回答
0

我有同样的问题。此外,我无法使用 .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 ();

赖默

于 2013-08-27T07:52:51.093 回答