private static ushort RegisterClass() { var wndclass = WNDCLASSEX.Create(); wndclass.lpszClassName = WindowClassName; wndclass.lpfnWndProc = StaticWndProc; var result = RegisterClassEx(ref wndclass); if (result == 0) { throw new Win32Exception("RegisterClass error."); } return(result); }
private static void EnsureInit() { if (!_isInit) { cl = WNDCLASSEX.Create(); cl.lpszClassName = ClassName; cl.hInstance = GetModuleHandle(null); cl.style = ClassStyles.CS_OWNDC; cl.lpfnWndProc = WindowProc; classRegistrationAtom = RegisterClassEx(ref cl); if (classRegistrationAtom == 0) { throw new PlatformException($"RegisterClassEx failed: {Marshal.GetLastWin32Error()}"); } _isInit = true; } }
public Win32Window() { var wndClass = WNDCLASSEX.Create(); wndClass.cbClsExtra = 0; wndClass.cbWndExtra = 0; wndClass.hbrBackground = CreateSolidBrush(COLORREF.Create(PlayerSettings.backgroundColor)); wndClass.hCursor = LoadCursor(IntPtr.Zero, IDC_ARROW); wndClass.hIcon = IntPtr.Zero; wndClass.hIconSm = IntPtr.Zero; wndClass.hInstance = IntPtr.Zero; wndClass.lpfnWndProc = Marshal.GetFunctionPointerForDelegate(this.wndproc = this.ProcessWindowsMessage); wndClass.lpszClassName = className; wndClass.style = WindowClassStyles.VREDRAW | WindowClassStyles.HREDRAW; if (0 == RegisterClassEx(ref wndClass)) { throw new Exception(); } CreateWindowEx(0, className, title, WindowStyles.OVERLAPPEDWINDOW, 100, 100, 1280, 720, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); ShowWindow(this.handle, WindowShowStyle.Show); UpdateWindow(this.handle); }