Example #1
0
        internal Win32Window(string title, int width, int height)
        {
            Width    = width;
            Height   = height;
            _wndProc = WndProc;
            var wndClass = new User32.WndClass
            {
                lpfnWndProc   = _wndProc,
                style         = 0x20,
                hbrBackground = new IntPtr(1),
                lpszClassName = "coreloader"
            };

            User32.RegisterClassA(ref wndClass);

            const int offset = 50;

            var rect = new User32.Rect
            {
                top    = offset,
                left   = offset,
                bottom = offset + height,
                right  = offset + width
            };
            var style = WindowStyles.WS_OVERLAPPEDWINDOW;

            User32.AdjustWindowRect(ref rect, style, false);

            NativeHandle = User32.CreateWindowExA(0, wndClass.lpszClassName, title, style, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);

            const int sizeofMsg = 48;

            _msg = Marshal.AllocHGlobal(sizeofMsg);
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TrayMessageWindow"/> class.
        /// </summary>
        /// <param name="className">Name of the window class to be used with this window.</param>
        public TrayMessageWindow(string className)
        {
            if (className == null || className == string.Empty)
            {
                throw new System.Exception("Provided class name cannot be empty");
            }

            windowProcDelegate = TrayWndProc;
            var windowClass = new User32.WndClass
            {
                ClassName       = className,
                WindowProcedure = Marshal.GetFunctionPointerForDelegate(windowProcDelegate),
            };

            // Register the class name
            ushort classId = User32.RegisterClassW(ref windowClass);

            if (classId == 0 && Marshal.GetLastWin32Error() != User32.ErrorClassAlreadyExists)
            {
                ErrorHandling.ErrorHandler.Handle("Cannot register Tray Window class", ErrorHandling.LogLevel.Error);
                Environment.Exit(1);
            }

            // Finally, create the window
            windowHandle = User32.CreateWindowExW(
                0,
                className,
                string.Empty,
                0,
                0,
                0,
                0,
                0,
                IntPtr.Zero,
                IntPtr.Zero,
                IntPtr.Zero,
                IntPtr.Zero
                );
        }