我在WPF該主機的Unity應用深化發展的應用程序。 該主機是通過使用HwndHost類(因爲與_hwndparent參數的統一方式似乎別(T工作)。嵌入式Unity3D在WPF應用程序 - > SetWindowLong函數問題
在我HwndHost類的BuilWindowCore,我需要改變使用GetWindowLong和SetWindowLong函數窗口子樣式設置。
所有這些作品完美我的深化發展的計算機上,但我不能在另一臺計算機上使用的應用。
當我剛剛設置WS_CCHILD值(不使用檢索的GetWindowLong風格)療法是不會崩潰在所有的計算機上,但子應用程序沒有正確顯示(最大化等)。這就是爲什麼我認爲問題是關於造型子窗口部分。
還有就是我HwndHost類代碼:
public class UnityHwndHost : HwndHost
{
private Process _process;
private HandleRef _hwnd;
private IntPtr _unityHWND; // = IntPtr.Zero;
private const int GWL_STYLE = -16;
// Window Styles
const UInt32 WS_OVERLAPPED = 0;
const UInt32 WS_POPUP = 0x80000000;
const UInt32 WS_CHILD = 0x40000000;
const UInt32 WS_MINIMIZE = 0x20000000;
const UInt32 WS_VISIBLE = 0x10000000;
const UInt32 WS_DISABLED = 0x8000000;
const UInt32 WS_CLIPSIBLINGS = 0x4000000;
const UInt32 WS_CLIPCHILDREN = 0x2000000;
const UInt32 WS_MAXIMIZE = 0x1000000;
const UInt32 WS_CAPTION = 0xC00000; // WS_BORDER or WS_DLGFRAME
const UInt32 WS_BORDER = 0x800000;
const UInt32 WS_DLGFRAME = 0x400000;
const UInt32 WS_VSCROLL = 0x200000;
const UInt32 WS_HSCROLL = 0x100000;
const UInt32 WS_SYSMENU = 0x80000;
const UInt32 WS_THICKFRAME = 0x40000;
const UInt32 WS_GROUP = 0x20000;
const UInt32 WS_TABSTOP = 0x10000;
const UInt32 WS_MINIMIZEBOX = 0x20000;
const UInt32 WS_MAXIMIZEBOX = 0x10000;
const UInt32 WS_TILED = WS_OVERLAPPED;
const UInt32 WS_ICONIC = WS_MINIMIZE;
const UInt32 WS_SIZEBOX = WS_THICKFRAME;
// Extended Window Styles
const UInt32 WS_EX_DLGMODALFRAME = 0x0001;
const UInt32 WS_EX_NOPARENTNOTIFY = 0x0004;
const UInt32 WS_EX_TOPMOST = 0x0008;
const UInt32 WS_EX_ACCEPTFILES = 0x0010;
const UInt32 WS_EX_TRANSPARENT = 0x0020;
const UInt32 WS_EX_MDICHILD = 0x0040;
const UInt32 WS_EX_TOOLWINDOW = 0x0080;
const UInt32 WS_EX_WINDOWEDGE = 0x0100;
const UInt32 WS_EX_CLIENTEDGE = 0x0200;
const UInt32 WS_EX_CONTEXTHELP = 0x0400;
const UInt32 WS_EX_RIGHT = 0x1000;
const UInt32 WS_EX_LEFT = 0x0000;
const UInt32 WS_EX_RTLREADING = 0x2000;
const UInt32 WS_EX_LTRREADING = 0x0000;
const UInt32 WS_EX_LEFTSCROLLBAR = 0x4000;
const UInt32 WS_EX_RIGHTSCROLLBAR = 0x0000;
const UInt32 WS_EX_CONTROLPARENT = 0x10000;
const UInt32 WS_EX_STATICEDGE = 0x20000;
const UInt32 WS_EX_APPWINDOW = 0x40000;
const UInt32 WS_EX_OVERLAPPEDWINDOW = (WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE);
const UInt32 WS_EX_PALETTEWINDOW = (WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST);
const UInt32 WS_EX_LAYERED = 0x00080000;
const UInt32 WS_EX_NOINHERITLAYOUT = 0x00100000; // Disable inheritence of mirroring by children
const UInt32 WS_EX_LAYOUTRTL = 0x00400000; // Right to left mirroring
const UInt32 WS_EX_COMPOSITED = 0x02000000;
const UInt32 WS_EX_NOACTIVATE = 0x08000000;
private const int WM_ACTIVATE = 0x0006;
private readonly IntPtr WA_ACTIVE = new IntPtr(1);
private readonly IntPtr WA_INACTIVE = new IntPtr(0);
[DllImport("user32.dll")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, UInt32 dwNewLong);
[DllImport("user32.dll", SetLastError = true)]
private static extern UInt32 GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32")]
private static extern IntPtr SetParent(IntPtr hWnd, IntPtr hWndParent);
internal delegate int WindowEnumProc(IntPtr hwnd, IntPtr lparam);
[DllImport("user32.dll")]
internal static extern bool EnumChildWindows(IntPtr hwnd, WindowEnumProc func, IntPtr lParam);
[DllImport("user32.dll")]
static extern int SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto)]
public static extern bool IsWindow(IntPtr hWnd);
#region CONSTRUCTORS
#endregion
#region METHODS
protected override HandleRef BuildWindowCore(HandleRef hwndParent)
{
var context = DataContext as UltrasoundVM;
var psi = new ProcessStartInfo("UnityStandAlone.exe");
psi.Arguments = "\"" + context.Workspace.Replace('\\', '/') + "\" " + context.SelectedFlexible;
LoggerHelper.Write(GetType().FullName + "." + new StackTrace().GetFrame(0).GetMethod().Name + " : " + psi.Arguments, EventLogEntryType.Information);
psi.WindowStyle = ProcessWindowStyle.Minimized;
_process = Process.Start(psi);
_process.WaitForInputIdle();
while (_process.MainWindowHandle == IntPtr.Zero || !IsWindow(_process.MainWindowHandle))
{
Thread.Yield();
}
_unityHWND = _process.MainWindowHandle;
SetParent(_unityHWND, hwndParent.Handle);
var style = GetWindowLong(_unityHWND, GWL_STYLE);
style = style & ~WS_CAPTION & ~WS_THICKFRAME; // Removes Caption bar and the sizing border
style |= (WS_CHILD); // Must be a child window to be hosted
SetWindowLong(_unityHWND, GWL_STYLE, style);
SetWindowLong(_unityHWND, GWL_STYLE, WS_CHILD | WS_MAXIMIZE);
SendMessage(_unityHWND, WM_ACTIVATE, WA_ACTIVE, IntPtr.Zero);
_hwnd = new HandleRef(this, _unityHWND);
return _hwnd;
}
protected override void DestroyWindowCore(HandleRef hwnd)
{
SendMessage(_hwnd.Handle, WM_ACTIVATE, WA_INACTIVE, IntPtr.Zero);
_process.CloseMainWindow();
_process.WaitForExit(5000);
if (_process.HasExited == false)
{
_process.Kill();
}
_process.Close();
_process.Dispose();
_process = null;
}
#endregion
}
注:
的深化發展計算機
- 操作系統:Windows 10家庭版 - 團結3D 5.5.2.f.1免費版
測試計算機 - 操作系統:Windows 10(家庭版&專業版)
當然,我一直試圖建立與不同的參數,與我父應用同樣的事情的統一應用。
_「因爲與_hwndparent參數的統一方式似乎別(T工作」 _ ......這就是它是如何工作的。它允許指定的窗口句柄子團結的窗口......沒有這樣的說法會拋出異常,並不會表現符合市場預期。 –
你有一個工作樣本?因爲官方的統一樣本(一與立方體)不工作... – Yokaichan
只需添加'-parentHWND'爲您的參數...在這之後一切都應該作爲工作之意。 –