Author Topic: How can I hide accoreconsole.exe window?  (Read 1802 times)

0 Members and 1 Guest are viewing this topic.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
How can I hide accoreconsole.exe window?
« on: April 08, 2016, 05:35:28 AM »
How can I hide accoreconsole.exe console window?
Code - C#: [Select]
  1. using cad = Autodesk.AutoCAD.ApplicationServices.Core.Application;
  2. ...
  3. if(null != cad.MainWindow) // is null here
  4.  cad.MainWindow.Visible = false;
I don't see similar properties or methods in the Process.GetCurrentProcess() also.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: How can I hide accoreconsole.exe window?
« Reply #1 on: April 08, 2016, 05:51:39 AM »
Hi,

The ProcessStartInfo type has a WindowStyle property.

You can do something like this with the AcCoreConsole process:
Code - C#: [Select]
  1. process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
Speaking English as a French Frog

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: How can I hide accoreconsole.exe window?
« Reply #2 on: April 08, 2016, 06:20:19 AM »
Thank you for your answer, gile.

This property changing doesn't help if accoreconsole.exe already is launched (my code is located in the .net extension of AutoCAD). Also I've tried to use FreeConsole() winapi function:

Code - C#: [Select]
  1. [DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
  2. static extern bool FreeConsole();
At this case console window will be closed (instead of hiding) successfully, then code of static constructor of my class and of Initialize() method will work successfully too, but right after it the accoreconsole process will be finished (even without calling the Terminate() and ProcessExit):

Code - C#: [Select]
  1. using System;
  2. using System.ServiceModel;
  3. using cad = Autodesk.AutoCAD.ApplicationServices.Core.Application;
  4. using Autodesk.AutoCAD.ApplicationServices;
  5. using Autodesk.AutoCAD.Runtime;
  6. using System.Runtime.InteropServices;
  7. using System.Diagnostics;
  8.  
  9. [assembly: ExtensionApplication(typeof(Bushman.CAD.Services.ExtensionApplication))]
  10.  
  11. namespace Bushman.CAD.Services {
  12.     public class ExtensionApplication : IExtensionApplication {
  13.  
  14.         [DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
  15.         static extern bool FreeConsole();
  16.  
  17.         static ServiceHost host = null;
  18.  
  19.         static ExtensionApplication() {
  20.             try {
  21.                 FreeConsole();
  22.                 host = new ServiceHost(typeof(MyService));
  23.                 host.Open();
  24.                 AppDomain.CurrentDomain.ProcessExit += ProcessExit;
  25.             }
  26.             catch (System.Exception ex) {
  27.                 Document doc = cad.DocumentManager.MdiActiveDocument;
  28.                 if (null != doc) doc.Editor.WriteMessage(ex.Message);
  29.             }
  30.         }
  31.  
  32.         private static void ProcessExit(object sender, EventArgs e) {
  33.             if (null != host) host.Close();
  34.         }
  35.  
  36.         public void Initialize() {
  37.             string status = null == host ? "null" : host.State.ToString();
  38.             Document doc = cad.DocumentManager.MdiActiveDocument;
  39.             if (null != doc) doc.Editor.WriteMessage("\nHost status: {0}.\n", status);
  40.         }
  41.  
  42.         public void Terminate() {
  43.             // Nothing is here.
  44.         }
  45.     }
  46. }
« Last Edit: April 08, 2016, 06:32:35 AM by Andrey Bushman »