我正在使用C#XNA屏幕保护套件,到目前为止,除了配置对话框之外,所有内容都已到位,该对话框必须是对Windows提供的屏幕保护程序设置对话框的模态(“/ c: < hwnd>“参数)。
我的基准是Vistas内置 3D Text 屏幕保护程序 - 我的代码应提供相同的功能,关于配置对话框, 3D Text 完全模态显示到屏幕“保护程序设置”对话框,单击屏幕保护程序设置对话框时,对话框将闪烁而不接受单击。
我已尝试使用Ryan Farley建议的IWin32Window包装HWND的方法,但即使我的对话框显示在屏幕保护程序设置对话框的顶部,<可以单击em>屏幕保护程序设置对话框。
所以我需要一些奇特的Win32API调用来通知父对话框它已被模态化还是存在更干净的解决方案?
答案 0 :(得分:0)
尝试调用SetParent
API函数。
答案 1 :(得分:0)
实际上,事实证明,Windows提供给屏幕保护程序的HWND
是设置对话框的子项,因此通过调用GetParent
上的HWND
,我得到HWND
1}}代表对话框。
今天是我在stackoverflow.com上写第一个问题并回答第一个问题的那一天。
答案 2 :(得分: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 directly: therefore this solution
// retrievs 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 positions itself outside
// the client area; then it prepares the call to create the dialog after
// the form is first shown in the window
{
// suppressing multiple layout events
SuspendLayout ();
// positioning the windoe outside the parent area
ClientSize = new Size ( 1, 1);
Location = new Point (-1, -1);
// the dialog will be created when this form is first shown
Shown += new EventHandler (HelpWindow_Shown);
// resuming layout events without executing pending layout requests
ResumeLayout (false);
// 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
{
// now 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 ();
默