1

私は C# XNA スクリーンセーバー キットに取り組んでいますが、これまでのところ、 Windows によって提供されるスクリーン セーバー設定ダイアログ ("/c:<hwnd>" 引数) に対してモーダルである必要がある構成ダイアログを除いて、すべてが整っています。

私のベンチマークは、Vista に組み込まれた 3D テキストスクリーンセーバーです。私のコードは同じ機能を提供し、設定ダイアログに関して、3D テキストはスクリーン セーバー設定ダイアログに対して完全にモーダルに表示され、スクリーン セーバー設定ダイアログをクリックすると、クリックを受け入れずにダイアログが点滅します。

Ryan Farleyが提案したように、HWND を IWin32Window でラップする方法を試しましたが、ダイアログが [スクリーン セーバーの設定] ダイアログの上に表示されても、[スクリーン セーバーの設定]ダイアログのコントロールは引き続きクリックできます。

では、親ダイアログにモダライズされたこと、またはよりクリーンなソリューションが存在することを通知するために、いくつかのエキゾチックな Win32API 呼び出しが必要ですか?

4

3 に答える 3

0

SetParentAPI 関数を呼び出してみてください。

于 2010-01-01T14:20:53.793 に答える
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 に答える
0

実際、Windows がスクリーンセーバーに提供する は設定ダイアログの子であることが判明したHWNDため、 を呼び出すGetParentと、ダイアログを表す がHWND取得されます。HWND

今日は、stackoverflow.com で最初の質問を書き、最初の質問に答えた日です。

于 2010-01-01T14:28:15.963 に答える