Пример #1
0
        public HwndSource()
        {
            HwndSourceParameters parameters = new HwndSourceParameters
            {
                PositionX = UnmanagedMethods.CW_USEDEFAULT,
                PositionY = UnmanagedMethods.CW_USEDEFAULT,
                Width = UnmanagedMethods.CW_USEDEFAULT,
                Height = UnmanagedMethods.CW_USEDEFAULT,
                WindowStyle = (int)UnmanagedMethods.WindowStyles.WS_OVERLAPPEDWINDOW
            };

            this.Initialize(parameters);
        }
Пример #2
0
        public HwndSource()
        {
            HwndSourceParameters parameters = new HwndSourceParameters
            {
                PositionX   = UnmanagedMethods.CW_USEDEFAULT,
                PositionY   = UnmanagedMethods.CW_USEDEFAULT,
                Width       = UnmanagedMethods.CW_USEDEFAULT,
                Height      = UnmanagedMethods.CW_USEDEFAULT,
                WindowStyle = (int)UnmanagedMethods.WindowStyles.WS_OVERLAPPEDWINDOW
            };

            this.Initialize(parameters);
        }
Пример #3
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();
            }
        }
Пример #4
0
        public override PlatformPresentationSource CreatePopupPresentationSource()
        {
            UnmanagedMethods.WindowStyles style =
                UnmanagedMethods.WindowStyles.WS_POPUP;

            UnmanagedMethods.WindowStyles extendedStyle =
                UnmanagedMethods.WindowStyles.WS_EX_TOPMOST |
                UnmanagedMethods.WindowStyles.WS_EX_TOOLWINDOW |
                UnmanagedMethods.WindowStyles.WS_EX_NOACTIVATE;

            HwndSourceParameters parameters = new HwndSourceParameters
            {
                WindowStyle         = unchecked ((int)style),
                ExtendedWindowStyle = unchecked ((int)extendedStyle),
                PositionX           = 500,
                PositionY           = 500,
                Width  = 200,
                Height = 200,
            };

            return(new HwndSource(parameters));
        }
Пример #5
0
 public HwndSource(HwndSourceParameters parameters)
 {
     this.Initialize(parameters);
 }
Пример #6
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();
            }
        }
        public override PlatformPresentationSource CreatePopupPresentationSource()
        {
            UnmanagedMethods.WindowStyles style =
                UnmanagedMethods.WindowStyles.WS_POPUP;

            UnmanagedMethods.WindowStyles extendedStyle =
                UnmanagedMethods.WindowStyles.WS_EX_TOPMOST |
                UnmanagedMethods.WindowStyles.WS_EX_TOOLWINDOW |
                UnmanagedMethods.WindowStyles.WS_EX_NOACTIVATE;

            HwndSourceParameters parameters = new HwndSourceParameters
            {
                WindowStyle = unchecked((int)style),
                ExtendedWindowStyle = unchecked((int)extendedStyle),
                PositionX = 500,
                PositionY = 500,
                Width = 200,
                Height = 200,
            };

            return new HwndSource(parameters);
        }
Пример #8
0
 public HwndSource(HwndSourceParameters parameters)
 {
     this.Initialize(parameters);
 }