예제 #1
0
        IntPtr CreateWindow(int x, int y, int width, int height, string title, GameWindowFlags options, DisplayDevice device, IntPtr parentHandle)
        {
            // Use win32 to create the native window.
            // Keep in mind that some construction code runs in the WM_CREATE message handler.

            // The style of a parent window is different than that of a child window.
            // Note: the child window should always be visible, even if the parent isn't.
            WindowStyle         style    = 0;
            ExtendedWindowStyle ex_style = 0;

            if (parentHandle == IntPtr.Zero)
            {
                style   |= WindowStyle.OverlappedWindow | WindowStyle.ClipChildren;
                ex_style = ParentStyleEx;
            }
            else
            {
                style   |= WindowStyle.Visible | WindowStyle.Child | WindowStyle.ClipSiblings;
                ex_style = ChildStyleEx;
            }

            // Find out the final window rectangle, after the WM has added its chrome (titlebar, sidebars etc).
            Win32Rectangle rect = new Win32Rectangle();

            rect.left = x; rect.top = y; rect.right = x + width; rect.bottom = y + height;
            Functions.AdjustWindowRectEx(ref rect, style, false, ex_style);
            // Create the window class that we will use for this window.
            // The current approach is to register a new class for each top-level WinGLWindow we create.
            if (!class_registered)
            {
                ExtendedWindowClass wc = new ExtendedWindowClass();
                wc.Size      = ExtendedWindowClass.SizeInBytes;
                wc.Style     = DefaultClassStyle;
                wc.Instance  = Instance;
                wc.WndProc   = WindowProcedureDelegate;
                wc.ClassName = ClassName;
                wc.Icon      = Icon != null ? Icon.Handle : IntPtr.Zero;
#warning "This seems to resize one of the 'large' icons, rather than using a small icon directly (multi-icon files). Investigate!"
                wc.IconSm = Icon != null ? new Icon(Icon, 16, 16).Handle : IntPtr.Zero;
                wc.Cursor = Functions.LoadCursor(CursorName.Arrow);
                ushort atom = Functions.RegisterClassEx(ref wc);
                if (atom == 0)
                {
                    throw new PlatformException(String.Format("Failed to register window class. Error: {0}", Marshal.GetLastWin32Error()));
                }
                class_registered = true;
            }

            IntPtr window_name = Marshal.StringToHGlobalAuto(title);
            IntPtr handle      = Functions.CreateWindowEx(
                ex_style, ClassName, window_name, style,
                rect.left, rect.top, rect.Width, rect.Height,
                parentHandle, IntPtr.Zero, Instance, IntPtr.Zero);
            if (handle == IntPtr.Zero)
            {
                throw new PlatformException(String.Format("Failed to create window. Error: {0}", Marshal.GetLastWin32Error()));
            }
            return(handle);
        }
예제 #2
0
        internal static Win32Rectangle From(Rectangle value)
        {
            Win32Rectangle rect = new Win32Rectangle();

            rect.left   = value.Left;
            rect.right  = value.Right;
            rect.top    = value.Top;
            rect.bottom = value.Bottom;
            return(rect);
        }
예제 #3
0
        internal static Win32Rectangle From(Size value)
        {
            Win32Rectangle rect = new Win32Rectangle();

            rect.left   = 0;
            rect.right  = value.Width;
            rect.top    = 0;
            rect.bottom = value.Height;
            return(rect);
        }
예제 #4
0
        private IntPtr CreateWindow(int x, int y, int width, int height, string title, GameWindowFlags options, DisplayDevice device, IntPtr parentHandle)
        {
            WindowStyle         windowStyle1 = WindowStyle.Overlapped;
            WindowStyle         windowStyle2;
            ExtendedWindowStyle extendedWindowStyle;

            if (parentHandle == IntPtr.Zero)
            {
                windowStyle2        = windowStyle1 | WindowStyle.TiledWindow | WindowStyle.ClipChildren;
                extendedWindowStyle = ExtendedWindowStyle.WindowEdge | ExtendedWindowStyle.ApplicationWindow;
            }
            else
            {
                windowStyle2        = windowStyle1 | WindowStyle.Child | WindowStyle.Visible | WindowStyle.ClipSiblings;
                extendedWindowStyle = ExtendedWindowStyle.Left;
            }
            Win32Rectangle lpRect = new Win32Rectangle();

            lpRect.left   = x;
            lpRect.top    = y;
            lpRect.right  = x + width;
            lpRect.bottom = y + height;
            Functions.AdjustWindowRectEx(ref lpRect, windowStyle2, false, extendedWindowStyle);
            if (!this.class_registered)
            {
                if ((int)Functions.RegisterClassEx(ref new ExtendedWindowClass()
                {
                    Size = ExtendedWindowClass.SizeInBytes,
                    Style = ClassStyle.OwnDC,
                    Instance = this.Instance,
                    WndProc = this.WindowProcedureDelegate,
                    ClassName = this.ClassName,
                    Icon = this.Icon != null ? this.Icon.Handle : IntPtr.Zero,
                    IconSm = this.Icon != null ? new Icon(this.Icon, 16, 16).Handle : IntPtr.Zero,
                    Cursor = Functions.LoadCursor(CursorName.Arrow)
                }) == 0)
                {
                    throw new PlatformException(string.Format("Failed to register window class. Error: {0}", (object)Marshal.GetLastWin32Error()));
                }
                this.class_registered = true;
            }
            IntPtr WindowName = Marshal.StringToHGlobalAuto(title);
            IntPtr windowEx   = Functions.CreateWindowEx(extendedWindowStyle, this.ClassName, WindowName, windowStyle2, lpRect.left, lpRect.top, lpRect.Width, lpRect.Height, parentHandle, IntPtr.Zero, this.Instance, IntPtr.Zero);

            if (windowEx == IntPtr.Zero)
            {
                throw new PlatformException(string.Format("Failed to create window. Error: {0}", (object)Marshal.GetLastWin32Error()));
            }
            else
            {
                return(windowEx);
            }
        }
예제 #5
0
        void GrabCursor()
        {
            Win32Rectangle rect = Win32Rectangle.From(ClientRectangle);
            Point          pos  = PointToScreen(new Point(rect.left, rect.top));

            rect.left = pos.X;
            rect.top  = pos.Y;
            if (!Functions.ClipCursor(ref rect))
            {
                Debug.WriteLine(String.Format("Failed to grab cursor. Error: {0}",
                                              Marshal.GetLastWin32Error()));
            }
        }
예제 #6
0
        void GrabCursor()
        {
            Point          pos  = PointToScreen(new Point(ClientRectangle.X, ClientRectangle.Y));
            Win32Rectangle rect = new Win32Rectangle();

            rect.left   = pos.X;
            rect.right  = pos.X + ClientRectangle.Width;
            rect.top    = pos.Y;
            rect.bottom = pos.Y + ClientRectangle.Height;
            if (!Functions.ClipCursor(ref rect))
            {
                Debug.WriteLine(String.Format("Failed to grab cursor. Error: {0}",
                                              Marshal.GetLastWin32Error()));
            }
        }
예제 #7
0
 internal static extern bool AdjustWindowRectEx(ref Win32Rectangle lpRect, WindowStyle dwStyle, bool bMenu, ExtendedWindowStyle dwExStyle);
예제 #8
0
 internal static extern bool AdjustWindowRect([In, Out] ref Win32Rectangle lpRect, WindowStyle dwStyle, bool bMenu);
예제 #9
0
 internal extern static bool GetClientRect(IntPtr windowHandle, out Win32Rectangle clientRectangle);
예제 #10
0
파일: API.cs 프로젝트: jpbruyere/opentk
 internal extern static BOOL GetWindowRect(HWND windowHandle, out Win32Rectangle windowRectangle);
예제 #11
0
파일: API.cs 프로젝트: jpbruyere/opentk
 internal extern static BOOL GetClientRect(HWND windowHandle, out Win32Rectangle clientRectangle);
예제 #12
0
파일: API.cs 프로젝트: jpbruyere/opentk
 internal static Win32Rectangle From(Size value)
 {
     Win32Rectangle rect = new Win32Rectangle();
     rect.left = 0;
     rect.right = value.Width;
     rect.top = 0;
     rect.bottom = value.Height;
     return rect;
 }
예제 #13
0
파일: Functions.cs 프로젝트: tanis2000/FEZ
 public static bool ClipCursor(ref Win32Rectangle rcClip);
예제 #14
0
 internal static bool GetWindowRect(IntPtr windowHandle, out Win32Rectangle windowRectangle);
예제 #15
0
        IntPtr CreateWindow(int x, int y, int width, int height, string title, GameWindowFlags options, DisplayDevice device, IntPtr parentHandle)
        {
            // Use win32 to create the native window.
            // Keep in mind that some construction code runs in the WM_CREATE message handler.

            // The style of a parent window is different than that of a child window.
            // Note: the child window should always be visible, even if the parent isn't.
            WindowStyle style = 0;
            ExtendedWindowStyle ex_style = 0;
            if (parentHandle == IntPtr.Zero)
            {
                style |= WindowStyle.OverlappedWindow | WindowStyle.ClipChildren;
                ex_style = ParentStyleEx;
            }
            else
            {
                style |= WindowStyle.Visible | WindowStyle.Child | WindowStyle.ClipSiblings;
                ex_style = ChildStyleEx;
            }

            // Find out the final window rectangle, after the WM has added its chrome (titlebar, sidebars etc).
            Win32Rectangle rect = new Win32Rectangle();
            rect.left = x; rect.top = y; rect.right = x + width; rect.bottom = y + height;
            Functions.AdjustWindowRectEx(ref rect, style, false, ex_style);

            // Create the window class that we will use for this window.
            // The current approach is to register a new class for each top-level WinGLWindow we create.
            if (!class_registered)
            {
                ExtendedWindowClass wc = new ExtendedWindowClass();
                wc.Size = ExtendedWindowClass.SizeInBytes;
                wc.Style = DefaultClassStyle;
                wc.Instance = Instance;
                wc.WndProc = WindowProcedureDelegate;
                wc.ClassName = ClassName;
                wc.Icon = Icon != null ? Icon.Handle : IntPtr.Zero;
#warning "This seems to resize one of the 'large' icons, rather than using a small icon directly (multi-icon files). Investigate!"
                wc.IconSm = Icon != null ? new Icon(Icon, 16, 16).Handle : IntPtr.Zero;
                wc.Cursor = Functions.LoadCursor(CursorName.Arrow);
                ushort atom = Functions.RegisterClassEx(ref wc);

                if (atom == 0)
                    throw new PlatformException(String.Format("Failed to register window class. Error: {0}", Marshal.GetLastWin32Error()));

                class_registered = true;
            }

            IntPtr window_name = Marshal.StringToHGlobalAuto(title);
            IntPtr handle = Functions.CreateWindowEx(
                ex_style, ClassName, window_name, style,
                rect.left, rect.top, rect.Width, rect.Height,
                parentHandle, IntPtr.Zero, Instance, IntPtr.Zero);

            if (handle == IntPtr.Zero)
                throw new PlatformException(String.Format("Failed to create window. Error: {0}", Marshal.GetLastWin32Error()));

            return handle;
        }
예제 #16
0
파일: API.cs 프로젝트: shahid-pk/opentk
 internal static extern bool AdjustWindowRectEx(ref Win32Rectangle lpRect, WindowStyle dwStyle, bool bMenu, ExtendedWindowStyle dwExStyle);
예제 #17
0
파일: Functions.cs 프로젝트: tanis2000/FEZ
 internal static bool GetClientRect(IntPtr windowHandle, out Win32Rectangle clientRectangle);
예제 #18
0
 private IntPtr CreateWindow(int x, int y, int width, int height, string title, GameWindowFlags options, DisplayDevice device, IntPtr parentHandle)
 {
   WindowStyle windowStyle1 = WindowStyle.Overlapped;
   WindowStyle windowStyle2;
   ExtendedWindowStyle extendedWindowStyle;
   if (parentHandle == IntPtr.Zero)
   {
     windowStyle2 = windowStyle1 | WindowStyle.TiledWindow | WindowStyle.ClipChildren;
     extendedWindowStyle = ExtendedWindowStyle.WindowEdge | ExtendedWindowStyle.ApplicationWindow;
   }
   else
   {
     windowStyle2 = windowStyle1 | WindowStyle.Child | WindowStyle.Visible | WindowStyle.ClipSiblings;
     extendedWindowStyle = ExtendedWindowStyle.Left;
   }
   Win32Rectangle lpRect = new Win32Rectangle();
   lpRect.left = x;
   lpRect.top = y;
   lpRect.right = x + width;
   lpRect.bottom = y + height;
   Functions.AdjustWindowRectEx(ref lpRect, windowStyle2, false, extendedWindowStyle);
   if (!this.class_registered)
   {
     if ((int) Functions.RegisterClassEx(ref new ExtendedWindowClass()
     {
       Size = ExtendedWindowClass.SizeInBytes,
       Style = ClassStyle.OwnDC,
       Instance = this.Instance,
       WndProc = this.WindowProcedureDelegate,
       ClassName = this.ClassName,
       Icon = this.Icon != null ? this.Icon.Handle : IntPtr.Zero,
       IconSm = this.Icon != null ? new Icon(this.Icon, 16, 16).Handle : IntPtr.Zero,
       Cursor = Functions.LoadCursor(CursorName.Arrow)
     }) == 0)
       throw new PlatformException(string.Format("Failed to register window class. Error: {0}", (object) Marshal.GetLastWin32Error()));
     this.class_registered = true;
   }
   IntPtr WindowName = Marshal.StringToHGlobalAuto(title);
   IntPtr windowEx = Functions.CreateWindowEx(extendedWindowStyle, this.ClassName, WindowName, windowStyle2, lpRect.left, lpRect.top, lpRect.Width, lpRect.Height, parentHandle, IntPtr.Zero, this.Instance, IntPtr.Zero);
   if (windowEx == IntPtr.Zero)
     throw new PlatformException(string.Format("Failed to create window. Error: {0}", (object) Marshal.GetLastWin32Error()));
   else
     return windowEx;
 }
예제 #19
0
 public static bool ClipCursor(ref Win32Rectangle rcClip);
예제 #20
0
파일: API.cs 프로젝트: jpbruyere/opentk
 internal static Win32Rectangle From(Rectangle value)
 {
     Win32Rectangle rect = new Win32Rectangle();
     rect.left = value.Left;
     rect.right = value.Right;
     rect.top = value.Top;
     rect.bottom = value.Bottom;
     return rect;
 }
예제 #21
0
파일: Functions.cs 프로젝트: tanis2000/FEZ
 internal static bool GetWindowRect(IntPtr windowHandle, out Win32Rectangle windowRectangle);
예제 #22
0
 void GrabCursor()
 {
     Point pos = PointToScreen(new Point(ClientRectangle.X, ClientRectangle.Y));
     Win32Rectangle rect = new Win32Rectangle();
     rect.left = pos.X;
     rect.right = pos.X + ClientRectangle.Width;
     rect.top = pos.Y;
     rect.bottom = pos.Y + ClientRectangle.Height;
     if (!Functions.ClipCursor(ref rect))
         Debug.WriteLine(String.Format("Failed to grab cursor. Error: {0}",
             Marshal.GetLastWin32Error()));
 }
예제 #23
0
파일: API.cs 프로젝트: jpbruyere/opentk
 internal static extern bool AdjustWindowRectEx(
     ref Win32Rectangle lpRect,
     WindowStyle dwStyle,
     [MarshalAs(UnmanagedType.Bool)] bool bMenu,
     ExtendedWindowStyle dwExStyle);