public unsafe override bool Equals(object obj) { if (!(obj is WNDCLASSEX)) { return(false); fixed(WNDCLASSEX *address = &this) { WNDCLASSEX other = (WNDCLASSEX)obj; IntPtr size = new IntPtr(GetSize()); IntPtr equalBytes = NativeMethods.RtlCompareMemory(address, &other, size); return(size == equalBytes); } }
internal unsafe MainWindow() { IntPtr handle; WNDCLASSEX windowClass = new WNDCLASSEX(); windowClass.cbSize = (uint)WNDCLASSEX.GetSize(); fixed (char* stringPointer = "WindowClass".ToCharArray()) { windowClass.style = NativeConstants.CS_HREDRAW | NativeConstants.CS_VREDRAW; windowClass.lpfnWndProc = (WNDPROC)WndProc; windowClass.cbClsExtra = 0; windowClass.cbWndExtra = 0; windowClass.hInstance = NativeMethods.GetModuleHandle((char*)null); windowClass.lpszClassName = stringPointer; } if (NativeMethods.RegisterClassEx(&windowClass) == 0) throw new InvalidOperationException(); RECT rectangle = new RECT { left = 0, top = 0, right = 640, bottom = 480 }; NativeMethods.AdjustWindowRect(&rectangle, NativeConstants.WS_OVERLAPPEDWINDOW, false); fixed (char* title = "TestApp".ToCharArray()) { handle = NativeMethods.CreateWindowEx(0, windowClass.lpszClassName, title, NativeConstants.WS_OVERLAPPEDWINDOW, NativeConstants.CW_USEDEFAULT, NativeConstants.CW_USEDEFAULT, rectangle.right - rectangle.left, rectangle.bottom - rectangle.top, IntPtr.Zero, IntPtr.Zero, windowClass.hInstance, null); } if (handle == IntPtr.Zero) throw new InvalidOperationException(); NativeMethods.ShowWindow(handle, (int)NativeConstants.SW_SHOW); }
public static extern short RegisterClassEx(ref WNDCLASSEX pcWndClassEx);
internal GameWindow(int x, int y, int width, int height, string title, IntPtr icon, IntPtr smallIcon, Action onTimer) { this.onTimer = onTimer; wndProc = ProcessMessages; WNDCLASSEX wc = new WNDCLASSEX { cbSize = (uint)WNDCLASSEX.SizeInBytes, //style = ClassStyles.HorizontalRedraw | ClassStyles.VerticalRedraw, style = ClassStyles.OwnDC | ClassStyles.HorizontalRedraw | ClassStyles.VerticalRedraw, hInstance = instance, lpfnWndProc = wndProc, lpszClassName = className, hIcon = icon, hIconSm = smallIcon, hCursor = Functions.LoadCursor(NULL, IDC.ARROW), hbrBackground = NULL, cbClsExtra = 0, cbWndExtra = 0, lpszMenuName = null }; short atom = Functions.RegisterClassEx(ref wc); if (atom == 0) throw new Exception(String.Format("Failed to register window class. Error: {0}", Marshal.GetLastWin32Error())); const WS style = //(WS)0x16cf0000; //WS.CAPTION | WS.VISIBLE | WS.CLIPSIBLINGS | WS.CLIPCHILDREN | //WS.SYSMENU | WS.SIZEFRAME | WS.OVERLAPPEDWINDOW | WS.MINIMIZEBOX | WS.MAXIMIZEBOX; (WS)114229248; const WS_EX exStyle = //(WS_EX)0x00040100; //WS_EX.LEFT | WS_EX.LTRREADING | WS_EX.RIGHTSCROLLBAR | //WS_EX.WINDOWEDGE | WS_EX.APPWINDOW; (WS_EX)262401 ^ WS_EX.DLGMODALFRAME; //IntPtr windowName = Marshal.StringToHGlobalAuto(title); // Find out the final window rectangle, after the WM has added its chrome (titlebar, sidebars etc). RECT rect = new RECT { left = x, top = y, right = x + width, bottom = y + height }; Functions.AdjustWindowRectEx(ref rect, style, false, exStyle); hwnd = Functions.CreateWindowEx( exStyle, className, title, style, rect.left, rect.top, rect.Width, rect.Height, IntPtr.Zero, IntPtr.Zero, instance, IntPtr.Zero); if (hwnd == IntPtr.Zero) throw new Exception(String.Format("Failed to create window. Error: {0}", Marshal.GetLastWin32Error())); Functions.GetClientRect(hwnd, out clientRectangle); input = new Input(GetClientRect); }
public static unsafe extern ushort RegisterClassEx(WNDCLASSEX* lpwcx);