private void RegisterWindowClass()
        {
            _wndProcDelegate = WndProc;
            var wc = new WindowClassEx
            {
                Styles         = WindowClassStyles.CS_HREDRAW | WindowClassStyles.CS_VREDRAW | WindowClassStyles.CS_OWNDC,
                WindowProc     = _wndProcDelegate,
                InstanceHandle = Kernel32.GetModuleHandle(null),
                CursorHandle   = User32.LoadCursor(IntPtr.Zero, (IntPtr)SystemCursor.IDC_ARROW),
                ClassName      = CLASS_NAME
            };

            wc.Size = (uint)Marshal.SizeOf(wc);

            // Load user icon - if any.
            wc.IconHandle = User32.LoadImage(Kernel32.GetModuleHandle(null), "#32512", ResourceImageType.IMAGE_ICON, 0, 0, LoadResourceFlags.LR_DEFAULTSIZE | LoadResourceFlags.LR_SHARED);
            if (wc.IconHandle == IntPtr.Zero)
            {
                Kernel32.SetLastError(0);

                // None loaded - load default.
                wc.IconHandle = User32.LoadImage(IntPtr.Zero, (IntPtr)SystemIcon.IDI_APPLICATION, ResourceImageType.IMAGE_ICON, 0, 0, LoadResourceFlags.LR_DEFAULTSIZE | LoadResourceFlags.LR_SHARED);
            }

            ushort windowClass = User32.RegisterClassEx(ref wc);

            if (windowClass == 0)
            {
                CheckError("Win32: Failed to register window class.", true);
            }

            CheckError("Win32: Could not register class.");
        }
Beispiel #2
0
        private static ushort CreateWindowClass(WndProc wndProc, string menuName, string className)
        {
            var wnd = new WindowClassEx()
            {
                cbSize        = WindowClassEx.GetSize(),
                style         = 0,
                lpfnWndProc   = Marshal.GetFunctionPointerForDelegate(wndProc),
                cbClsExtra    = 0,
                cbWndExtra    = 0,
                hInstance     = IntPtr.Zero,
                hIcon         = IntPtr.Zero,
                hCursor       = IntPtr.Zero,
                hbrBackground = IntPtr.Zero,
                lpszMenuName  = menuName,
                lpszClassName = className,
                hIconSm       = IntPtr.Zero
            };

            var regResult = User32.RegisterClassEx(ref wnd);

            if (regResult == 0)
            {
                ExceptionHelper.ThrowLastWin32Exception();
            }

            return(regResult);
        }
Beispiel #3
0
        /// <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);
        }
Beispiel #4
0
        public WindowFactory(string name, WindowClassStyles styles, IntPtr hInstance, IntPtr hIcon, IntPtr hCursor,
                             IntPtr hBgBrush, WindowProc wndProc)
        {
            var cache     = Cache.Instance;
            var className = name ?? Guid.NewGuid().ToString();

            this.ClassName      = className;
            this.InstanceHandle = hInstance;
            this.m_windowProc   = wndProc ?? DefWindowProc;

            this.m_classInitializerProcRef = this.ClassInitializerProc;

            var classInfo = new WindowClassEx
            {
                Size                  = cache.WindowClassExSize,
                ClassName             = className,
                CursorHandle          = hCursor,
                IconHandle            = hIcon,
                Styles                = styles,
                BackgroundBrushHandle = hBgBrush,
                WindowProc            = this.m_classInitializerProcRef,
                InstanceHandle        = hInstance
            };

            this.RegisterClass(ref classInfo);
        }
Beispiel #5
0
        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();
        }
Beispiel #6
0
		private static void RegisterWindowClass() {
			WindowClassEx classEx = new WindowClassEx();
			classEx.ClassName = MessageWindowClassName;
			classEx.WndProc = wndProc;

			classEx.Size = (uint)Marshal.SizeOf(typeof(WindowClassEx));

			var atom = ShellObjectWatcherNativeMethods.RegisterClassEx(ref classEx);
			if (atom == 0) {
				throw new ShellException(LocalizedMessages.MessageListenerClassNotRegistered,
					Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error()));
			}
			_atom = atom;
		}
Beispiel #7
0
        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);
        }
Beispiel #8
0
        public WindowFactory(ref WindowClassEx classEx)
        {
            this.ClassName      = classEx.ClassName;
            this.InstanceHandle = classEx.InstanceHandle;
            this.m_windowProc   = classEx.WindowProc ?? DefWindowProc;

            this.m_classInitializerProcRef = this.ClassInitializerProc;
            // Leave the reference untouched. So, use a copy for the modified registration.
            var classExClone = classEx;

            classExClone.WindowProc = this.m_classInitializerProcRef;

            this.RegisterClass(ref classExClone);
        }
Beispiel #9
0
        /// <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);
        }
Beispiel #10
0
 private void RegisterClass(ref WindowClassEx classEx)
 {
     if (User32Methods.RegisterClassEx(ref classEx) == 0)
     {
         var errString = string.Empty;
         var err       = Kernel32Methods.GetLastError();
         // It may not always be the correct code. Since we aren't using
         // Marshal's last error. If the CLR runtime calls into the
         // system meanwhile that may be returned instead, at times.
         if (err != 0)
         {
             errString = "Possible error code: " + err;
         }
         throw new Exception("Failed to register class. " + errString);
     }
 }
Beispiel #11
0
        public static int CreateWindow(string title)
        {
            // Window class
            WindowClassEx windowClass = new WindowClassEx
            {
                Size           = (uint)Marshal.SizeOf <WindowClassEx>(),
                WindowProc     = _wndProc,
                InstanceHandle = GetModuleHandle(null),
                CursorHandle   = LoadCursor(IntPtr.Zero, new IntPtr(IDC_ARROW)),
                ClassName      = ClassName
            };

            RegisterClassEx(ref windowClass);

            // Window
            Rectangle rect = new Rectangle {
                Left = 0, Top = 0, Right = _width, Bottom = _height
            };

            AdjustWindowRect(ref rect, WS_OVERLAPPEDWINDOW, false);
            _hWnd = CreateWindowEx(0, ClassName, title, WS_OVERLAPPEDWINDOW,
                                   CW_USEDEFAULT, CW_USEDEFAULT, rect.Right - rect.Left, rect.Bottom - rect.Top,
                                   IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);

            // GL Context
            PixelFormatDescriptor pfd = new PixelFormatDescriptor
            {
                Size        = (short)Marshal.SizeOf <PixelFormatDescriptor>(),
                Version     = 1,
                Flags       = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
                PixelType   = PFD_TYPE_RGBA,
                ColorBits   = 24,
                StencilBits = 8
            };

            _hDC = GetDC(_hWnd);
            int pixelFormat = ChoosePixelFormat(_hDC, ref pfd);

            SetPixelFormat(_hDC, pixelFormat, ref pfd);

            IntPtr hRC = wglCreateContext(_hDC);

            wglMakeCurrent(_hDC, hRC);

            return(0);
        }
        private static void RegisterWindowClass()
        {
            WindowClassEx classEx = new WindowClassEx();

            classEx.ClassName = MessageWindowClassName;
            classEx.WndProc   = wndProc;

            classEx.Size = (uint)Marshal.SizeOf(typeof(WindowClassEx));

            var atom = ShellObjectWatcherNativeMethods.RegisterClassEx(ref classEx);

            if (atom == 0)
            {
                throw new ShellException(LocalizedMessages.MessageListenerClassNotRegistered,
                                         Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error()));
            }
            _atom = atom;
        }
Beispiel #13
0
        /// <summary> Register the class with the winapi </summary>
        private protected virtual void RegisterClass()
        {
            WindowClassEx wcex = new WindowClassEx()
            {
                Style       = DoubleClicks | VRedraw | HRedraw,
                WindowsProc = proc,
                ClsExtra    = 0,
                WndExtra    = 0,
                Icon        = LoadIcon(IntPtr.Zero, (IntPtr)ApplicationIcon),
                Cursor      = LoadCursorA(IntPtr.Zero, (IntPtr)ArrowCursor),
                IconSm      = IntPtr.Zero,
                Background  = (IntPtr)(ColorWindow + 1),
                MenuName    = null,
                ClassName   = ClassName
            };

            wcex.Size = (uint)Marshal.SizeOf(wcex);

            RegisterClassEx(ref wcex);
        }
Beispiel #14
0
 public static extern int RegisterClassEx(ref WindowClassEx wcex);
        /// <summary>
        ///     Setups the instance.
        /// </summary>
        /// <param name="x">The x.</param>
        /// <param name="y">The y.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        private void SetupInstance(int x = 0, int y = 0, int width = 800, int height = 600)
        {
            IsVisible = true;
            Topmost   = !BypassTopmost;

            X      = x;
            Y      = y;
            Width  = width;
            Height = height;

            WindowClassName = HelperMethods.GenerateRandomString(5, 11);
            string randomMenuName = HelperMethods.GenerateRandomString(5, 11);

            if (WindowTitle == null)
            {
                WindowTitle = HelperMethods.GenerateRandomString(5, 11);
            }

            // prepare method
            _windowProc = WindowProcedure;
            RuntimeHelpers.PrepareDelegate(_windowProc);
            _windowProcPtr = Marshal.GetFunctionPointerForDelegate(_windowProc);

            var wndClassEx = new WindowClassEx
            {
                cbSize        = WindowClassEx.Size(),
                style         = 0,
                lpfnWndProc   = _windowProcPtr,
                cbClsExtra    = 0,
                cbWndExtra    = 0,
                hInstance     = IntPtr.Zero,
                hIcon         = IntPtr.Zero,
                hCursor       = IntPtr.Zero,
                hbrBackground = IntPtr.Zero,
                lpszMenuName  = randomMenuName,
                lpszClassName = WindowClassName,
                hIconSm       = IntPtr.Zero
            };

            if (User32.RegisterClassEx(ref wndClassEx) == 0)
            {
                WinApi.ThrowWin32Exception("Failed to register window class!");
            }

            uint exStyle;

            if (BypassTopmost)
            {
                exStyle = (uint)(ExtendedWindowStyles.Transparent | ExtendedWindowStyles.Layered |
                                 ExtendedWindowStyles.NoActivate);
            }
            else
            {
                exStyle = (uint)(ExtendedWindowStyles.TopMost | ExtendedWindowStyles.Transparent |
                                 ExtendedWindowStyles.Layered | ExtendedWindowStyles.NoActivate);
            }

            WindowHandle = User32.CreateWindowEx(
                exStyle,
                WindowClassName,
                WindowTitle,
                (uint)(WindowStyles.Popup | WindowStyles.Visible),
                X, Y,
                Width, Height,
                IntPtr.Zero,
                IntPtr.Zero,
                IntPtr.Zero,
                IntPtr.Zero
                );

            if (WindowHandle == IntPtr.Zero)
            {
                WinApi.ThrowWin32Exception("Failed to create window!");
            }

            User32.SetLayeredWindowAttributes(WindowHandle, 0, 255, (uint)LayeredWindowAttribute.Alpha);
            User32.UpdateWindow(WindowHandle);

            IsInitialized = true;

            // If window is incompatible on some platforms use SetWindowLong to set the style again
            // and UpdateWindow If you have changed certain window data using SetWindowLong, you must
            // call SetWindowPos for the changes to take effect. Use the following combination for
            // uFlags: SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED.

            ExtendFrameIntoClientArea();
        }
Beispiel #16
0
        public static IntPtr CreateWindow(Func <Message, IntPtr> processMessage, string className, string title = null)
        {
            if (HandleWindow != IntPtr.Zero)
            {
                return(HandleWindow);
            }
            WindowProc = new WindowProc((handleWindow, wm, wParam, lParam) =>
            {
                IntPtr result = IntPtr.Zero;
                if (processMessage != null)
                {
                    var message = new Message
                    {
                        handle  = handleWindow,
                        message = wm,
                        wParam  = wParam,
                        lParam  = lParam,
                    };;
                    result = processMessage(message);
                }
                if (result == IntPtr.Zero)
                {
                    return(Win32.DefWindowProc(handleWindow, wm, wParam, lParam));
                }
                else
                {
                    return(result);
                }
            });

            WindowClassEx = new WindowClassEx()
            {
                size               = Marshal.SizeOf(typeof(WindowClassEx)),
                style              = CS.HREDRAW | CS.VREDRAW,
                windowProc         = Marshal.GetFunctionPointerForDelegate(WindowProc),
                classExtra         = 0,
                windowExtra        = 0,
                handleInstance     = IntPtr.Zero,
                handleIcon         = IntPtr.Zero,
                handleCursor       = IntPtr.Zero,
                handlebrBackground = IntPtr.Zero,
                menuName           = null,
                className          = className,
                handleIconSm       = IntPtr.Zero,
            };

            Tracable.LogLine("windowClassEx {0}", WindowClassEx.ToString());

            var registeredClassEx = Win32.RegisterClassEx(ref WindowClassEx);

            Tracable.LogLine("registeredClassEx {0}", registeredClassEx.ToString());
            if (registeredClassEx == 0)
            {
                var error = Win32.GetLastError();
                Tracable.LogLine("error {0}", error.ToRepr());
                Win32.UnregisterClass(className, IntPtr.Zero);
                return(IntPtr.Zero);
            }

            HandleWindow = Win32.CreateWindowEx
                           (
                WS_EX.NONE,
                registeredClassEx,
                title ?? WindowClassEx.className,
                WS.NONE,
                0,
                0,
                0,
                0,
                IntPtr.Zero,
                IntPtr.Zero,
                WindowClassEx.handleInstance,
                IntPtr.Zero
                           );
            Tracable.LogLine("handle {0}", HandleWindow.ToRepr());

            if (HandleWindow == null)
            {
                var error = Win32.GetLastError();
                Tracable.LogLine("error {0}", error.ToRepr());
            }
            return(HandleWindow);
        }
Beispiel #17
0
        /// <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);
        }
Beispiel #18
0
 private static extern ushort RegisterClassEx([In] ref WindowClassEx lpwcx);
Beispiel #19
0
        private void SetupWindow()
        {
            // generate a random title if it's null (invalid)
            if (_title == null)
            {
                _title = WindowHelper.GenerateRandomTitle();
            }
            if (string.IsNullOrEmpty(MenuName))
            {
                MenuName = WindowHelper.GenerateRandomTitle();
            }
            // if no class name is given then generate a "unique" one
            if (string.IsNullOrEmpty(_className))
            {
                _className = WindowHelper.GenerateRandomClass();
            }

            // prepare window procedure
            _windowProc        = WindowProcedure;
            _windowProcAddress = Marshal.GetFunctionPointerForDelegate(_windowProc);

            // try to register our class
            while (true)
            {
                var wndClassEx = new WindowClassEx
                {
                    Size        = WindowClassEx.NativeSize(),
                    Style       = 0,
                    WindowProc  = _windowProcAddress,
                    ClsExtra    = 0,
                    WindowExtra = 0,
                    Instance    = IntPtr.Zero,
                    Icon        = IntPtr.Zero,
                    Curser      = IntPtr.Zero,
                    Background  = IntPtr.Zero,
                    MenuName    = MenuName,
                    ClassName   = _className,
                    IconSm      = IntPtr.Zero
                };

                if (User32.RegisterClassEx(ref wndClassEx) != 0)
                {
                    break;
                }
                else
                {
                    // already taken name?
                    _className = WindowHelper.GenerateRandomClass();
                }
            }

            var extendedWindowStyle = ExtendedWindowStyle.Transparent | ExtendedWindowStyle.Layered | ExtendedWindowStyle.NoActivate;

            if (_isTopmost)
            {
                extendedWindowStyle |= ExtendedWindowStyle.Topmost;
            }

            var windowStyle = WindowStyle.Popup;

            if (_isVisible)
            {
                windowStyle |= WindowStyle.Visible;
            }

            _handle = User32.CreateWindowEx(
                extendedWindowStyle,
                _className,
                _title,
                windowStyle,
                _x, _y,
                _width, _height,
                IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);

            User32.SetLayeredWindowAttributes(_handle, 0, 255, LayeredWindowAttributes.Alpha);
            User32.UpdateWindow(_handle);

            // if the window is incompatible on some platforms then use
            // SetWindowLong and UpdateWindow to set the style again and
            // call SetWindowPos with SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED

            if (_isVisible)
            {
                WindowHelper.ExtendFrameIntoClientArea(_handle);
            }
        }
Beispiel #20
0
 public static extern ushort RegisterClassEx([In] ref WindowClassEx windowClassEx);
Beispiel #21
0
 //Documentation: https://msdn.microsoft.com/en-us/library/windows/desktop/ms633587(v=vs.85).aspx
 private static extern ushort RegisterClassEx(ref WindowClassEx windowClass);