/* The following code creates a window that is not full screen
* on Pocket PC 2002 handhelds. The code was written in C# using
* the .NET compact framework and test on the Pocket PC 2002
* emulator.
*
* ** NOTE ** This will create a hung window in the .NET emulator
* but since there is no need for it in the .NET emulator...
* Use at your own risk.
*
* ** This code is presented as-is and not guaranteed to work **
*
* Written by: Craig Lubitz
* Date: May, 31, 2003
*/
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
namespace non_fullscreen
{
public class Form1 : System.Windows.Forms.Form
{
// import entry points in coredll.dll for GetForegroundWindow,
// so we can find our out window handle
[DllImport("coredll.dll", CharSet=CharSet.Auto, EntryPoint="GetForegroundWindow")]
private static extern IntPtr GetForegroundWindow();
// import entry points in coredll.dll for SetWindowLong,
// so we force our window style
[DllImport("coredll.dll", CharSet=CharSet.Auto, EntryPoint="SetWindowLong")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, uint dwNewLong);
const int GWL_STYLE = -16;
const int GWL_EXSTYLE = -20;
const uint DS_MODALFRAME = 0x80;
const uint DS_CENTER = 0x800;
const uint DS_3DLOOK = 0x4;
const uint WS_OVERLAPPED= 0x0;
const uint WS_MAXIMIZEBOX = 0x10000;
const uint WS_MINIMIZEBOX = 0x20000;
const uint WS_SYSMENU = 0x80000;
const uint WS_CAPTION = 0xC00000;
const uint WS_BORDER = 0x800000;
const uint WS_POPUP = 0x80000000;
const uint WS_VISIBLE = 0x10000000;
// import entry points in coredll.dll for SetWindowPos.
// allows us to easily move and resize the window
[DllImport("coredll.dll", CharSet=CharSet.Auto, EntryPoint="SetWindowPos")]
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags);
const int SWP_NOSIZE = 0x1;
const int SWP_NOMOVE = 0x2;
const int SWP_NOZORDER = 0x4;
const int SWP_DRAWFRAME = 0x20;
public Form1()
{
this.ClientSize = new System.Drawing.Size(106, 55);
this.Text = "not full screen";
this.Activated += new
System.EventHandler(this.Form1_Activated);
}
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Activated(object sender, System.EventArgs e)
{
// I found overriding the Form Activated event works the best
IntPtr l_HwndFocus = new IntPtr(); // handle to our window
l_HwndFocus = GetForegroundWindow(); // get the handle to our window
// force the new window settings
SetWindowLong(l_HwndFocus, GWL_STYLE, DS_CENTER|WS_POPUP|WS_CAPTION|
WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_SYSMENU|WS_VISIBLE);
// even though we forced the Min/Max buttons, they do not show up for some reason
// I’m open to ideas as how to make that happen.
// position the window, otherwise it takes up the client area and the menu bar (optional)
SetWindowPos(l_HwndFocus, (IntPtr)0, 10, 50, 200, 150, SWP_NOZORDER|SWP_DRAWFRAME);
// your wild idea goes here
}
}
}