wince c# 建立案頭捷徑 自動啟動 只運行一次 全螢幕顯示

來源:互聯網
上載者:User

標籤:des   blog   io   ar   os   sp   for   on   div   

using System;using System.Linq;using System.Collections.Generic;using System.Text;using System.Runtime.InteropServices;using System.Drawing;using System.Windows.Forms;using Microsoft.Win32;using System.IO;namespace SingleXZ{    class FullScreenClass    {        public static string CodePath = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase;//擷取當前應用程式完整路徑        public const int SPI_SETWORKAREA = 47;        public const int SPI_GETWORKAREA = 48;        public const int SW_HIDE = 0x00;        public const int SW_SHOW = 0x0001;        public const int SPIF_UPDATEINIFILE = 0x01;        public const int WM_CLOSE = 0x10;        [DllImport("coredll.dll", EntryPoint = "FindWindow")]        private static extern IntPtr FindWindow(string lpWindowName, string lpClassName);        [DllImport("coredll.dll", EntryPoint = "ShowWindow")]        private static extern bool ShowWindow(IntPtr hwnd, int nCmdShow);        [DllImport("coredll.dll", EntryPoint = "SystemParametersInfo")]        private static extern int SystemParametersInfo(int uAction, int uParam, ref Rectangle lpvParam, int fuWinIni);        [DllImport("coredll.dll", EntryPoint = "SystemParametersInfo")]        private static extern bool IsWindowVisible(IntPtr hwnd);        [DllImport("coredll.dll", EntryPoint = "PostMessage")]        public static extern int PostMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);        [DllImport("coredll.dll", EntryPoint = "CreateMutex", SetLastError = true)]        public static extern IntPtr CreateMutex(IntPtr lpMutexAttributes, bool InitialOwner, string MutexName);        [DllImport("coredll.dll", EntryPoint = "ReleaseMutex", SetLastError = true)]        public static extern bool ReleaseMutex(IntPtr hMutex);        private const int ERROR_ALREADY_EXISTS = 0183;         /// <summary>        /// 設定全屏或取消全屏        /// </summary>        /// <param name="fullscreen">true:全屏 false:恢複</param>        /// <param name="rectOld">設定的時候,此參數返回原始大小,恢複時用此參數設定恢複</param>        /// <returns>設定結果</returns>        public static bool SetFullScreen(bool fullscreen, ref Rectangle rectOld)        {            IntPtr Hwnd = FindWindow("HHTaskBar", null);            if (Hwnd == IntPtr.Zero) return false;            if (fullscreen)            {                ShowWindow(Hwnd, SW_HIDE);                Rectangle rectFull = Screen.PrimaryScreen.Bounds;                SystemParametersInfo(SPI_GETWORKAREA, 0, ref rectOld, SPIF_UPDATEINIFILE);//get                SystemParametersInfo(SPI_SETWORKAREA, 0, ref rectFull, SPIF_UPDATEINIFILE);//set            }            else            {                ShowWindow(Hwnd, SW_SHOW);                SystemParametersInfo(SPI_SETWORKAREA, 0, ref rectOld, SPIF_UPDATEINIFILE);            }            return true;        }        //public static bool SetFullScreen(bool fullscreen, ref Rectangle rectOld)        //{        //    IntPtr Hwnd = FindWindow("HHTaskBar", null);        //    if (Hwnd == IntPtr.Zero) return false;        //    if (fullscreen)        //    {        //        ShowWindow(Hwnd, SW_HIDE);        //    }        //    else        //    {        //        ShowWindow(Hwnd, SW_SHOW);        //    }        //    return true;        //}        public static void KillMessageBox(string sCaption)        {            IntPtr ptr = FindWindow(null, sCaption);            if (ptr != IntPtr.Zero)                PostMessage(ptr, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);        }        //程式只能運行一次        public static bool IsExist()        {            string strAppName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;            IntPtr hMutex = CreateMutex(IntPtr.Zero, true, strAppName);            if (hMutex == IntPtr.Zero)                throw new ApplicationException("Failure creating mutex: " + Marshal.GetLastWin32Error().ToString("X"));            if (Marshal.GetLastWin32Error() == ERROR_ALREADY_EXISTS)            {                ReleaseMutex(hMutex);                return true;            }            return false;        }        public static void AutoRun()        {            using (RegistryKey key = Registry.LocalMachine.OpenSubKey("init", true))            {                key.SetValue("Launch70", CodePath);            }        }        public static void DesktopLink()        {            string PathGPRSTrue = @"/Windows/Desktop/app.exe.lnk";            if (!File.Exists(PathGPRSTrue))            {                //File.Copy(PathGPRS, PathGPRSTrue, true);                try                {                    string text = (CodePath.Length + 2).ToString() + "#\"" + CodePath + "\"";                    byte[] buf = new byte[text.Length];                    buf = System.Text.Encoding.GetEncoding(936).GetBytes(text.Substring(0, text.Length));                    FileStream fs = new FileStream(PathGPRSTrue, FileMode.CreateNew);                    fs.Write(buf, 0, buf.Length);                    fs.Close();                    fs = null;                }                catch (System.Exception ex)                {                }            }        }    }}

  

wince c# 建立案頭捷徑 自動啟動 只運行一次 全螢幕顯示

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.