2016-09-28 15 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"); –