console 程序随系统启动及隐藏当前程序窗口
生活随笔
收集整理的這篇文章主要介紹了
console 程序随系统启动及隐藏当前程序窗口
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
應業務需求,程序需要與系統啟動而自動運行,故加入以下代碼,保存成 .bat文件 ,雙擊執行即可
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run" /v HuazhuPushRecord /t reg_sz /d "your app path/app.exe" /fecho "成功添加開機啟動 you app.exe"your app.exe?
?
有些時候,窗口程序需要隱藏,防止誤關閉導致程序不運行,故添加以下代碼,可避免這種情況
[DllImport("User32.dll", EntryPoint = "FindWindow")]private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);[DllImport("user32.dll", EntryPoint = "FindWindowEx")] //找子窗體 private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);[DllImport("User32.dll", EntryPoint = "SendMessage")] //用于發送信息給窗體 private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, string lParam);[DllImport("User32.dll", EntryPoint = "ShowWindow")] // private static extern bool ShowWindow(IntPtr hWnd, int type);public static void WindowHide(){Console.Title = "youappname";IntPtr ParenthWnd = new IntPtr(0);IntPtr et = new IntPtr(0);ParenthWnd = FindWindow(null, "youappname");ShowWindow(ParenthWnd, 0);//隱藏本dos窗體, 0: 后臺執行;1:正常啟動;2:最小化到任務欄;3:最大化}?
轉載于:https://www.cnblogs.com/chenhuzi/p/4917756.html
總結
以上是生活随笔為你收集整理的console 程序随系统启动及隐藏当前程序窗口的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 计算机网络入门知识大全,计算机网络基础知
- 下一篇: 后台寻路系统的大体思路与流程