private Cache() { this.ProcessHandle = Kernel32Methods.GetCurrentProcess(); this.AppIconHandle = User32Helpers.LoadIcon(IntPtr.Zero, SystemIcon.IDI_APPLICATION); this.ArrowCursorHandle = User32Helpers.LoadCursor(IntPtr.Zero, SystemCursor.IDC_ARROW); this.WindowClassExSize = (uint)Marshal.SizeOf <WindowClassEx>(); }
/// <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; } User32Methods.ShowWindow(Handle, styles.Item3); User32Methods.UpdateWindow(Handle); }
public void Init(string title, int width, int height, bool vsync, bool fullscreen) { if (m_Info != null) { throw new InvalidOperationException("application already initialized"); } m_Info = new ApplicationInfo { Title = title, Width = width, Height = height, VSync = vsync, FullScreen = fullscreen }; IntPtr hInstance = Kernel32Methods.GetModuleHandle(IntPtr.Zero); m_WindowProc = WindowProc; var wc = new WindowClassEx { Size = (uint)Marshal.SizeOf <WindowClassEx>(), ClassName = "MainWindow", CursorHandle = User32Helpers.LoadCursor(IntPtr.Zero, SystemCursor.IDC_ARROW), IconHandle = User32Helpers.LoadIcon(IntPtr.Zero, SystemIcon.IDI_APPLICATION), Styles = WindowClassStyles.CS_HREDRAW | WindowClassStyles.CS_VREDRAW | WindowClassStyles.CS_OWNDC, BackgroundBrushHandle = new IntPtr((int)StockObject.WHITE_BRUSH), WindowProc = m_WindowProc, InstanceHandle = hInstance }; if (User32Methods.RegisterClassEx(ref wc) == 0) { throw new ExternalException("window registration failed"); } NetCoreEx.Geometry.Rectangle size = new NetCoreEx.Geometry.Rectangle(0, 0, width, height); User32Methods.AdjustWindowRectEx(ref size, WindowStyles.WS_OVERLAPPEDWINDOW | WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS, false, WindowExStyles.WS_EX_APPWINDOW | WindowExStyles.WS_EX_WINDOWEDGE); m_hWnd = User32Methods.CreateWindowEx(WindowExStyles.WS_EX_APPWINDOW | WindowExStyles.WS_EX_WINDOWEDGE, wc.ClassName, title, WindowStyles.WS_OVERLAPPEDWINDOW | WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS, (int)CreateWindowFlags.CW_USEDEFAULT, (int)CreateWindowFlags.CW_USEDEFAULT, size.Right + (-size.Left), size.Bottom + (-size.Top), IntPtr.Zero, IntPtr.Zero, hInstance, IntPtr.Zero); if (m_hWnd == IntPtr.Zero) { throw new ExternalException("window creation failed"); } User32Methods.ShowWindow(m_hWnd, ShowWindowCommands.SW_SHOWNORMAL); User32Methods.UpdateWindow(m_hWnd); Context.Instance.Init(m_hWnd, m_Info); Renderer.Instance.Init(); Script.LuaEngine.Instance.Init(); }
static int Main(string[] args) { var instanceHandle = Kernel32Methods.GetModuleHandle(IntPtr.Zero); var wc = new WindowClassEx { Size = (uint)Marshal.SizeOf <WindowClassEx>(), ClassName = "MainWindow", CursorHandle = User32Helpers.LoadCursor(IntPtr.Zero, SystemCursor.IDC_ARROW), IconHandle = User32Helpers.LoadIcon(IntPtr.Zero, SystemIcon.IDI_APPLICATION), 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) { Console.Error.WriteLine("registration failed"); return(-1); } var hwnd = User32Methods.CreateWindowEx(WindowExStyles.WS_EX_APPWINDOW, wc.ClassName, "Hello", WindowStyles.WS_OVERLAPPEDWINDOW, (int)CreateWindowFlags.CW_USEDEFAULT, (int)CreateWindowFlags.CW_USEDEFAULT, (int)CreateWindowFlags.CW_USEDEFAULT, (int)CreateWindowFlags.CW_USEDEFAULT, IntPtr.Zero, IntPtr.Zero, instanceHandle, IntPtr.Zero); if (hwnd == IntPtr.Zero) { Console.Error.WriteLine("window creation failed"); return(-1); } User32Methods.ShowWindow(hwnd, ShowWindowCommands.SW_SHOWNORMAL); User32Methods.UpdateWindow(hwnd); Message msg; int res; while ((res = User32Methods.GetMessage(out msg, IntPtr.Zero, 0, 0)) != 0) { User32Methods.TranslateMessage(ref msg); User32Methods.DispatchMessage(ref msg); } return(res); }
/// <summary> /// The create window. /// </summary> private void CreateWindow() { var instanceHandle = Kernel32Methods.GetModuleHandle(IntPtr.Zero); 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(mHostConfig.HostState); var hwnd = User32Methods.CreateWindowEx( styles.Item2, wc.ClassName, mHostConfig.HostTitle, styles.Item1, 0, 0, mHostConfig.HostWidth, mHostConfig.HostHeight, IntPtr.Zero, IntPtr.Zero, instanceHandle, IntPtr.Zero); if (hwnd == IntPtr.Zero) { Log.Error("chromelywindow creation failed"); return; } User32Methods.ShowWindow(Handle, styles.Item3); User32Methods.UpdateWindow(Handle); }
/// <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); }