2016-09-28 5 views
4

私は、メインUIの一部として既に存在するQT GUIアプリケーションをホストするためにWPF GUIアプリケーションを作成しようとしています。QTアプリケーションをWPFアプリケーションにホストすることはできますか?

QTアプリケーションはマウス/キーボード入力を処理する必要はありません。

このSO Postに記載されているアプローチを試しました。これらのアプローチはすべてQTアプリケーションでは機能しないようです。

enter image description here

答えて

0

それを行うには正しいことかどうかは分かりませんが、それは私が(インターネット上で見つかった)他のアプリをembeddするためにいくつかの時間を使用したものです:

public partial class MainWindow : Window 
{ 
private Process _process; 

[DllImport("user32.dll")] 
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong); 

[DllImport("user32.dll", SetLastError = true)] 
private static extern int GetWindowLong(IntPtr hWnd, int nIndex); 

[DllImport("user32")] 
private static extern IntPtr SetParent(IntPtr hWnd, IntPtr hWndParent); 

[DllImport("user32")] 
private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags); 

private const int SWP_NOZORDER = 0x0004; 
private const int SWP_NOACTIVATE = 0x0010; 
private const int GWL_STYLE = -16; 
private const int WS_CAPTION = 0x00C00000; 
private const int WS_THICKFRAME = 0x00040000; 
const string patran = "patran"; 
public MainWindow() 
{ 
    InitializeComponent(); 

    Loaded += (s, e) => LaunchChildProcess(); 
} 

private void LaunchChildProcess() 
{ 
    _process = Process.Start("/path/to/QtExecutable.exe"); 
    _process.WaitForInputIdle(); 

    var helper = new WindowInteropHelper(this); 

    SetParent(_process.MainWindowHandle, helper.Handle); 

    // remove control box 
    int style = GetWindowLong(_process.MainWindowHandle, GWL_STYLE); 
    style = style & ~WS_CAPTION & ~WS_THICKFRAME; 
    SetWindowLong(_process.MainWindowHandle, GWL_STYLE, style); 
    // resize embedded application & refresh 
    ResizeEmbeddedApp(); 
} 

private void ResizeEmbeddedApp() 
{ 
    if (_process == null) 
     return; 
    SetWindowPos(_process.MainWindowHandle, IntPtr.Zero, 0, 0, (int)ActualWidth, (int)ActualHeight, SWP_NOZORDER | SWP_NOACTIVATE); 
} 

protected override Size MeasureOverride(Size availableSize) 
{ 
    Size size = base.MeasureOverride(availableSize); 
    ResizeEmbeddedApp(); 
    return size; 
} 

はこれを修正しますあなたの必需品にスケルトン。 動作するかどうか教えてください。

+0

ありがとう:それはどのようなものか

。私はそれを答えとして受け入れ、より良い解決策がない場合には後に賞を授与します。 – ricky

+0

@rickyよろしくお願いします –

+0

「インターネット上に見つかりません」というのは、ここにあります:http://stackoverflow.com/questions/5028598/hosting-external-app-in-wpf-window –

0

はい。可能です。あなたのクイックスタートのための非常に簡単な方法は、コーディングの努力なしに。

このリンクを確認してください:WPFウィンドウアプリケーション(http://www.codeproject.com/Tips/673701/Hosting-EXE-Applications-in-a-WPF-Window-Applicati)でEXEアプリケーションをホストする。プロジェクトをダウンロードします。プロジェクトで "notepad.exe"を見つけて、QTアプリケーションのファイル名に置き換えます。 WPF exeがQTアプリケーションを起動するためには、QTが必要とする環境変数を処理する必要があるかもしれません。いくつかのマイナーな問題がまだあるものの、ルカが、それは、私の作品 enter image description here

+0

私はこの質問をする前にこれを試しました。そして、このファイルのQTアプリ – ricky

+0

で動作しないようです:TestWpfAppControl \ MainWindow.xaml.cs、あなたのQTに必要な環境変数を登録してください。私の場合は、すべてのQT実行ファイルを自分のWPF exeのフォルダの下に置きます。また、MainWindow.xaml.csファイルを次のように変更します。appControl.ExeName = "myQT.exe"; Environment.SetEnvironmentVariable( "PATH"、 "bin"); –

関連する問題