c# 智能設備應用程序不顯示在任務欄以及最小化窗體

在c#winform應用程序中,窗體有ShowInTaskbar和FormWindowState.Minimized屬性,經過.NET Framework類庫能夠輕鬆地實現窗體不顯示在任務欄以及窗體最小化操做,而c#的智能設備.NET Compact Framework不支持這兩項,要實現着兩個功能,須要經過調用底層win32 API函數來實現,一大批Win32 底層操做的函數都存在於cordll.dll 動態連接庫中。具體實現方法: c#

首先調用Win32 的申明:using System.Runtime.InteropServices; 函數

1.窗體不顯示在任務欄 ui

            const int EXSTYLE = -20;
            const int WS_EX_NOANIMATION = 0x04000000;

            [DllImport("coredll.dll", SetLastError=true)]
            public static extern void SetWindowLong(IntPtr hWnd, int GetWindowLongParam, uint nValue);

            [DllImport("coredll.dll", SetLastError=true)]
            public static extern uint GetWindowLong(IntPtr hWnd, int nItem);

            [DllImport("coredll.dll")]
            private static extern IntPtr GetCapture();

            void NotShowInTaskbar()
            {
                  Capture = true;
                  IntPtr hwnd = GetCapture();
                  Capture = false;

                  uint style = GetWindowLong(hwnd, EXSTYLE);
                  style |= WS_EX_NOANIMATION; 
                  SetWindowLong(hwnd, EXSTYLE, style);
            }
2.最小化窗體 this

      [DllImport("coredll.dll")]
      static extern int ShowWindow(IntPtr hWnd, int nCmdShow); spa

 

      const int SW_MINIMIZED = 6;
   void  MiniMize()
orm

   {
       ShowWindow(this.Handle, SW_MINIMIZED);
   }
ast

相關文章
相關標籤/搜索