Console程序后台运行
[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);
Console.Title = "printx在线"; IntPtr intptr = FindWindow(null, "printx在线"); if (intptr != IntPtr.Zero) { ShowWindow(intptr, 0);//隐藏这个窗口 }