locked
Window and Client Area Properties Workaround

    General discussion

  • Greetings all,

    Just thought I'd share my workaround for finding the screen position of the Game Window.

    In your Game derived class put this code:


    using System.Windows.Forms;

    [DllImport("user32")]
    private static extern int GetWindowRect(IntPtr handle, ref Rectangle rc);


    public Rectangle Area
    {
        get
        {
        Rectangle rect = new Rectangle();
        GetWindowRect(this.Window.Handle, ref rect);
        return rect;
        }
    }

    public Rectangle ClientArea
    {
        get
        {
        System.Drawing.Size borderSize = SystemInformation.FrameBorderSize;
        int titleBarHeight = SystemInformation.CaptionHeight;

        Rectangle rect = new Rectangle();
        GetWindowRect(this.Window.Handle, ref rect);

        rect.X += (borderSize.Width / 2) + 1;
        rect.Y += (borderSize.Height / 2) + titleBarHeight + 1;
        rect.Width = graphics.BackBufferWidth;
        rect.Height = graphics.BackBufferHeight;

        return rect;
        }
    }


    Please post any improvements.

    PS: This forum is pretty cool but it doesn't seem to have a code block insertion tool. I noticed some people have their pasted code color coded... am I missing it or did they manually color?


    Wednesday, September 6, 2006 6:36 AM

All replies

  • Yup, already did this. It's fine until you wanna put it on XBOX.(But then that should always be full screen)
    Wednesday, September 6, 2006 1:34 PM