2009-12-09 23 views

回答

5

首先,您必須通過P/Invoke隱藏任務欄。這裏的C代碼,這應該是很容易to convert

HWND hwndTaskbar = ::FindWindow(_T("HHTaskBar"), NULL); 
::ShowWindow(hwndTaskbar, SW_HIDE); 

一旦你這樣做,然後使用Screen.PrimaryScreen以確定您的顯示器有多大和調整您的表格,這些尺寸。

+0

能否請您給一些C#調用這些API。對不起,我對P/Invoke不太瞭解。 – Gopinath 2009-12-10 07:18:35

+3

如果你要編寫一個CF應用程序,你將不得不學習P/Invoke - 這是無法解決的。這些非常簡單,我給了一個鏈接,讓你開始。我沒有給你魚,只有釣竿。 – ctacke 2009-12-10 13:57:15

+1

謝謝。我開始學習P/Invoke :) – Gopinath 2009-12-10 15:47:56

5

使用此代碼:

public class FullScreenEngine 
{ 
    // Fields 
    private IntPtr _hWndInputPanel; 
    private IntPtr _hWndSipButton; 
    private IntPtr _hWndTaskBar; 
    private Rectangle _desktopArea; 

    public FullScreenEngine() 
    { 
     Init(); 
    } 

    public bool SetFullScreen(bool mode) 
    { 
     try 
     { 
      if (mode) 
      { 
       if (_hWndTaskBar.ToInt64() != 0L) 
       { 
        ShowWindow(_hWndTaskBar, SW_HIDE); 
       } 
       if (_hWndInputPanel.ToInt64() != 0L) 
       { 
        ShowWindow(_hWndInputPanel, SW_HIDE); 
       } 
       if (_hWndSipButton.ToInt64() != 0L) 
       { 
        ShowWindow(_hWndSipButton, SW_HIDE); 
       } 
       WorkArea.SetWorkArea(new RECT(Screen.PrimaryScreen.Bounds)); 
      } 
      else 
      { 
       if (_hWndTaskBar.ToInt64() != 0L) 
       { 
        ShowWindow(_hWndTaskBar, SW_SHOW); 
       } 
       if (_hWndInputPanel.ToInt64() != 0L) 
       { 
        //ShowWindow(_hWndInputPanel, SW_SHOW); 
       } 
       if (_hWndSipButton.ToInt64() != 0L) 
       { 
        ShowWindow(_hWndSipButton, SW_SHOW); 
       } 
       WorkArea.SetWorkArea(new RECT(_desktopArea)); 
      } 
     } 
     catch (Exception) 
     { 
      return false; 
     } 
     return true; 
    } 

    private bool Init() 
    { 
     try 
     { 
      _desktopArea = Screen.PrimaryScreen.WorkingArea; 
      _hWndInputPanel = FindWindowW("SipWndClass", null); 
      _hWndSipButton = FindWindowW("MS_SIPBUTTON", null); 
      _hWndTaskBar = FindWindowW("HHTaskBar", null); 
     } 
     catch (Exception) 
     { 
      return false; 
     } 
     return true; 
    } 

    private const uint SW_HIDE = 0; 
    private const uint SW_SHOW = 1; 

    [DllImport("coredll.dll")] 
    private static extern int ShowWindow(IntPtr hwnd, uint command); 

    [DllImport("coredll.dll")] 
    private static extern IntPtr FindWindowW(string lpClassName, string lpWindowName); 

    // Nested Types 
    public struct RECT 
    { 
     public int Left; 
     public int Top; 
     public int Right; 
     public int Bottom; 

     public RECT(Rectangle rect) : this() 
     { 
      Left = rect.Left; 
      Right = rect.Left+rect.Width; 
      Top = rect.Top; 
      Bottom = rect.Top + rect.Height; 
     } 
    } 

    private static class WorkArea 
    { 
     [DllImport("coredll.dll")] 
     private static extern bool SystemParametersInfo(uint uAction, uint uparam, ref RECT rect, uint fuWinIni); 

     private const uint WM_SETTINGCHANGE = 0x1a; 
     const uint SPI_GETWORKAREA = 48; 
     const uint SPI_SETWORKAREA = 47; 

     public static bool SetWorkArea(RECT rect) 
     { 
      return SystemParametersInfo(SPI_SETWORKAREA, 0, ref rect, WM_SETTINGCHANGE); 
     } 

     public static RECT GetWorkArea() 
     { 
      var rect = new RECT(); 
      SystemParametersInfo(SPI_GETWORKAREA, 0, ref rect, 0); 
      return rect; 
     } 
    } 
} 
相關問題