Esempio n. 1
0
 private Cache()
 {
     this.ProcessHandle     = Kernel32Methods.GetCurrentProcess();
     this.AppIconHandle     = User32Helpers.LoadIcon(IntPtr.Zero, SystemIcon.IDI_APPLICATION);
     this.ArrowCursorHandle = User32Helpers.LoadCursor(IntPtr.Zero, SystemCursor.IDC_ARROW);
     this.WindowClassExSize = (uint)Marshal.SizeOf <WindowClassEx>();
 }
Esempio n. 2
0
        public void Init(string title, int width, int height, bool vsync, bool fullscreen)
        {
            if (m_Info != null)
            {
                throw new InvalidOperationException("application already initialized");
            }
            m_Info = new ApplicationInfo
            {
                Title      = title,
                Width      = width,
                Height     = height,
                VSync      = vsync,
                FullScreen = fullscreen
            };

            IntPtr hInstance = Kernel32Methods.GetModuleHandle(IntPtr.Zero);

            m_WindowProc = WindowProc;
            var wc = new WindowClassEx
            {
                Size                  = (uint)Marshal.SizeOf <WindowClassEx>(),
                ClassName             = "MainWindow",
                CursorHandle          = User32Helpers.LoadCursor(IntPtr.Zero, SystemCursor.IDC_ARROW),
                IconHandle            = User32Helpers.LoadIcon(IntPtr.Zero, SystemIcon.IDI_APPLICATION),
                Styles                = WindowClassStyles.CS_HREDRAW | WindowClassStyles.CS_VREDRAW | WindowClassStyles.CS_OWNDC,
                BackgroundBrushHandle = new IntPtr((int)StockObject.WHITE_BRUSH),
                WindowProc            = m_WindowProc,
                InstanceHandle        = hInstance
            };

            if (User32Methods.RegisterClassEx(ref wc) == 0)
            {
                throw new ExternalException("window registration failed");
            }

            NetCoreEx.Geometry.Rectangle size = new NetCoreEx.Geometry.Rectangle(0, 0, width, height);
            User32Methods.AdjustWindowRectEx(ref size, WindowStyles.WS_OVERLAPPEDWINDOW | WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS,
                                             false, WindowExStyles.WS_EX_APPWINDOW | WindowExStyles.WS_EX_WINDOWEDGE);

            m_hWnd = User32Methods.CreateWindowEx(WindowExStyles.WS_EX_APPWINDOW | WindowExStyles.WS_EX_WINDOWEDGE, wc.ClassName,
                                                  title, WindowStyles.WS_OVERLAPPEDWINDOW | WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS,
                                                  (int)CreateWindowFlags.CW_USEDEFAULT, (int)CreateWindowFlags.CW_USEDEFAULT,
                                                  size.Right + (-size.Left), size.Bottom + (-size.Top), IntPtr.Zero, IntPtr.Zero, hInstance, IntPtr.Zero);

            if (m_hWnd == IntPtr.Zero)
            {
                throw new ExternalException("window creation failed");
            }

            User32Methods.ShowWindow(m_hWnd, ShowWindowCommands.SW_SHOWNORMAL);
            User32Methods.UpdateWindow(m_hWnd);

            Context.Instance.Init(m_hWnd, m_Info);
            Renderer.Instance.Init();
            Script.LuaEngine.Instance.Init();
        }
Esempio n. 3
0
        /// <summary>
        /// The get icon handle.
        /// </summary>
        /// <returns>
        /// The <see cref="IntPtr"/>.
        /// </returns>
        private IntPtr GetIconHandle()
        {
            IntPtr?hIcon = NativeMethods.LoadIconFromFile(this.mHostConfig.HostIconFile);

            if (hIcon == null)
            {
                return(User32Helpers.LoadIcon(IntPtr.Zero, SystemIcon.IDI_APPLICATION));
            }

            return(hIcon.Value);
        }
Esempio n. 4
0
        static int Main(string[] args)
        {
            var instanceHandle = Kernel32Methods.GetModuleHandle(IntPtr.Zero);

            var wc = new WindowClassEx
            {
                Size                  = (uint)Marshal.SizeOf <WindowClassEx>(),
                ClassName             = "MainWindow",
                CursorHandle          = User32Helpers.LoadCursor(IntPtr.Zero, SystemCursor.IDC_ARROW),
                IconHandle            = User32Helpers.LoadIcon(IntPtr.Zero, SystemIcon.IDI_APPLICATION),
                Styles                = WindowClassStyles.CS_HREDRAW | WindowClassStyles.CS_VREDRAW,
                BackgroundBrushHandle = new IntPtr((int)StockObject.WHITE_BRUSH),
                WindowProc            = WindowProc,
                InstanceHandle        = instanceHandle
            };

            var resReg = User32Methods.RegisterClassEx(ref wc);

            if (resReg == 0)
            {
                Console.Error.WriteLine("registration failed");
                return(-1);
            }

            var hwnd = User32Methods.CreateWindowEx(WindowExStyles.WS_EX_APPWINDOW,
                                                    wc.ClassName, "Hello", WindowStyles.WS_OVERLAPPEDWINDOW,
                                                    (int)CreateWindowFlags.CW_USEDEFAULT, (int)CreateWindowFlags.CW_USEDEFAULT,
                                                    (int)CreateWindowFlags.CW_USEDEFAULT, (int)CreateWindowFlags.CW_USEDEFAULT,
                                                    IntPtr.Zero, IntPtr.Zero, instanceHandle, IntPtr.Zero);

            if (hwnd == IntPtr.Zero)
            {
                Console.Error.WriteLine("window creation failed");
                return(-1);
            }

            User32Methods.ShowWindow(hwnd, ShowWindowCommands.SW_SHOWNORMAL);
            User32Methods.UpdateWindow(hwnd);

            Message msg;
            int     res;

            while ((res = User32Methods.GetMessage(out msg, IntPtr.Zero, 0, 0)) != 0)
            {
                User32Methods.TranslateMessage(ref msg);
                User32Methods.DispatchMessage(ref msg);
            }

            return(res);
        }
Esempio n. 5
0
        /// <summary>
        /// The get icon handle.
        /// </summary>
        /// <returns>
        /// The <see cref="IntPtr"/>.
        /// </returns>
        private IntPtr GetIconHandle()
        {
            var hIcon = NativeMethods.LoadIconFromFile(mHostConfig.HostIconFile);

            return(hIcon ?? User32Helpers.LoadIcon(IntPtr.Zero, SystemIcon.IDI_APPLICATION));
        }