2011-04-22 6 views
1

C#에서 Windows 7 작업 표시 줄을 숨기려고합니다. 내가 this 포스트와 this 페이지를 보았지만, 모든 지시를 따른 후에, 나는 밑바닥에 평범한 검은 색 막대기로 끝났다. 나는 이런 작업 표시 줄의 클래스 결국 : 나는 문제의 스크린 샷을 촬영했습니다C# Windows 7에서 작업 표시 줄 숨기기

using System; 
using System.Collections.Generic; 
using System.Text; 
using System.Runtime.InteropServices; 
using System.Diagnostics; 

public static class Taskbar 
{ 
    [DllImport("user32.dll")] 
    private static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count); 
    [DllImport("user32.dll", CharSet = CharSet.Auto)] 
    private static extern bool EnumThreadWindows(int threadId, EnumThreadProc pfnEnum, IntPtr lParam); 
    [DllImport("user32.dll", SetLastError = true)] 
    private static extern System.IntPtr FindWindow(string lpClassName, string lpWindowName); 
    [DllImport("user32.dll", SetLastError = true)] 
    private static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle); 
    [DllImport("user32.dll")] 
    private static extern int ShowWindow(IntPtr hwnd, int nCmdShow); 
    [DllImport("user32.dll")] 
    private static extern uint GetWindowThreadProcessId(IntPtr hwnd, out int lpdwProcessId); 

    private const int SW_HIDE = 0; 
    private const int SW_SHOW = 5; 

    private const string VistaStartMenuCaption = "Start"; 
    private static IntPtr vistaStartMenuWnd = IntPtr.Zero; 
    private delegate bool EnumThreadProc(IntPtr hwnd, IntPtr lParam); 

    public static void Show() 
    { 
     SetVisibility(true); 
    } 

    public static void Hide() 
    { 
     SetVisibility(false); 
    } 

    public static bool Visible 
    { 
     set { SetVisibility(value); } 
    } 

    private static void SetVisibility(bool show) 
    { 
     IntPtr taskBarWnd = FindWindow("Shell_TrayWnd", null); 

     IntPtr startWnd = FindWindowEx(taskBarWnd, IntPtr.Zero, "Button", "Start"); 
     if (startWnd == IntPtr.Zero) 
     { 
      startWnd = FindWindow("Button", null); 

      if (startWnd == IntPtr.Zero) 
      { 
       startWnd = GetVistaStartMenuWnd(taskBarWnd); 
      } 
     } 

     ShowWindow(taskBarWnd, show ? SW_SHOW : SW_HIDE); 
     ShowWindow(startWnd, show ? SW_SHOW : SW_HIDE); 
    } 

    private static IntPtr GetVistaStartMenuWnd(IntPtr taskBarWnd) 
    { 
     int procId; 
     GetWindowThreadProcessId(taskBarWnd, out procId); 

     Process p = Process.GetProcessById(procId); 
     if (p != null) 
     { 
      foreach (ProcessThread t in p.Threads) 
      { 
       EnumThreadWindows(t.Id, MyEnumThreadWindowsProc, IntPtr.Zero); 
      } 
     } 
     return vistaStartMenuWnd; 
    } 

    private static bool MyEnumThreadWindowsProc(IntPtr hWnd, IntPtr lParam) 
    { 
     StringBuilder buffer = new StringBuilder(256); 
     if (GetWindowText(hWnd, buffer, buffer.Capacity) > 0) 
     { 
      Console.WriteLine(buffer); 
      if (buffer.ToString() == VistaStartMenuCaption) 
      { 
       vistaStartMenuWnd = hWnd; 
       return false; 
      } 
     } 
     return true; 
    } 
} 

:

미리 감사드립니다.

+3

∞ 놀랍게도 유용한 스크린 샷 – Deanna

+0

나는 그것을 제거했습니다. 현실 확인을 위해 –

답변

1

WPF 창이있는 경우 WindowStyle을 None으로 설정하고 최대화하면 전체 화면 (작업 표시 줄을 포함)을 덮습니다. Windows Forms를 사용하는 경우 비슷한 기능이 작동 할 수도 있습니다.

+0

고마워. 원래 Windows Forms를 사용했지만 WPF가 훨씬 뛰어 났고 제안이 훌륭하게 작동 함을 알았습니다! 이 모든 것보다 훨씬 간단하고 깨끗합니다 [DLLImport ("user32")]! 원래의 (작동하지 않는) 솔루션은 한 페이지에 걸쳐있었습니다. –

+0

당신도 WinForms에서 그것을 할 수 있습니다. 그냥 전체 화면 창입니다. –

+0

나도 알아, (적어도 내 컴퓨터에서) 작업 표시 줄은 가끔 엉뚱한 시간에 무작위로 나타났습니다. –

2

시도해보십시오. 를 Shell32.dll의 4.71

버전 및 이후 작업 표시 줄의 내용을 수정할 수있는 기능을 추가

  • ITaskbarList::DeleteTab
  • 또한 pinvoke.net: ITaskbarList

    MSDN의 FROM ITaskbarList::AddTab

    • . 응용 프로그램에서 이제 작업 표시 줄 단추를 추가, 제거 및 활성화 할 수 있습니다. 항목을 활성화해도 창이 활성화되지 않습니다. 작업 표시 줄에 누를 때마다 항목이 표시됩니다.

      작업 표시 줄 수정 기능은 ITaskbarList 인터페이스 (IID_ITaskbarList)를 노출하는 COM (구성 요소 개체 모델) 개체 (CLSID_TaskbarList)로 구현됩니다. 개체를 초기화하려면 ITaskbarList :: HrInit 메서드를 호출해야합니다. 그런 다음 ITaskbarList 인터페이스의 메서드를 사용하여 작업 표시 줄의 내용을 수정할 수 있습니다.

    6

    앱을 전체 화면으로 표시하는 것이 더 적절합니다. 이처럼 작업 표시 줄의 내부를 파고하면 반드시 문제가 발생할 것입니다.

    사용자는 작업 표시 줄을 잃을 때마다 짜증을 느낄 수 있습니다. 작업 표시 줄은 사용자가 아닌 응용 프로그램에 속합니다.

    +1

    +1 – hoetz

    관련 문제