void IFrameworkView.SetWindow(CoreWindow window) { _coreWindow = window; UpdateSize(window); _coreWindow.SizeChanged += CoreWindow_SizeChanged; // Set handle. OnHandleCreated(SwapChainHandle.CreateUWPCoreWindow(_coreWindow)); }
public Win32Window(WindowsApplicationHost host, string title, int width, int height) : base(title) { _title = title; _host = host; //const bool fullscreen = false; var resizable = true; var x = 0; var y = 0; WindowStyles style = 0; WindowExStyles styleEx = 0; // Setup the screen settings depending on whether it is running in full screen or in windowed mode. //if (fullscreen) //{ //style = User32.WindowStyles.WS_POPUP | User32.WindowStyles.WS_VISIBLE; //styleEx = User32.WindowStyles.WS_EX_APPWINDOW; //width = screenWidth; //height = screenHeight; //} //else { if (width > 0 && height > 0) { var screenWidth = GetSystemMetrics(SystemMetrics.SM_CXSCREEN); var screenHeight = GetSystemMetrics(SystemMetrics.SM_CYSCREEN); // Place the window in the middle of the screen.WS_EX_APPWINDOW x = (screenWidth - width) / 2; y = (screenHeight - height) / 2; } if (resizable) { style = WindowStyles.WS_OVERLAPPEDWINDOW; } else { style = WindowStyles.WS_POPUP | WindowStyles.WS_BORDER | WindowStyles.WS_CAPTION | WindowStyles.WS_SYSMENU; } styleEx = WindowExStyles.WS_EX_APPWINDOW | WindowExStyles.WS_EX_WINDOWEDGE; } style |= WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS; int windowWidth; int windowHeight; if (width > 0 && height > 0) { var rect = new Rect(0, 0, (int)(width * ContentScale), (int)(height * ContentScale)); // Adjust according to window styles AdjustWindowRectEx( ref rect, style, false, styleEx); windowWidth = rect.Right - rect.Left; windowHeight = rect.Bottom - rect.Top; } else { x = y = windowWidth = windowHeight = CW_USEDEFAULT; } _hwnd = CreateWindowEx( (int)styleEx, WindowsApplicationHost.WndClassName, title, (int)style, x, y, windowWidth, windowHeight, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); if (_hwnd == IntPtr.Zero) { //Log.Error("[Win32] - Failed to create window"); return; } _host.RegisterWindow(this); ShowWindow(_hwnd, ShowWindowCommand.Normal); // Rase and set handle. OnHandleCreated(SwapChainHandle.CreateWin32(host.HInstance, _hwnd)); }