• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 776
  • Last Modified:

Set Taskbar to Auto-Hide

I am writing a program and need to set the Windows taskbar to auto-hide when a button is clicked. Any idea how to do this?

Alternatively, if you can tell me how to make a window be full screen, cover the taskbar and always be on top, that would work to.

Thanks in advance.
0
strickdd
Asked:
strickdd
  • 4
  • 4
  • 4
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
You can make it fullscreen like so...

        private void Form1_Load(object sender, EventArgs e)
        {
            this.TopMost = true;
            this.FormBorderStyle = FormBorderStyle.Fixed3D;
            this.StartPosition = FormStartPosition.Manual;
            this.Location = new Point(0, 0);
            this.Width = Screen.PrimaryScreen.Bounds.Width;
            this.Height = Screen.PrimaryScreen.Bounds.Height;
        }

Or without a border...

        private void Form1_Load(object sender, EventArgs e)
        {
            this.TopMost = true;
            this.FormBorderStyle = FormBorderStyle.None;
            this.WindowState = FormWindowState.Maximized;
        }
0
 
strickddAuthor Commented:
Neither of these worked for covering the taskbar. I need to be able to prevent users from accessing anything on the taskbar. Is there a way to do this?

I was able to manually set the taskbar to auto-hide and then when I ran my program as fullscreen and topmost, i was unable to make the taskbar appear by moving to the bottom of the screen. This is more-or-less the effect I need.

Thanks

0
 
Fernando SotoCommented:
Hi strickdd;

Here is sample code to do what you want. Just remember to unhide the task window before closing the program down otherwiae the user will not have access to it.

      [DllImport("user32.dll", EntryPoint="FindWindowW",  SetLastError=true,
             CharSet=CharSet.Unicode, ExactSpelling=true,
             CallingConvention=CallingConvention.StdCall)]
      public  static extern int  FindWindowW( string lpClassName,
             string lpWindowName);

      [DllImport("user32.dll", EntryPoint="SetWindowPos",  SetLastError=true,
             CharSet=CharSet.Unicode, ExactSpelling=true,
             CallingConvention=CallingConvention.StdCall)]
      public  static extern int  SetWindowPos( int hWnd,
            int hWndInsertAfter,
            int x, int y, int cx, int cy,
            int wFlags
      );

      const int TOGGLE_HIDE = 0x80;
      const int TOGGLE_UNHIDE = 0x40;

      private int hTaskWindow;

      private void btnHide_Click(object sender, System.EventArgs e)
      {
              SetWindowPos(hTaskWindow, 0, 0, 0, 0, 0, TOGGLE_HIDE);
      }

      private void btnShow_Click(object sender, System.EventArgs e)
      {
              SetWindowPos(hTaskWindow, 0, 0, 0, 0, 0, TOGGLE_UNHIDE);
      }

      private void Form1_Load(object sender, System.EventArgs e)
      {
              hTaskWindow = FindWindowW("Shell_traywnd", "");
      }


Fernando
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Fernando SotoCommented:
You will need to add this statement to the top of the code.

using System.Runtime.InteropServices;

Fernando
0
 
strickddAuthor Commented:
I know this question was posted in the C# section but could you also give me the VB.Net code for the first part:

[DllImport("user32.dll", EntryPoint="FindWindowW",  SetLastError=true,
           CharSet=CharSet.Unicode, ExactSpelling=true,
           CallingConvention=CallingConvention.StdCall)]
     public  static extern int  FindWindowW( string lpClassName,
           string lpWindowName);

     [DllImport("user32.dll", EntryPoint="SetWindowPos",  SetLastError=true,
           CharSet=CharSet.Unicode, ExactSpelling=true,
           CallingConvention=CallingConvention.StdCall)]
     public  static extern int  SetWindowPos( int hWnd,
          int hWndInsertAfter,
          int x, int y, int cx, int cy,
          int wFlags
     );


Thanks!
0
 
Fernando SotoCommented:
Here you go strickdd;

    Private Declare Unicode Function FindWindowW Lib "user32" _
        (ByVal lpClassName As String, _
         ByVal lpWindowName As String) As Integer

    Private Declare Unicode Function SetWindowPos Lib "user32" (ByVal hWnd As Integer, _
        ByVal hWndInsertAfter As Integer, _
        ByVal x As Integer, ByVal y As Integer, ByVal cx As Integer, _
        ByVal cy As Integer, ByVal wFlags As Integer) As Integer

    Const TOGGLE_HIDE As Integer = &H80
    Const TOGGLE_UNHIDE As Integer = &H40

    Private hTaskWindow As Integer

    Private Sub btnHide_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles btnHide.Click

        SetWindowPos(hTaskWindow, 0, 0, 0, 0, 0, TOGGLE_HIDE)

    End Sub

    Private Sub btnUnHide_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles btnUnHide.Click

        SetWindowPos(hTaskWindow, 0, 0, 0, 0, 0, TOGGLE_UNHIDE)

    End Sub

    Private Sub Form1_Load(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles MyBase.Load

        hTaskWindow = FindWindowW("Shell_traywnd", "")

    End Sub


Fernando
0
 
strickddAuthor Commented:
Thanks! That worked perfectly
0
 
Fernando SotoCommented:
No problem. Glad I was able to help. :=)
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
"Neither of these worked for covering the taskbar."

Both methods worked fine for me for "covering" the taskbar.  The taskbar did not popup when it was autohiding either.

Just so you know...the User can still hit the Windows Key and bring up the Start Menu even when the TaskBar is hidden...
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Running WinXP Pro SP2.
0
 
strickddAuthor Commented:
Idle_Mind,
     The only way I could get your solution to work was if i manually set the taskbar to auto-hide, then the program would take up the whole screen and I couldn't get it to pop up still.

     I am aware that the windows menu can still pop up if the key is pressed and I am working on setting up a handle to intercept that keystroke. I will also intercept the ALT and CTRL keys to prevent task manager and other shortcuts.

Thanks for the information, it just wasn't quite what I was looking for.

strickdd
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
You can't prevent Ctrl-Alt-Del by individually trapping the Alt and Ctrl keys...
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 4
  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now