Click here to Skip to main content
15,868,292 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
So basically my problem is that i work in unity3D, and it sadly don't have a "FullScreen Maximized" option... but i've heard/seen that you can do some DLLImport with "using System.Runtime.InteropServices;" but im not sure of what functions i need and what values i should assign to different field.

So how can i remove any window's Border (all of it) only using pure code/DLLImport?

- Thanks Jackie
Posted
Comments
Sergey Alexandrovich Kryukov 1-Jul-12 23:56pm    
Why P/Invoke? What do you think is not available with regular .NET API?
Do you need full screen or remove border? border is not removed in full screen, did you know that?
--SA
Jackie00100 2-Jul-12 8:26am    
.NET API is due to sources from unity3D not compatible... one source said that you could use DLLImport as mentioned, and i need to remove the borders to have the "Fullscreen maximized window" effect (like seen in lots of game) where you can have windows above your actual "fullscreen" window (windowed maximized mode) i did know that fullscreen still have borders but some how they're "hidden"
Sergey Alexandrovich Kryukov 2-Jul-12 15:25pm    
Those borders are hidden only because they go out of the visible screen. I developed the desktop manager where I moved all windows on a low-level, so I could clearly see it. I'm less sure about Unity, but have some reasons to suspect the situation is exactly the same...
--SA
Jackie00100 2-Jul-12 18:03pm    
So do you know any way of doing this then?
Sergey Alexandrovich Kryukov 2-Jul-12 18:14pm    
Sorry, never tried Unity, so I'm not sure... otherwise I would put an answer, not just comments.
--SA

1 solution

okay fixed this my self after finding the right imports...

EDIT:

Source code:

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace border_removal_test
{
    public partial class Form1 : Form
    {
        //Import window changing function
        [DllImport("USER32.DLL")]
        public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

        //Import find window function
        [DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
        static extern IntPtr FindWindowByCaption(IntPtr ZeroOnly, string lpWindowName);

        //Import force window draw function
        [DllImport("user32.dll")]
        static extern bool DrawMenuBar(IntPtr hWnd);

        [DllImport("user32.dll", EntryPoint = "SetWindowPos")]
        public static extern IntPtr SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int Y, int cx, int cy, int wFlags);


        private readonly string WINDOW_NAME = "Form1";  //name of the window
        private const int GWL_STYLE = -16;              //hex constant for style changing
        private const int WS_BORDER = 0x00800000;       //window with border
        private const int WS_CAPTION = 0x00C00000;      //window with a title bar
        private const int WS_SYSMENU = 0x00080000;      //window with no borders etc.
        private const int WS_MINIMIZEBOX = 0x00020000;  //window with minimizebox

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            IntPtr window = FindWindowByCaption(IntPtr.Zero, WINDOW_NAME);
            SetWindowLong(window, GWL_STYLE, WS_SYSMENU);
            SetWindowPos(window, -2, 0, 0, 800, 600, 0x0040);
            //this.WindowState = FormWindowState.Maximized;
            DrawMenuBar(window);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            IntPtr window = FindWindowByCaption(IntPtr.Zero, WINDOW_NAME);
            SetWindowLong(window, GWL_STYLE, WS_CAPTION | WS_BORDER | WS_SYSMENU | WS_MINIMIZEBOX);
            this.WindowState = FormWindowState.Normal;
            DrawMenuBar(window);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}


a simple google search on each import function will let you know how they works...
 
Share this answer
 
v2
Comments
barneyman 8-Jul-12 22:12pm    
Do you want to explain how? That way, this becomes an answer someone else can use!
Jackie00100 9-Jul-12 9:52am    
Yaeh was to tired yester day to do anything and now im lazy so just uploading source code

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900