示例#1
0
        private void CreateMessageWindow()
        {
            // Ensure that the delegate doesn't get garbage collected by storing it as a field.
            _wndProcDelegate = new UnmanagedMethods.WndProc(WndProc);

            UnmanagedMethods.WNDCLASSEX wndClassEx = new UnmanagedMethods.WNDCLASSEX
            {
                cbSize        = Marshal.SizeOf <UnmanagedMethods.WNDCLASSEX>(),
                lpfnWndProc   = _wndProcDelegate,
                hInstance     = UnmanagedMethods.GetModuleHandle(null),
                lpszClassName = "AvaloniaMessageWindow " + Guid.NewGuid(),
            };

            ushort atom = UnmanagedMethods.RegisterClassEx(ref wndClassEx);

            if (atom == 0)
            {
                throw new Win32Exception();
            }

            _hwnd = UnmanagedMethods.CreateWindowEx(0, atom, null, 0, 0, 0, 0, 0, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);

            if (_hwnd == IntPtr.Zero)
            {
                throw new Win32Exception();
            }
        }
示例#2
0
        private void CreateMessageWindow()
        {
            // Ensure that the delegate doesn't get garbage collected by storing it as a field.
            _wndProcDelegate = new UnmanagedMethods.WndProc(WndProc);

            UnmanagedMethods.WNDCLASSEX wndClassEx = new UnmanagedMethods.WNDCLASSEX
            {
                cbSize        = Marshal.SizeOf(typeof(UnmanagedMethods.WNDCLASSEX)),
                lpfnWndProc   = _wndProcDelegate,
                hInstance     = Marshal.GetHINSTANCE(GetType().Module),
                lpszClassName = "PerspexMessageWindow",
            };

            ushort atom = UnmanagedMethods.RegisterClassEx(ref wndClassEx);

            if (atom == 0)
            {
                throw new Win32Exception();
            }

            _hwnd = UnmanagedMethods.CreateWindowEx(0, atom, null, 0, 0, 0, 0, 0, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);

            if (_hwnd == IntPtr.Zero)
            {
                throw new Win32Exception();
            }
        }
示例#3
0
        protected override IntPtr CreateWindowOverride(ushort atom)
        {
            UnmanagedMethods.WindowStyles style =
                UnmanagedMethods.WindowStyles.WS_POPUP |
                UnmanagedMethods.WindowStyles.WS_CLIPSIBLINGS;

            UnmanagedMethods.WindowStyles exStyle =
                UnmanagedMethods.WindowStyles.WS_EX_TOOLWINDOW |
                UnmanagedMethods.WindowStyles.WS_EX_TOPMOST;

            var result = UnmanagedMethods.CreateWindowEx(
                (int)exStyle,
                atom,
                null,
                (uint)style,
                UnmanagedMethods.CW_USEDEFAULT,
                UnmanagedMethods.CW_USEDEFAULT,
                UnmanagedMethods.CW_USEDEFAULT,
                UnmanagedMethods.CW_USEDEFAULT,
                IntPtr.Zero,
                IntPtr.Zero,
                IntPtr.Zero,
                IntPtr.Zero);

            var classes = (int)UnmanagedMethods.GetClassLongPtr(result, (int)UnmanagedMethods.ClassLongIndex.GCL_STYLE);

            classes |= (int)UnmanagedMethods.ClassStyles.CS_DROPSHADOW;

            UnmanagedMethods.SetClassLong(result, UnmanagedMethods.ClassLongIndex.GCL_STYLE, new IntPtr(classes));

            return(result);
        }
示例#4
0
 protected virtual IntPtr CreateWindowOverride(ushort atom)
 {
     return(UnmanagedMethods.CreateWindowEx(
                0,
                atom,
                null,
                (int)UnmanagedMethods.WindowStyles.WS_OVERLAPPEDWINDOW,
                UnmanagedMethods.CW_USEDEFAULT,
                UnmanagedMethods.CW_USEDEFAULT,
                UnmanagedMethods.CW_USEDEFAULT,
                UnmanagedMethods.CW_USEDEFAULT,
                IntPtr.Zero,
                IntPtr.Zero,
                IntPtr.Zero,
                IntPtr.Zero));
 }
示例#5
0
        private void CreateWindow()
        {
            // Ensure that the delegate doesn't get garbage collected by storing it as a field.
            this.wndProcDelegate = new UnmanagedMethods.WndProc(this.WndProc);

            this.className = Guid.NewGuid().ToString();

            UnmanagedMethods.WNDCLASSEX wndClassEx = new UnmanagedMethods.WNDCLASSEX
            {
                cbSize        = Marshal.SizeOf(typeof(UnmanagedMethods.WNDCLASSEX)),
                style         = 0,
                lpfnWndProc   = this.wndProcDelegate,
                hInstance     = Marshal.GetHINSTANCE(this.GetType().Module),
                hCursor       = UnmanagedMethods.LoadCursor(IntPtr.Zero, (int)UnmanagedMethods.Cursor.IDC_ARROW),
                hbrBackground = (IntPtr)5,
                lpszClassName = this.className,
            };

            ushort atom = UnmanagedMethods.RegisterClassEx(ref wndClassEx);

            if (atom == 0)
            {
                throw new Win32Exception();
            }

            this.hwnd = UnmanagedMethods.CreateWindowEx(
                0,
                atom,
                null,
                (int)UnmanagedMethods.WindowStyles.WS_OVERLAPPEDWINDOW,
                UnmanagedMethods.CW_USEDEFAULT,
                UnmanagedMethods.CW_USEDEFAULT,
                UnmanagedMethods.CW_USEDEFAULT,
                UnmanagedMethods.CW_USEDEFAULT,
                IntPtr.Zero,
                IntPtr.Zero,
                IntPtr.Zero,
                IntPtr.Zero);

            if (this.hwnd == IntPtr.Zero)
            {
                throw new Win32Exception();
            }

            this.Handle = new PlatformHandle(this.hwnd, "HWND");
        }
示例#6
0
        protected override IntPtr CreateWindowOverride(ushort atom)
        {
            var hWnd = UnmanagedMethods.CreateWindowEx(
                0,
                atom,
                null,
                (int)UnmanagedMethods.WindowStyles.WS_CHILD,
                0,
                0,
                640,
                480,
                DefaultParentWindow,
                IntPtr.Zero,
                IntPtr.Zero,
                IntPtr.Zero);

            return(hWnd);
        }
示例#7
0
        protected override IntPtr CreateWindowOverride(ushort atom)
        {
            var hWnd = UnmanagedMethods.CreateWindowEx(
                0,
                atom,
                null,
                (int)UnmanagedMethods.WindowStyles.WS_CHILD,
                0,
                0,
                640,
                480,
                WinFormsControl.Handle,
                IntPtr.Zero,
                IntPtr.Zero,
                IntPtr.Zero);

            return(hWnd);
        }
示例#8
0
        private void Initialize(HwndSourceParameters parameters)
        {
            // Ensure that the delegate doesn't get garbage collected by storing it as a field.
            this.wndProcDelegate = new UnmanagedMethods.WndProc(this.WndProc);

            this.className = Guid.NewGuid().ToString();

            UnmanagedMethods.WNDCLASSEX wndClassEx = new UnmanagedMethods.WNDCLASSEX
            {
                cbSize        = Marshal.SizeOf(typeof(UnmanagedMethods.WNDCLASSEX)),
                style         = parameters.WindowClassStyle,
                lpfnWndProc   = this.wndProcDelegate,
                hInstance     = Marshal.GetHINSTANCE(this.GetType().Module),
                hCursor       = UnmanagedMethods.LoadCursor(IntPtr.Zero, (int)UnmanagedMethods.Cursor.IDC_ARROW),
                hbrBackground = (IntPtr)5,
                lpszClassName = this.className,
            };

            ushort atom = UnmanagedMethods.RegisterClassEx(ref wndClassEx);

            if (atom == 0)
            {
                throw new Win32Exception();
            }

            this.Handle = UnmanagedMethods.CreateWindowEx(
                parameters.ExtendedWindowStyle,
                atom,
                parameters.WindowName,
                parameters.WindowStyle,
                parameters.PositionX,
                parameters.PositionY,
                parameters.Width,
                parameters.Height,
                parameters.ParentWindow,
                IntPtr.Zero,
                IntPtr.Zero,
                IntPtr.Zero);

            if (this.Handle == IntPtr.Zero)
            {
                throw new Win32Exception();
            }
        }
示例#9
0
        private static IntPtr CreateParentWindow()
        {
            _wndProcDelegate = new UnmanagedMethods.WndProc(ParentWndProc);

            var wndClassEx = new UnmanagedMethods.WNDCLASSEX
            {
                cbSize        = Marshal.SizeOf <UnmanagedMethods.WNDCLASSEX>(),
                hInstance     = UnmanagedMethods.GetModuleHandle(null),
                lpfnWndProc   = _wndProcDelegate,
                lpszClassName = "AvaloniaEmbeddedWindow-" + Guid.NewGuid(),
            };

            var atom = UnmanagedMethods.RegisterClassEx(ref wndClassEx);

            if (atom == 0)
            {
                throw new Win32Exception();
            }

            var hwnd = UnmanagedMethods.CreateWindowEx(
                0,
                atom,
                null,
                (int)UnmanagedMethods.WindowStyles.WS_OVERLAPPEDWINDOW,
                UnmanagedMethods.CW_USEDEFAULT,
                UnmanagedMethods.CW_USEDEFAULT,
                UnmanagedMethods.CW_USEDEFAULT,
                UnmanagedMethods.CW_USEDEFAULT,
                IntPtr.Zero,
                IntPtr.Zero,
                IntPtr.Zero,
                IntPtr.Zero);

            if (hwnd == IntPtr.Zero)
            {
                throw new Win32Exception();
            }

            return(hwnd);
        }
            public DumbWindow(bool layered = false, IntPtr?parent = null)
            {
                _wndProcDelegate = WndProc;
                var wndClassEx = new UnmanagedMethods.WNDCLASSEX
                {
                    cbSize        = Marshal.SizeOf <UnmanagedMethods.WNDCLASSEX>(),
                    hInstance     = UnmanagedMethods.GetModuleHandle(null),
                    lpfnWndProc   = _wndProcDelegate,
                    lpszClassName = _className = "AvaloniaDumbWindow-" + Guid.NewGuid(),
                };

                var atom = UnmanagedMethods.RegisterClassEx(ref wndClassEx);

                Handle = UnmanagedMethods.CreateWindowEx(
                    layered ? (int)UnmanagedMethods.WindowStyles.WS_EX_LAYERED : 0,
                    atom,
                    null,
                    (int)UnmanagedMethods.WindowStyles.WS_CHILD,
                    0,
                    0,
                    640,
                    480,
                    parent ?? OffscreenParentWindow.Handle,
                    IntPtr.Zero,
                    IntPtr.Zero,
                    IntPtr.Zero);

                if (Handle == IntPtr.Zero)
                {
                    throw new InvalidOperationException("Unable to create child window for native control host. Application manifest with supported OS list might be required.");
                }

                if (layered)
                {
                    UnmanagedMethods.SetLayeredWindowAttributes(Handle, 0, 255,
                                                                UnmanagedMethods.LayeredWindowFlags.LWA_ALPHA);
                }
            }
        protected override IntPtr CreateWindowOverride(ushort atom)
        {
            UnmanagedMethods.WindowStyles style =
                UnmanagedMethods.WindowStyles.WS_POPUP |
                UnmanagedMethods.WindowStyles.WS_CLIPSIBLINGS;

            UnmanagedMethods.WindowStyles exStyle =
                UnmanagedMethods.WindowStyles.WS_EX_TOOLWINDOW |
                UnmanagedMethods.WindowStyles.WS_EX_TOPMOST;

            return(UnmanagedMethods.CreateWindowEx(
                       (int)exStyle,
                       atom,
                       null,
                       (uint)style,
                       UnmanagedMethods.CW_USEDEFAULT,
                       UnmanagedMethods.CW_USEDEFAULT,
                       UnmanagedMethods.CW_USEDEFAULT,
                       UnmanagedMethods.CW_USEDEFAULT,
                       IntPtr.Zero,
                       IntPtr.Zero,
                       IntPtr.Zero,
                       IntPtr.Zero));
        }