Esempio n. 1
0
        /// <summary>
        /// Creates child window and D3D device
        /// </summary>
        /// <param name="hwndParent"></param>
        /// <returns></returns>
        protected override HandleRef BuildWindowCore(HandleRef hwndParent)
        {
            IntPtr hInstance    = Marshal.GetHINSTANCE(typeof(System.Windows.Application).Module);
            string wndClassName = "NetDCWin323DEngineClass";
            string wndName      = "WinRender";

            _CallbackOnCollectedDelegateWindowProc = new User32.WndProc(MyWndProc);

            User32.WNDCLASSEX wcex = new User32.WNDCLASSEX()
            {
                cbSize        = Marshal.SizeOf(typeof(User32.WNDCLASSEX)),
                style         = User32.CS.CS_HREDRAW | User32.CS.CS_VREDRAW,
                lpfnWndProc   = _CallbackOnCollectedDelegateWindowProc,
                cbClsExtra    = 0,
                cbWndExtra    = 0,
                hInstance     = hInstance,
                hIcon         = IntPtr.Zero,
                hbrBackground = (IntPtr)(GDI32.COLOR.COLOR_WINDOW + 1),
                hCursor       = User32.LoadCursor(IntPtr.Zero, User32.IDC.IDC_ARROW),
                lpszClassName = wndClassName,
                lpszMenuName  = null,
                hIconSm       = IntPtr.Zero
            };

            short atom = User32.RegisterClassEx(ref wcex);

            if (atom == 0)
            {
                throw new System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error());
            }

            IntPtr hWnd = User32.CreateWindowEx(
                User32.WS_EX.WS_EX_NONE,
                wndClassName,
                wndName,
                User32.WS.WS_CHILD | User32.WS.WS_VISIBLE,
                User32.CW_USEDEFAULT, User32.CW_USEDEFAULT,
                640, 480,
                hwndParent.Handle,
                IntPtr.Zero,
                hInstance,
                IntPtr.Zero);

            if (hWnd == IntPtr.Zero)
            {
                throw new System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error()); //Cannot find window class???
            }
            _childHwnd = hWnd;



            return(new HandleRef(this, _childHwnd));
        }
Esempio n. 2
0
        protected override HandleRef BuildWindowCore(HandleRef hwndParent)
        {
            var wndclass = new User32.WNDCLASSEX();

            wndclass.cbSize    = Marshal.SizeOf <User32.WNDCLASSEX>();
            wndclass.style     = 0;
            wndclass.hInstance = Kernel32.GetModuleHandle(null).DangerousGetHandle();
            User32.RegisterClassEx(ref wndclass);
            var windowHandle = User32.CreateWindowEx((User32.WindowStylesEx)WS_EX_NOREDIRECTIONBITMAP, "static", "", User32.WindowStyles.WS_CHILD | User32.WindowStyles.WS_CLIPCHILDREN | User32.WindowStyles.WS_VISIBLE, 0, 0, (int)Width, (int)Height, hwndParent.Handle, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);

            User32.SetWindowPos(windowHandle, hwndParent.Handle, 0, 0, (int)Width, (int)Height, User32.SetWindowPosFlags.SWP_SHOWWINDOW);
            ANGLE.InitializeContext((int)Width, (int)Height, true, windowHandle, User32.GetDC(windowHandle).DangerousGetHandle());
            var angleInterface = GRGlInterface.CreateAngle(ANGLE.AngleGetProcAddress);
            var grContext      = GRContext.CreateGl(angleInterface);
            var buffer         = ANGLE.GetFrameBuffer();
            var fbinfo         = new GRGlFramebufferInfo(buffer, ANGLE.GetFramebufferFormat());
            var backendRT      = new GRBackendRenderTarget((int)Width, (int)Height, 4, 8, fbinfo);
            var surfaceprops   = new SKSurfaceProperties(SKSurfacePropsFlags.UseDeviceIndependentFonts, SKPixelGeometry.Unknown);
            var surface        = SKSurface.Create(grContext, backendRT, GRSurfaceOrigin.BottomLeft, SKColorType.Rgba8888, null, surfaceprops);
            var canvas         = surface.Canvas;

            canvas.Clear(SKColor.Empty);
            SKPaint paint = new SKPaint();

            paint.Style       = SKPaintStyle.Fill;
            paint.IsAntialias = true;
            paint.StrokeWidth = 4;
            paint.Color       = new SKColor(0xff4285f4);
            SKRect rect = SKRect.Create(10, 10, 100, 160);

            canvas.DrawRect(rect, paint);
            SKRoundRect oval = new SKRoundRect();

            oval.SetOval(rect);
            oval.Offset(40, 80);
            paint.Color = new SKColor(0xffdb4437);
            canvas.DrawRoundRect(oval, paint);
            paint.Color = new SKColor(0xff0f9d58);
            canvas.DrawCircle(180, 50, 25, paint);
            rect.Offset(80, 50);
            paint.Color = new SKColor(0xfff4b400);
            paint.Style = SKPaintStyle.Stroke;
            canvas.DrawRoundRect(rect, 10, 10, paint);
            canvas.Flush();
            ANGLE.Swap();
            return(new HandleRef(this, windowHandle));
        }
Esempio n. 3
0
        private void CreateWindow()
        {
            var    wc = new User32.WNDCLASSEX();
            IntPtr hwnd;


            //1 register window class
            wc.cbSize      = Marshal.SizeOf(wc);
            wc.style       = User32.CS.CS_HREDRAW | User32.CS.CS_VREDRAW;
            wc.lpfnWndProc = _wndProc;
            wc.cbClsExtra  = 0;
            wc.cbWndExtra  = 0;

            wc.hInstance     = Kernel32.GetModuleHandle(null);//Kernel32.GetModuleHandle(null);
            wc.lpszClassName = "CanvasWindow";

            wc.hIcon         = User32.LoadIcon(wc.hInstance, new IntPtr((uint)User32.IDI.IDI_APPLICATION));
            wc.hCursor       = User32.LoadCursor(IntPtr.Zero, User32.IDC.IDC_ARROW);
            wc.hbrBackground = new IntPtr((uint)Win32.GDI32.COLOR.COLOR_WINDOW + 1);
            wc.lpszMenuName  = "";
            wc.hIconSm       = IntPtr.Zero;


            if (User32.RegisterClassEx(ref wc) == 0)
            {
                // throw new Exception("注册窗口类失败: " + Marshal.GetLastWin32Error());
            }

            hwnd = User32.CreateWindowEx(User32.WS_EX.WS_EX_LAYERED | User32.WS_EX.WS_EX_TOPMOST
                                         | User32.WS_EX.WS_EX_TOOLWINDOW, wc.lpszClassName, null,
                                         0, _bounds.Left, _bounds.Top,
                                         _bounds.Width, _bounds.Height, IntPtr.Zero, IntPtr.Zero, wc.hInstance, IntPtr.Zero);

            if (hwnd == IntPtr.Zero)
            {
                throw new Exception("创建窗口失败: " + Marshal.GetLastWin32Error());
            }

            _handle = hwnd;
        }