Here is my approach to make a compact framework form fullscreen:
(You are right, you don't see ‘fullscreen’ in the screen shot, BUT the taskbar is locked!)
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace myApp{
class fullScreen
{
#region DllImports
[DllImport("coredll.dll")]
extern private static IntPtr FindWindowW(string lpClassName, string lpWindowName);
[DllImport("coredll.dll")]
extern private static int GetSystemMetrics(int nIndex);
private const int SM_CXSCREEN = 0;
private const int SM_CYSCREEN = 1;
[DllImport("coredll.dll")]
static extern bool IsWindowVisible(IntPtr hWnd);
#endregion
[DllImport("coredll.dll")]
static extern bool ShowWindow(IntPtr hWnd, uint nCmdShow);
#region WStyles
private enum WindowShowStyle : uint
{
Hide = 0,
ShowNormal = 1,
ShowMinimized = 2,
ShowMaximized = 3,
Maximize = 3,
ShowNormalNoActivate = 4,
Show = 5,
Minimize = 6,
ShowMinNoActivate = 7,
ShowNoActivate = 8,
Restore = 9,
ShowDefault = 10,
ForceMinimized = 11
}
#endregion
#region private vars
private int m_width = 240;
private int m_height = 320;
private bool m_SIP_shown = false;
#endregion
public fullScreen()
{
m_width = GetSystemMetrics(SM_CXSCREEN);
m_height = GetSystemMetrics(SM_CYSCREEN);
IntPtr hWndSipWndClass = IntPtr.Zero;
hWndSipWndClass = FindWindowW("SipWndClass", null);
if (hWndSipWndClass != IntPtr.Zero)
{
m_SIP_shown = IsWindowVisible(hWndSipWndClass);
}
GXopen();
}
private void GXopen(){
if (System.IO.File.Exists(@"\Windows\gx.dll"))
{
GX_WM gxwm = new GX_WM();
gxwm.GXopen();
}
}
private void GXclose()
{
if (System.IO.File.Exists(@"\Windows\gx.dll"))
{
GX_WM gxwm = new GX_WM();
gxwm.GXopen();
}
}
public int width
{
get
{
return m_width;
}
}
public int height
{
get
{
return m_height;
}
}
public void makeFullScreen(System.Windows.Forms.Form f)
{
f.Width = m_width;
f.Height = m_height;
f.Top = 0; f.Left = 0;
hideTaskBar(true);
showSIP(false);
}
public void Unload()
{
hideTaskBar(false);
if (m_SIP_shown)
showSIP(true);
}
public void showSIP(bool bShow)
{
IntPtr hWndSipWndClass = IntPtr.Zero;
hWndSipWndClass = FindWindowW("SipWndClass", null);
if (hWndSipWndClass != IntPtr.Zero)
{
if (bShow)
ShowWindow(hWndSipWndClass, (uint)WindowShowStyle.ShowNormal);
else
ShowWindow(hWndSipWndClass, (uint)WindowShowStyle.Minimize);
}
}
private int hideTaskBar(bool mode)
{
IntPtr hWndTaskBar = IntPtr.Zero;
if (mode)
{
hWndTaskBar = FindWindowW("HHTaskBar", null);
if (hWndTaskBar != IntPtr.Zero)
ShowWindow(hWndTaskBar, (uint)WindowShowStyle.Hide);
}
else
{
hWndTaskBar = FindWindowW("HHTaskBar", null);
if (hWndTaskBar != IntPtr.Zero)
ShowWindow(hWndTaskBar, (uint)WindowShowStyle.ShowNormal);
}
return 0;
}
}
}
The GX_WM
class:
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace myApp
{
class GX_WM {
[DllImport("gx.dll", EntryPoint="?GXCloseInput@@YAHXZ")]
extern private static Int16 GXOpenInput();
[DllImport("gx.dll", EntryPoint="?GXOpenInput@@YAHXZ")]
extern private static Int16 GXCloseInput();
public void GXopen(){
GXOpenInput();
System.Diagnostics.Debug.WriteLine("GXOpenInput()");
}
public void GXclose() {
GXCloseInput();
System.Diagnostics.Debug.WriteLine("GXCloseInput()");
}
}
}
To use the classes in your code, declare a new fullScreen
object at a central point of your app. For example, in Program.cs:
public static fullScreen fse;
The declaration is static
to enable you to use this object in all forms of your app. Then before your Run
statement, place the initialisation of the fullScreen
object. At the end of your app, it is a good way to unload the object, so it may restore the taskbar and SIP status.
static class Program
{
public static fullScreen fse;
[MTAThread]
static void Main()
{
try
{
fse = new fullScreen();
Application.Run(new MyAppForm());
}
catch (Exception ex)
{
MessageBox.Show("Sorry: " + ex.Message);
}
fse.Unload();
}
}
Now in every form you have, place the line:
Program.fse.makeFullScreen(this);
in the _Load
event or – as I do – in the form constructor after the line “InitializeComponent();
”
public myAppForm() {
if (!InitApp())
AppShutdown();
InitializeComponent();
<strong>Program.fse.makeFullScreen(this);</strong>
}
If you need to show the SIP, use:
Program.fse.showSIP(true);
If you want to have a real fullscreen app without a title bar, don't forget to set the borderstyle of your form to None. You can also change the makeFullScreen
function and do this for the form given in the argument.
Any comments or enhancements?
Have fun!
P.S.: Key catching works fine in C# with the fullscreen class (either using GXOpenInput()
or AllKeys()
), see attached C# sample.
<!-- Social Bookmarks BEGIN -->
<!-- Social Bookmarks END -->