private void button2_Click(object sender, EventArgs e) { WndClass wc = new WndClass(); wc.style = 0x0001 | 0x0002; wc.lpfnWndProc = new WndProc(MyWndProc); wc.hInstance = Program.hInstance; wc.hbrBackground = (IntPtr)6; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hIcon = IntPtr.Zero; wc.hCursor = IntPtr.Zero; wc.lpszMenuName = null; wc.lpszClassName = "Mqd.WinForm.WndClassName3"; ushort rc = Win32API.RegisterClass(ref wc); if (rc == 0) { uint n = Win32API.GetLastError(); Console.WriteLine(n); } else { StringBuilder className = new StringBuilder(100); Win32API.GetClassName(this.Handle, className, 100); IntPtr hwnd = Win32API.CreateWindow(wc.lpszClassName, "WindowName", WndStyle.WS_CAPTION | WndStyle.WS_VISIBLE | WndStyle.WS_BORDER | WndStyle.WS_OVERLAPPED | WndStyle.WS_SYSMENU, 10, 10, 500, 350, IntPtr.Zero, IntPtr.Zero, Program.hInstance, IntPtr.Zero); if (hwnd == IntPtr.Zero) { uint n = Win32API.GetLastError(); Console.WriteLine(n); } } }
private void RegisterClass() { WndClass l_class = new WndClass (ClassName); if (!l_class.IsRegistered ()) { l_class.Style = ClassStyle; l_class.WindowProcedure = ClassWindowProcedure; // For the time being, users cannot change the icon, cursor and brush for the class. l_class.Cursor = Win32.LoadCursor (IntPtr.Zero, (int) IdcStandardCursors.Idc_arrow); l_class.Icon = Win32.LoadIcon (IntPtr.Zero, new IntPtr ((int) SystemIcons.Idi_application)); l_class.BackgroundBrush = Win32.GetStockObject (StockObjects.Gray_brush); l_class.Register (); } wnd_class = l_class; Contract.Ensures (l_class.IsRegistered (), "class is registered"); }
protected ushort RegisterClass(string className) { var lpWndClass = new WndClass { cbClsExtra = 0, cbWndExtra = 0, hbrBackground = IntPtr.Zero, hCursor = IntPtr.Zero, hIcon = IntPtr.Zero, lpfnWndProc = _wndProc = new NativeMethods.NativeMethods.WndProc(WndProc), lpszClassName = className, lpszMenuName = null, style = 0U }; return(User32.RegisterClass(ref lpWndClass)); }
private void RegisterClass() { WndClass l_class = new WndClass(ClassName); if (!l_class.IsRegistered()) { l_class.Style = ClassStyle; l_class.WindowProcedure = ClassWindowProcedure; // For the time being, users cannot change the icon, cursor and brush for the class. l_class.Cursor = Win32.LoadCursor(IntPtr.Zero, (int)IdcStandardCursors.Idc_arrow); l_class.Icon = Win32.LoadIcon(IntPtr.Zero, new IntPtr((int)SystemIcons.Idi_application)); l_class.BackgroundBrush = Win32.GetStockObject(StockObjects.Gray_brush); l_class.Register(); } wnd_class = l_class; Contract.Ensures(l_class.IsRegistered(), "class is registered"); }
public PeageantWindow(SshAgent agent) { _wndProcDelegate = PegeantWndProc; // Create WNDCLASS WndClass windClass = new WndClass(); windClass.lpszClassName = CLASS_NAME_PAGEANT; windClass.lpfnWndProc = Marshal.GetFunctionPointerForDelegate(_wndProcDelegate); var classAtom = RegisterClassW(ref windClass); int lastError = Marshal.GetLastWin32Error(); if (classAtom == 0 && lastError != ERROR_CLASS_ALREADY_EXISTS) { throw new Exception("Could not register window class"); } // Create window _hwnd = CreateWindowExW( 0, CLASS_NAME_PAGEANT, CLASS_NAME_PAGEANT, 0, 0, 0, 0, 0, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero ); _agent = agent; }
public static extern ushort RegisterClassW([In] ref WndClass lpWndClass);
public static void CreateWindow() { if (IsOpen) { return; } MelonLogger.Msg("Starting window creation"); CheckLightTheme(); CheckLemonTheme(); IntPtr hInstance = Process.GetCurrentProcess().Handle; string szClassName = "VRCModUpdaterWinClass"; WndClass wc = default; wc.lpfnWndProc = HandleWindowEvent; wc.hInstance = hInstance; wc.lpszClassName = szClassName; if (lemonMode) { //backgroundColor = GDI.RGB(255, 242, 0); backgroundColor = GDI.RGB(255, 236, 0); } else if (lightMode) { backgroundColor = GDI.RGB(255, 255, 255); } else { backgroundColor = GDI.RGB(42, 42, 46); } hBackgroudBrush = GDI.CreateSolidBrush(backgroundColor); wc.hbrBackground = hBackgroudBrush; MelonLogger.Msg("Registering window class"); ushort regResult = User32.RegisterClass(ref wc); if (regResult == 0) { MelonLogger.Warning("Failed to register updater window. Updating in windowless mode"); GDI.DeleteObject(hBackgroudBrush); return; } MelonLogger.Msg("Creating window"); hWindow = User32.CreateWindowEx( 0, // Optional window styles. szClassName, // Window class "VRCModUpdater", // Window text WindowStyles.WS_POPUPWINDOW, // Window style // Size and position 100, 100, 600, 250, IntPtr.Zero, // Parent window IntPtr.Zero, // Menu hInstance, // Instance handle IntPtr.Zero); // Additional application data if (hWindow == IntPtr.Zero) { int lastError = Marshal.GetLastWin32Error(); string errorMessage = new Win32Exception(lastError).Message; MelonLogger.Warning("Failed to create updater window. Updating in windowless mode. Error:\n" + errorMessage); GDI.DeleteObject(hBackgroudBrush); return; } MelonLogger.Msg("Showing window"); User32.ShowWindow(hWindow, ShowWindowCommands.Normal); IsOpen = true; }
internal static extern ushort RegisterClass(ref WndClass lpWndClass);
public static extern ushort RegisterClassA(ref WndClass wndClass);
private static extern UInt16 RegisterClassW( [In] ref WndClass lpWndClass ); [DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr RegisterClassEx(ref WndClass wndClass);
public static extern ushort RegisterClass([In] ref WndClass lpwcx);