hiding TaskBar and FormWindowState.Maximized

  • Thread starter Rüdiger Kardel
  • Start date
R

Rüdiger Kardel

this one is driving me crazy:

I'm just porting an old app from CF 1.0 (VS2003) to CF 2.0 (VS2008)
OS CE 4.2

as in the past I'm hiding the taskbar with:

public static void TaskbarOff()
{
int h = FindWindow("HHTaskBar", "");
ShowWindow(h, SW_HIDE);
EnableWindow(h, false);
}

and afterwards the form is resized:

public void Fullscreen(Form form)
{
form.Capture = true;
IntPtr hwnd = GetCapture();
form.Capture = false;
form.WindowState = FormWindowState.Maximized; // ** here's the problem **
SetWindowPos(hwnd,
SetWindowPosZOrder.HWND_TOPMOST, 0, 0,
Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height, 0);
form.Update();
}

when we use "FormWindowState.Normal" everything works as expected.
Using "FormWindowState.Maximized" the area of the hidden taskbar is not used
by the form.
Even moving the taskbar out of the screen area did not help.

What's wrong with the above code? Did work as expected under CF1.
It seems that the behavior of
"form.WindowState = FormWindowState.Maximized;"
changed from CF1 to CF2.
Is there an alternative to prevent the user from moving forms around?

regards
Ruediger
 
A

arnodieter

Hello Rüdiger (are you German?).
Enclosed is a code snippet that works für CE5.0 and VS2008 using CF2.0.
Your forms must have:
- minizebox = false
-maximizebox = false
-formborderstyle = none
This works for me.

public static void HideTaskBar()
{
// updated : 03.09.2008 ard/ar:fr MC70
if (Environment.OSVersion.ToString().IndexOf("5.1") == -1)
{
// MC1000
//detect taskbar height
int taskbarHeight = Screen.PrimaryScreen.Bounds.Height -
Screen.PrimaryScreen.WorkingArea.Height;
// move the task bar south by taskbar height so that it's not visible any
longer
IntPtr iptrTB = FindWindow("HHTaskBar", null);
MoveWindow(iptrTB, 0, Screen.PrimaryScreen.Bounds.Height,
Screen.PrimaryScreen.Bounds.Width, taskbarHeight, false);
}
}
public static void HideTaskBar()
{
// updated : 03.09.2008 ard/ar:fr MC70
if (Environment.OSVersion.ToString().IndexOf("5.1") == -1)
{
// MC1000
//detect taskbar height
int taskbarHeight = Screen.PrimaryScreen.Bounds.Height -
Screen.PrimaryScreen.WorkingArea.Height;
// move the task bar south by taskbar height so that it's not visible any
longer
IntPtr iptrTB = FindWindow("HHTaskBar", null);
MoveWindow(iptrTB, 0, Screen.PrimaryScreen.Bounds.Height,
Screen.PrimaryScreen.Bounds.Width, taskbarHeight, false);
}
}
public static void RestoreTaskBar()
{
if (Environment.OSVersion.ToString().IndexOf("5.1") == -1)
{
// fr MC1000
//detect taskbar height
int taskbarHeight = Screen.PrimaryScreen.Bounds.Height -
Screen.PrimaryScreen.WorkingArea.Height;
// move the task bar to orig. position
IntPtr iptrTB = FindWindow("HHTaskBar", null);
MoveWindow(iptrTB, 0, Screen.PrimaryScreen.Bounds.Height - taskbarHeight,
Screen.PrimaryScreen.Bounds.Width, taskbarHeight, false);
}
}
[DllImport("coredll.dll", SetLastError = true)]
public static extern IntPtr FindWindow(string _ClassName, string
_WindowName);
[DllImport("coredll.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetWindowPos(IntPtr hwnd, int hwnd2, int x, int y,
int cx, int cy, SWP uFlags);
[DllImport("coredll.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool MoveWindow(IntPtr hWnd, int x, int y, int cx, int
cy, bool repaint);

HTH arno (aus der Pfalz)
 
R

Rüdiger Kardel

Hello Arno,
Hello Rüdiger (are you German?).
yes - from Kiel
Enclosed is a code snippet that works für CE5.0 and VS2008 using CF2.0.
Your forms must have:
- minizebox = false
-maximizebox = false
-formborderstyle = none
This works for me.

The problem is: at least all forms of that solution do have a borderstyle
set to FixedSingle. Often the caption of a form is used to display some
information. Changing the FormBorderstyle would mean: touch , redesign and
retest every single form. That could only be plan C or D (but for the moment
I see me ending up that way)

I would call that a bug:
FormWindowState.Normal covers the hole screen and
FormWindowState.Maximized leaves out the rectangle of the moved taskbar.

anyhow: thanks for your input
and have a nice weekend

Ruediger
public static void HideTaskBar()
{
// updated : 03.09.2008 ard/ar:fr MC70
if (Environment.OSVersion.ToString().IndexOf("5.1") == -1)
{
// MC1000
//detect taskbar height
int taskbarHeight = Screen.PrimaryScreen.Bounds.Height -
Screen.PrimaryScreen.WorkingArea.Height;
// move the task bar south by taskbar height so that it's not visible any
longer
IntPtr iptrTB = FindWindow("HHTaskBar", null);
MoveWindow(iptrTB, 0, Screen.PrimaryScreen.Bounds.Height,
Screen.PrimaryScreen.Bounds.Width, taskbarHeight, false);
}
}
public static void HideTaskBar()
{
// updated : 03.09.2008 ard/ar:fr MC70
if (Environment.OSVersion.ToString().IndexOf("5.1") == -1)
{
// MC1000
//detect taskbar height
int taskbarHeight = Screen.PrimaryScreen.Bounds.Height -
Screen.PrimaryScreen.WorkingArea.Height;
// move the task bar south by taskbar height so that it's not visible any
longer
IntPtr iptrTB = FindWindow("HHTaskBar", null);
MoveWindow(iptrTB, 0, Screen.PrimaryScreen.Bounds.Height,
Screen.PrimaryScreen.Bounds.Width, taskbarHeight, false);
}
}
public static void RestoreTaskBar()
{
if (Environment.OSVersion.ToString().IndexOf("5.1") == -1)
{
// fr MC1000
//detect taskbar height
int taskbarHeight = Screen.PrimaryScreen.Bounds.Height -
Screen.PrimaryScreen.WorkingArea.Height;
// move the task bar to orig. position
IntPtr iptrTB = FindWindow("HHTaskBar", null);
MoveWindow(iptrTB, 0, Screen.PrimaryScreen.Bounds.Height - taskbarHeight,
Screen.PrimaryScreen.Bounds.Width, taskbarHeight, false);
}
}
[DllImport("coredll.dll", SetLastError = true)]
public static extern IntPtr FindWindow(string _ClassName, string
_WindowName);
[DllImport("coredll.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetWindowPos(IntPtr hwnd, int hwnd2, int x, int
y, int cx, int cy, SWP uFlags);
[DllImport("coredll.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool MoveWindow(IntPtr hWnd, int x, int y, int cx,
int cy, bool repaint);

HTH arno (aus der Pfalz)

Rüdiger Kardel said:
this one is driving me crazy:

I'm just porting an old app from CF 1.0 (VS2003) to CF 2.0 (VS2008)
OS CE 4.2

as in the past I'm hiding the taskbar with:

public static void TaskbarOff()
{
int h = FindWindow("HHTaskBar", "");
ShowWindow(h, SW_HIDE);
EnableWindow(h, false);
}

and afterwards the form is resized:

public void Fullscreen(Form form)
{
form.Capture = true;
IntPtr hwnd = GetCapture();
form.Capture = false;
form.WindowState = FormWindowState.Maximized; // ** here's the problem
**
SetWindowPos(hwnd,
SetWindowPosZOrder.HWND_TOPMOST, 0, 0,
Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height, 0);
form.Update();
}

when we use "FormWindowState.Normal" everything works as expected.
Using "FormWindowState.Maximized" the area of the hidden taskbar is not
used by the form.
Even moving the taskbar out of the screen area did not help.

What's wrong with the above code? Did work as expected under CF1.
It seems that the behavior of
"form.WindowState = FormWindowState.Maximized;"
changed from CF1 to CF2.
Is there an alternative to prevent the user from moving forms around?

regards
Ruediger
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top