C # GUI issue in C # code

I want to disable the GUI of my exe. Ho, can I do this programmatically? there is a way to disable gui. Does user32.dll do this? Can someone give me a very short example? thanks

+4
source share
2 answers

Why would you want to do that? You better create a service application that runs in the background and, of course, without gui.

UPDATE

Here is my friend's solution: http://www.developer.com/net/net/article.php/3336751/C-Tip-Placing-Your-C-Application-in-the-System-Tray.htm

+3
source

In your startup code ( Program.cs , Main ), you create the main application window (both in Windows.Forms and in WPF). Here you can add code to get around creating any application window, perhaps using command line argument checking.

If your application is being used from a Windows service, you can check Envirnment.UserInteractive to see if you have a user. I do not know what it returns if your application is called from a service (that is: the service runs your application), but then it is easy to add a command line argument.

  [STAThread] static void Main() { // Test if any argument == "/batchmode" using upper or lowercase if (Environment.GetCommandLineArgs().Any(a => string.Equals(a, "/batchmode", StringComparison.InvariantCultureIgnoreCase)) { // Batch mode } else { // Interactive mode Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } } 

Note. This does not turn your application into a console / command line application.

+2
source

Source: https://habr.com/ru/post/1345835/


All Articles