Exemplo n.º 1
0
        private static int RegisterClass()
        {
            Win32.WNDCLASSEX wcex = new Win32.WNDCLASSEX
            {
                style = Win32.ClassStyles.DoubleClicks
            };

            wcex.cbSize        = (uint)Marshal.SizeOf(wcex);
            wcex.lpfnWndProc   = WndProc;
            wcex.cbClsExtra    = 0;
            wcex.cbWndExtra    = 0;
            wcex.hIcon         = Win32.LoadIcon(IntPtr.Zero, (IntPtr)Win32.IDI_APPLICATION);
            wcex.hCursor       = Win32.LoadCursor(IntPtr.Zero, (int)Win32.IDC_ARROW);
            wcex.hIconSm       = IntPtr.Zero;
            wcex.hbrBackground = (IntPtr)(Win32.COLOR_WINDOW + 1);
            wcex.lpszMenuName  = null;
            wcex.lpszClassName = ClassName;

            if (Win32.RegisterClassEx(ref wcex) == 0)
            {
                Win32.MessageBox(IntPtr.Zero, "RegisterClassEx failed", AppName, (int)(Win32.MB_OK | Win32.MB_ICONEXCLAMATION | Win32.MB_SETFOREGROUND));
                return(0);
            }
            return(1);
        }
Exemplo n.º 2
0
        public MessageWindow()
        {
            _wndProc = WndProc;
            handlers = new Dictionary <Win32.WindowMessages, Action <IntPtr, Win32.WindowMessages, IntPtr, IntPtr> >();
            var wnd = new Win32.WNDCLASSEX
            {
                cbSize        = (uint)Marshal.SizeOf <Win32.WNDCLASSEX>(),
                hInstance     = Process.GetCurrentProcess().Handle,
                lpszClassName = WndClass,
                lpfnWndProc   = _wndProc
            };

            Win32.RegisterClassEx(ref wnd);

            WindowHandle = Win32.CreateWindowEx(Win32.WindowStylesEx.WS_EX_LEFT, WndClass, WndClass,
                                                Win32.WindowStyles.WS_OVERLAPPED, 0, 0, 0, 0, Win32.HWND_MESSAGE, IntPtr.Zero, IntPtr.Zero,
                                                IntPtr.Zero);
        }
        /// <summary>
        /// Creates the render context provider. Must also create the OpenGL extensions.
        /// </summary>
        /// <param name="openGLVersion">The desired OpenGL version.</param>
        /// <param name="gl">The OpenGL context.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="bitDepth">The bit depth.</param>
        /// <param name="parameter">The parameter</param>
        /// <returns></returns>
        public override bool Create(OpenGLVersion openGLVersion, OpenGL gl, int width, int height, int bitDepth, object parameter)
        {
            //  Call the base.
            base.Create(openGLVersion, gl, width, height, bitDepth, parameter);

            //	Create a new window class, as basic as possible.
            Win32.WNDCLASSEX wndClass = new Win32.WNDCLASSEX();
            wndClass.Init();
            wndClass.style         = Win32.ClassStyles.HorizontalRedraw | Win32.ClassStyles.VerticalRedraw | Win32.ClassStyles.OwnDC;
            wndClass.lpfnWndProc   = wndProcDelegate;
            wndClass.cbClsExtra    = 0;
            wndClass.cbWndExtra    = 0;
            wndClass.hInstance     = IntPtr.Zero;
            wndClass.hIcon         = IntPtr.Zero;
            wndClass.hCursor       = IntPtr.Zero;
            wndClass.hbrBackground = IntPtr.Zero;
            wndClass.lpszMenuName  = null;
            wndClass.lpszClassName = "SharpGLRenderWindow";
            wndClass.hIconSm       = IntPtr.Zero;
            Win32.RegisterClassEx(ref wndClass);

            //	Create the window. Position and size it.
            windowHandle = Win32.CreateWindowEx(0,
                                                "SharpGLRenderWindow",
                                                "",
                                                Win32.WindowStyles.WS_CLIPCHILDREN | Win32.WindowStyles.WS_CLIPSIBLINGS | Win32.WindowStyles.WS_POPUP,
                                                0, 0, width, height,
                                                IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);

            //	Get the window device context.
            deviceContextHandle = Win32.GetDC(windowHandle);

            //	Setup a pixel format.
            Win32.PIXELFORMATDESCRIPTOR pfd = new Win32.PIXELFORMATDESCRIPTOR();
            pfd.Init();
            pfd.nVersion     = 1;
            pfd.dwFlags      = Win32.PFD_DRAW_TO_WINDOW | Win32.PFD_SUPPORT_OPENGL | Win32.PFD_DOUBLEBUFFER;
            pfd.iPixelType   = Win32.PFD_TYPE_RGBA;
            pfd.cColorBits   = (byte)bitDepth;
            pfd.cDepthBits   = 16;
            pfd.cStencilBits = 8;
            pfd.iLayerType   = Win32.PFD_MAIN_PLANE;

            //	Match an appropriate pixel format
            int iPixelformat;

            if ((iPixelformat = Win32.ChoosePixelFormat(deviceContextHandle, pfd)) == 0)
            {
                return(false);
            }

            //	Sets the pixel format
            if (Win32.SetPixelFormat(deviceContextHandle, iPixelformat, pfd) == 0)
            {
                return(false);
            }

            //	Create the render context.
            renderContextHandle = Win32.wglCreateContext(deviceContextHandle);

            //  Make the context current.
            MakeCurrent();

            //  Update the context if required.
            UpdateContextVersion(gl);

            //  Return success.
            return(true);
        }
        /// <summary>
        /// Creates the render context provider. Must also create the OpenGL extensions.
        /// </summary>
        /// <param name="openGLVersion">The desired OpenGL version.</param>
        /// <param name="gl">The OpenGL context.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="bitDepth">The bit depth.</param>
        /// <param name="parameter">The parameter</param>
        /// <returns></returns>
        public override bool Create(OpenGLVersion openGLVersion, OpenGL gl, int width, int height, int bitDepth, object parameter)
        {
            //  Call the base.
            base.Create(openGLVersion, gl, width, height, bitDepth, parameter);

            //	Create a new window class, as basic as possible.                
            Win32.WNDCLASSEX wndClass = new Win32.WNDCLASSEX();
            wndClass.Init();
		    wndClass.style			= Win32.ClassStyles.HorizontalRedraw | Win32.ClassStyles.VerticalRedraw | Win32.ClassStyles.OwnDC;
            wndClass.lpfnWndProc    = wndProcDelegate;
		    wndClass.cbClsExtra		= 0;
		    wndClass.cbWndExtra		= 0;
		    wndClass.hInstance		= IntPtr.Zero;
		    wndClass.hIcon			= IntPtr.Zero;
		    wndClass.hCursor		= IntPtr.Zero;
		    wndClass.hbrBackground	= IntPtr.Zero;
		    wndClass.lpszMenuName	= null;
		    wndClass.lpszClassName	= "SharpGLRenderWindow";
		    wndClass.hIconSm		= IntPtr.Zero;
		    Win32.RegisterClassEx(ref wndClass);
            	
		    //	Create the window. Position and size it.
		    windowHandle = Win32.CreateWindowEx(0,
					      "SharpGLRenderWindow",
					      "",
					      Win32.WindowStyles.WS_CLIPCHILDREN | Win32.WindowStyles.WS_CLIPSIBLINGS | Win32.WindowStyles.WS_POPUP,
					      0, 0, width, height,
					      IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);

		    //	Get the window device context.
		    deviceContextHandle = Win32.GetDC(windowHandle);

		    //	Setup a pixel format.
		    Win32.PIXELFORMATDESCRIPTOR pfd = new Win32.PIXELFORMATDESCRIPTOR();
            pfd.Init();
		    pfd.nVersion = 1;
		    pfd.dwFlags = Win32.PFD_DRAW_TO_WINDOW | Win32.PFD_SUPPORT_OPENGL | Win32.PFD_DOUBLEBUFFER;
		    pfd.iPixelType = Win32.PFD_TYPE_RGBA;
		    pfd.cColorBits = (byte)bitDepth;
		    pfd.cDepthBits = 16;
		    pfd.cStencilBits = 8;
		    pfd.iLayerType = Win32.PFD_MAIN_PLANE;
		
		    //	Match an appropriate pixel format 
		    int iPixelformat;
		    if((iPixelformat = Win32.ChoosePixelFormat(deviceContextHandle, pfd)) == 0 )
			    return false;

		    //	Sets the pixel format
            if (Win32.SetPixelFormat(deviceContextHandle, iPixelformat, pfd) == 0)
		    {
			    return false;
		    }

		    //	Create the render context.
            renderContextHandle = Win32.wglCreateContext(deviceContextHandle);
            
            //  Make the context current.
            MakeCurrent();

            //  Update the context if required.
            UpdateContextVersion(gl);

            //  Return success.
            return true;
        }
Exemplo n.º 5
0
        private bool CreateWindowPane(int x, int y, int w, int h, bool fs)
        {
            windowSize = new Vec2d(w, h);
            windowPos  = new Vec2d(x, y);

            mWndProcDelegate = MyWndProc;
            Win32.WNDCLASSEX wcex = new Win32.WNDCLASSEX
            {
                style         = (int)Win32.ClassStyles.CS_DBLCLKS,
                lpfnWndProc   = Marshal.GetFunctionPointerForDelegate(mWndProcDelegate),
                lpszClassName = CLASS_NAME,
                cbSize        = Marshal.SizeOf(typeof(Win32.WNDCLASSEX)),
                cbClsExtra    = 0,
                cbWndExtra    = 0,
                hIcon         = Win32.LoadIcon(IntPtr.Zero, (IntPtr)Win32.SystemIcons.IDI_APPLICATION),
                hCursor       = Win32.LoadCursor(IntPtr.Zero, (int)Win32.IDC_ARROW),
                hIconSm       = IntPtr.Zero,
                hbrBackground = (IntPtr)(Win32.COLOR_WINDOW + 1),
                lpszMenuName  = null
            };

            ushort regReturn = Win32.RegisterClassEx(ref wcex);

            if (regReturn == 0)
            {
                return(false);
            }

            uint dwExStyle = (uint)(Win32.WindowStylesEx.WS_EX_APPWINDOW | Win32.WindowStylesEx.WS_EX_WINDOWEDGE);
            uint dwStyle   = (uint)(Win32.WindowStyles.WS_CAPTION | Win32.WindowStyles.WS_SYSMENU | Win32.WindowStyles.WS_VISIBLE);

            if (fs)
            {
                dwExStyle = 0;
                dwStyle   = (uint)(Win32.WindowStyles.WS_VISIBLE | Win32.WindowStyles.WS_POPUP);
                IntPtr hmon = Win32.MonitorFromWindow(m_hWnd, Win32.MONITOR_DEFAULTTONEAREST);
                Win32.MonitorInfoEx mon_info = new Win32.MonitorInfoEx();
                mon_info.Size = (int)Marshal.SizeOf(mon_info);
                if (!Win32.GetMonitorInfo(hmon, ref mon_info))
                {
                    return(false);
                }
                windowSize  = new Vec2d(mon_info.Monitor.Right, mon_info.Monitor.Bottom);
                windowPos.X = 0;
                windowPos.Y = 0;
            }

            Win32.RECT rWndRect = new Win32.RECT(0, 0, (int)windowSize.X, (int)windowSize.Y);
            Win32.AdjustWindowRectEx(ref rWndRect, dwStyle, false, dwExStyle);
            int width  = rWndRect.Right - rWndRect.Left;
            int height = rWndRect.Bottom - rWndRect.Top;

            m_hWnd = Win32.CreateWindowEx(
                dwExStyle,
                regReturn,
                Title,
                dwStyle,
                (int)windowPos.X,
                (int)windowPos.Y,
                width,
                height,
                IntPtr.Zero,
                IntPtr.Zero,
                wcex.hInstance,
                IntPtr.Zero);

            mapKeys[0x00] = KeyUtil.Key.NONE;
            mapKeys[0x41] = KeyUtil.Key.A; mapKeys[0x42] = KeyUtil.Key.B; mapKeys[0x43] = KeyUtil.Key.C; mapKeys[0x44] = KeyUtil.Key.D; mapKeys[0x45] = KeyUtil.Key.E;
            mapKeys[0x46] = KeyUtil.Key.F; mapKeys[0x47] = KeyUtil.Key.G; mapKeys[0x48] = KeyUtil.Key.H; mapKeys[0x49] = KeyUtil.Key.I; mapKeys[0x4A] = KeyUtil.Key.J;
            mapKeys[0x4B] = KeyUtil.Key.K; mapKeys[0x4C] = KeyUtil.Key.L; mapKeys[0x4D] = KeyUtil.Key.M; mapKeys[0x4E] = KeyUtil.Key.N; mapKeys[0x4F] = KeyUtil.Key.O;
            mapKeys[0x50] = KeyUtil.Key.P; mapKeys[0x51] = KeyUtil.Key.Q; mapKeys[0x52] = KeyUtil.Key.R; mapKeys[0x53] = KeyUtil.Key.S; mapKeys[0x54] = KeyUtil.Key.T;
            mapKeys[0x55] = KeyUtil.Key.U; mapKeys[0x56] = KeyUtil.Key.V; mapKeys[0x57] = KeyUtil.Key.W; mapKeys[0x58] = KeyUtil.Key.X; mapKeys[0x59] = KeyUtil.Key.Y;
            mapKeys[0x5A] = KeyUtil.Key.Z;

            mapKeys[(int)Win32.VK.F1] = KeyUtil.Key.F1; mapKeys[(int)Win32.VK.F2] = KeyUtil.Key.F2; mapKeys[(int)Win32.VK.F3] = KeyUtil.Key.F3; mapKeys[(int)Win32.VK.F4] = KeyUtil.Key.F4;
            mapKeys[(int)Win32.VK.F5] = KeyUtil.Key.F5; mapKeys[(int)Win32.VK.F6] = KeyUtil.Key.F6; mapKeys[(int)Win32.VK.F7] = KeyUtil.Key.F7; mapKeys[(int)Win32.VK.F8] = KeyUtil.Key.F8;
            mapKeys[(int)Win32.VK.F9] = KeyUtil.Key.F9; mapKeys[(int)Win32.VK.F10] = KeyUtil.Key.F10; mapKeys[(int)Win32.VK.F11] = KeyUtil.Key.F11; mapKeys[(int)Win32.VK.F12] = KeyUtil.Key.F12;

            mapKeys[(int)Win32.VK.DOWN]   = KeyUtil.Key.DOWN; mapKeys[(int)Win32.VK.LEFT] = KeyUtil.Key.LEFT; mapKeys[(int)Win32.VK.RIGHT] = KeyUtil.Key.RIGHT; mapKeys[(int)Win32.VK.UP] = KeyUtil.Key.UP;
            mapKeys[(int)Win32.VK.RETURN] = KeyUtil.Key.ENTER;             //mapKeys[VK_RETURN] = KeyUtil.Key.RETURN;

            mapKeys[(int)Win32.VK.BACK]   = KeyUtil.Key.BACK; mapKeys[(int)Win32.VK.ESCAPE] = KeyUtil.Key.ESCAPE; mapKeys[(int)Win32.VK.RETURN] = KeyUtil.Key.ENTER; mapKeys[(int)Win32.VK.PAUSE] = KeyUtil.Key.PAUSE;
            mapKeys[(int)Win32.VK.SCROLL] = KeyUtil.Key.SCROLL; mapKeys[(int)Win32.VK.TAB] = KeyUtil.Key.TAB; mapKeys[(int)Win32.VK.DELETE] = KeyUtil.Key.DEL; mapKeys[(int)Win32.VK.HOME] = KeyUtil.Key.HOME;
            mapKeys[(int)Win32.VK.END]    = KeyUtil.Key.END; mapKeys[(int)Win32.VK.PRIOR] = KeyUtil.Key.PGUP; mapKeys[(int)Win32.VK.NEXT] = KeyUtil.Key.PGDN; mapKeys[(int)Win32.VK.INSERT] = KeyUtil.Key.INS;
            mapKeys[(int)Win32.VK.SHIFT]  = KeyUtil.Key.SHIFT; mapKeys[(int)Win32.VK.CONTROL] = KeyUtil.Key.CTRL;
            mapKeys[(int)Win32.VK.SPACE]  = KeyUtil.Key.SPACE;

            mapKeys[0x30] = KeyUtil.Key.K0; mapKeys[0x31] = KeyUtil.Key.K1; mapKeys[0x32] = KeyUtil.Key.K2; mapKeys[0x33] = KeyUtil.Key.K3; mapKeys[0x34] = KeyUtil.Key.K4;
            mapKeys[0x35] = KeyUtil.Key.K5; mapKeys[0x36] = KeyUtil.Key.K6; mapKeys[0x37] = KeyUtil.Key.K7; mapKeys[0x38] = KeyUtil.Key.K8; mapKeys[0x39] = KeyUtil.Key.K9;

            mapKeys[(int)Win32.VK.NUMPAD0]  = KeyUtil.Key.NP0; mapKeys[(int)Win32.VK.NUMPAD1] = KeyUtil.Key.NP1; mapKeys[(int)Win32.VK.NUMPAD2] = KeyUtil.Key.NP2; mapKeys[(int)Win32.VK.NUMPAD3] = KeyUtil.Key.NP3; mapKeys[(int)Win32.VK.NUMPAD4] = KeyUtil.Key.NP4;
            mapKeys[(int)Win32.VK.NUMPAD5]  = KeyUtil.Key.NP5; mapKeys[(int)Win32.VK.NUMPAD6] = KeyUtil.Key.NP6; mapKeys[(int)Win32.VK.NUMPAD7] = KeyUtil.Key.NP7; mapKeys[(int)Win32.VK.NUMPAD8] = KeyUtil.Key.NP8; mapKeys[(int)Win32.VK.NUMPAD9] = KeyUtil.Key.NP9;
            mapKeys[(int)Win32.VK.MULTIPLY] = KeyUtil.Key.NP_MUL; mapKeys[(int)Win32.VK.ADD] = KeyUtil.Key.NP_ADD; mapKeys[(int)Win32.VK.DIVIDE] = KeyUtil.Key.NP_DIV; mapKeys[(int)Win32.VK.SUBTRACT] = KeyUtil.Key.NP_SUB; mapKeys[(int)Win32.VK.DECIMAL] = KeyUtil.Key.NP_DECIMAL;

            return(true);
        }
Exemplo n.º 6
0
        private void RegisterWindowClass()
        {
            Win32.WNDCLASSEX wndClass = new Win32.WNDCLASSEX();
            wndClass.cbSize = (uint)Marshal.SizeOf(wndClass);
            wndClass.hInstance = Win32.GetModuleHandle(null);
            wndClass.lpfnWndProc = Win32.DefaultWindowProc;
            wndClass.lpszClassName = WindowClass;
            wndClass.hCursor = Win32.LoadCursor(IntPtr.Zero, Win32.IDC_ARROW);

            Win32.RegisterClassEx(ref wndClass);
        }