1

wpf アプリケーションで exe をカプセル化する必要があります。私の wpf アプリケーションは非常に大きく、多くの UserControls があります。これを行うには、コードからexeを開始し、ハンドルを取得して「setParent」を使用してexeをアプリケーションに「バインド」しましたが、唯一の効果はexeのドロップダウンメニューを表示することですが、メインページではありません。例:メモ帳を埋め込もうとしましたが、その領域をクリックするとドロップダウンメニューのみが表示されます(メインメニューバーは表示されないことに注意してください)。

  var procInfo = new System.Diagnostics.ProcessStartInfo(this.exeName);
  procInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(this.exeName);

  // Start the process
  _childp = System.Diagnostics.Process.Start(procInfo);

  // Wait for process to be created and enter idle condition
  _childp.WaitForInputIdle();

  // Get the main handle
  _appWin = _childp.MainWindowHandle;

  // Get main window handle
  var helper = new WindowInteropHelper(Window.GetWindow(this.AppContainer));

  // Incapsulate
  SetWindowLongA(_appWin, -20, 0x00000040 | 0x00000008);
  SetParent(_appWin, helper.Handle);

このコードを他の C# アプリケーションで試してみたところ、問題なく動作したことに注意してください。ビューポートの再描画/更新に問題があると思います。アプリケーション内の外部 exe のこの再描画をどのように強制できますか? exeを埋め込むための代替ソリューションを見つけるために、私を助けてもらえますか? ありがとう

ここに画像の説明を入力

別のタブ( here )でexeを実行するソリューションを試しましたが、このソリューションでも機能しません。

「SendMessage」でこれを解決できますか??? 行うべきテストを提案してもらえますか?

ひとつお願いがあります。助けてください!!!

4

2 に答える 2

0

ウィンドウの WPF 内でallowstransparency ="false"の代わりに allowtransparency="true" を使用すると、問題を部分的に解決することができました

これで、このアプローチ ( WindowsFormHostアプローチ) を使用して、外部 exe (例: "notepad.exe") を埋め込みました。

System.Windows.Forms.Panel _pnlSched = new System.Windows.Forms.Panel();

System.Windows.Forms.Integration.WindowsFormsHost windowsFormsHost1 = 
              new System.Windows.Forms.Integration.WindowsFormsHost();
windowsFormsHost1.Child = _pnlSched;
_grid.Children.Add(windowsFormsHost1);
ProcessStartInfo psi = new ProcessStartInfo(@"notepad.exe");
psi.WindowStyle = ProcessWindowStyle.Normal;
Process PR = Process.Start(psi);
PR.WaitForInputIdle(); 
SetParent(PR.MainWindowHandle, _pnlSched.Handle);  

新しい問題は、ユーザー コントロールの Z オーダーである可能性があります。実際、別のユーザーコントロールが「メモ帳」の上に移動すると、上ではなく下になります...

ここに画像の説明を入力

WindowsFormHost の背景も「z オーダー」を尊重しないことに注意してください。

ここに画像の説明を入力

どんな提案も大歓迎です

ありがとう

于 2016-06-23T10:40:07.200 に答える
0

以下は私にとってはうまくいきます。必要に応じてサンプルプロジェクトを提供できます。欠落している部分は、az インデックスの問題があるか、デスクトップ座標の最初のウィンドウの配置が「外側のウィンドウ」の外側にあるようです。

これにより、 from が取得され、ウィンドウがいっぱいになります。

SetWindowPos(_appWin, default(IntPtr), 0, 0, (int)Application.Current.MainWindow.Width, (int)Application.Current.MainWindow.Height, SetWindowPosFlags.FrameChanged);

デフォルト (IntPtr) は ZIndex 用で、「前面に表示」と表示されます

次に、含まれているコントロールからオフセットを渡すことで、それを小さくすることができます。つまり、this.gridメモ帳を上に表示したい場合:

    var desiredPos = this.grid.TranslatePoint(new Point(0, 0), Window.GetWindow(this.grid));
    SetWindowPos(_appWin, default(IntPtr), 
        (int)desiredPos.X, (int)desiredPos.Y, 
        (int)this.grid.ActualWidth, (int)this.grid.ActualHeight, SetWindowPosFlags.FrameChanged);
于 2016-06-10T14:40:59.023 に答える