C# 屏幕保护程序:配置对话框模式以提供 HWND

发布于 2024-08-17 01:37:32 字数 542 浏览 14 评论 0原文

我正在开发 C# XNA 屏幕保护程序套件,到目前为止,除了配置对话框之外,一切都已就位,该对话框必须是 Windows 提供的屏幕保护程序设置对话框的模式(“/c:;“ 争论)。

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

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

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

I am working on a C# XNA screensaver kit and so far, everything is in place except for the configuration dialog which must be modal to the Screen Saver Settings dialog provided by windows ("/c:<hwnd>" argument).

My benchmark is Vistas builtin 3D Text screensaver - my code shall provide the same features and regarding the configuration dialog, 3D Text displays fully modal to the Screen Saver Settings dialog and when clicking Screen Saver Settings dialog, the dialogs blink without accepting the click.

I have tried the method of wrapping the HWND with a IWin32Window as suggested by Ryan Farley, but even though my dialog displays on top of the Screen Saver Settings dialog, the controls in Screen Saver Settings dialog still can be clicked.

So do I need some exotic Win32API calls to inform the parent dialog that it has been modalized or does a more clean solution exist?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

流殇 2024-08-24 01:37:32

Try calling the SetParent API function.

孤独患者 2024-08-24 01:37:32

实际上,原来Windows向屏幕保护程序提供的HWND是设置对话框的子项,因此通过在HWND上调用GetParent ,我得到一个代表对话框的 HWND

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

Actually, it turned out that the HWND provided by windows to the screensaver is a child of the settings dialog, so by calling GetParent on the HWND, I get an HWND that represents the dialog.

Today is the day that I wrote my first question on stackoverflow.com and answered the first question.

飞烟轻若梦 2024-08-24 01:37:32

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

,您可以通过Reimer

I had the same problem. Additionally I was not able to directly hook a dialog to a foreign window with .NET. Therefore I supply a work around to hook a dialog to the parent of a given window handle:

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

After extracting your handle from the command line

/c:####

you create your Dialog by

CHelpWindow oHelpWindow = new CHelpWindow (liHandle);
oHelpWindow.ShowDialog ();

Reimer

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文