protected override void OnCreate(ref CreateWindowPacket packet) { SetText("Terminal Velocity"); const int LOGPIXELSX = 88; const int LOGPIXELSY = 90; IntPtr hdc = User32Methods.GetDC(Handle); _dpiScale = new SizeF( WinApi.Gdi32.Gdi32Methods.GetDeviceCaps(hdc, LOGPIXELSX) / 96.0f, WinApi.Gdi32.Gdi32Methods.GetDeviceCaps(hdc, LOGPIXELSY) / 96.0f ); User32Methods.ReleaseDC(Handle, hdc); Convert(GetClientSize(), out SizeF size); _initializeEvent?.Publish(new InitializeEventData(Handle, size)); _createEvent?.Publish(new CreateEventData()); base.OnCreate(ref packet); }
/// <summary> /// The create window. /// </summary> private void CreateWindow() { var instanceHandle = Kernel32Methods.GetModuleHandle(IntPtr.Zero); _windowProc = WindowProc; var wc = new WindowClassEx { Size = (uint)Marshal.SizeOf <WindowClassEx>(), ClassName = "chromelywindow", CursorHandle = User32Helpers.LoadCursor(IntPtr.Zero, SystemCursor.IDC_ARROW), IconHandle = GetIconHandle(), Styles = WindowClassStyles.CS_HREDRAW | WindowClassStyles.CS_VREDRAW, BackgroundBrushHandle = new IntPtr((int)StockObject.WHITE_BRUSH), WindowProc = _windowProc, InstanceHandle = instanceHandle }; var resReg = User32Methods.RegisterClassEx(ref wc); if (resReg == 0) { Log.Error("chromelywindow registration failed"); return; } var styles = GetWindowStyles(_hostConfig.HostPlacement.State); var placement = _hostConfig.HostPlacement; NativeMethods.RECT rect; rect.Left = placement.Left; rect.Top = placement.Top; rect.Right = placement.Left + placement.Width; rect.Bottom = placement.Top + placement.Height; NativeMethods.AdjustWindowRectEx(ref rect, styles.Item1, false, styles.Item2); var hwnd = User32Methods.CreateWindowEx( styles.Item2, wc.ClassName, _hostConfig.HostPlacement.Frameless ? string.Empty : _hostConfig.HostTitle, styles.Item1, rect.Left, rect.Top, rect.Right - rect.Left, rect.Bottom - rect.Top, IntPtr.Zero, IntPtr.Zero, instanceHandle, IntPtr.Zero); if (hwnd == IntPtr.Zero) { Log.Error("chromelywindow creation failed"); return; } if (_hostConfig.HostPlacement.KioskMode) { //// Set new window style and size. var windowHDC = User32Methods.GetDC(Handle); var fullscreenWidth = Gdi32Methods.GetDeviceCaps(windowHDC, (int)DeviceCapsParams.HORZRES); var fullscreenHeight = Gdi32Methods.GetDeviceCaps(windowHDC, (int)DeviceCapsParams.VERTRES); User32Methods.ReleaseDC(Handle, windowHDC); User32Methods.SetWindowLongPtr(Handle, (int)WindowLongFlags.GWL_STYLE, (IntPtr)styles.Item1); User32Methods.SetWindowLongPtr(Handle, (int)WindowLongFlags.GWL_EXSTYLE, (IntPtr)styles.Item2); User32Methods.SetWindowPos(Handle, (IntPtr)HwndZOrder.HWND_TOP, 0, 0, fullscreenWidth, fullscreenHeight, WindowPositionFlags.SWP_NOZORDER | WindowPositionFlags.SWP_FRAMECHANGED); User32Methods.ShowWindow(Handle, ShowWindowCommands.SW_MAXIMIZE); try { this._hookID = NativeMethods.SetHook(_hookCallback); } catch { DetachKeyboardHook(); } } else { User32Methods.ShowWindow(Handle, styles.Item3); } User32Methods.UpdateWindow(Handle); User32Methods.RegisterHotKey(IntPtr.Zero, 1, KeyModifierFlags.MOD_CONTROL, VirtualKey.L); }
public IntPtr GetDc() { return(User32Methods.GetDC(this.Handle)); }