如何隐藏控制台窗口并弹出一个屏幕?

时间:2022-07-17 00:21:23

I've used the Matlab Compiler to create a .exe file. The program takes 15 sec to start. I would like to hide the console window, and display a custom splash screen. How can I do that?

我使用Matlab编译器创建了一个.exe文件。这个程序需要15秒才能启动。我想隐藏控制台窗口,并显示一个自定义的启动屏幕。我怎么做呢?

3 个解决方案

#1


2  

With regard to making a splash screen, there are a few submissions on The MathWorks File Exchange that deal with just that:

关于创建一个启动屏幕,在MathWorks文件交换中有一些提交文件可以处理以下问题:

I haven't used any of them personally, but they should at the very least give you some guidance if you want to design your own splash screen functionality.

我还没有亲自使用过它们中的任何一个,但是如果您想设计自己的splash界面功能,它们至少应该给您一些指导。

#2


0  

You can write a "launcher" program.

您可以编写一个“启动程序”。

The launcher would

发射器将

  1. Create the splash screen
  2. 创建一个启动画面
  3. Launch the matlab exe using CreateProcess() or some other method.
  4. 使用CreateProcess()或其他方法启动matlab exe。
  5. Wait until the matlab exe has opened properly
  6. 等待matlab exe正确打开
  7. Exit
  8. 退出

The tricky bit will be determining when the matlab program has started. One method might be to call EnumWindows() and GetWindowText() in a loop, looking for the matlab window title, but you might be able to come up with a better way given knowledge of what the matlab program does.

棘手的一点是确定matlab程序何时开始。一种方法可能是在循环中调用EnumWindows()和GetWindowText(),查找matlab窗口的标题,但是如果了解matlab程序的功能,您可能可以找到更好的方法。

You would probably need to keep checking that the matlab process hasn't died, in case something goes wrong.

您可能需要继续检查matlab进程是否没有死,以防出现问题。

#3


0  

To get rid of the DOS window, use mcc -e instead of mcc -m. See "MATLAB Compiler > Function Reference" in the online documentation, brought up by doc(). You might not want to do that, though: the DOS window is the output of last resort; it's where unhandled exceptions, core dumps, and other diagnostic output go. At least make it an option so you can have a debug build that has the DOS window.

要摆脱DOS窗口,使用mcc -e而不是mcc -m。在在线文档中看到“MATLAB编译器>功能参考”,由doc()提出。但是,您可能不想这样做:DOS窗口是last resort的输出;这是未处理的异常、核心转储和其他诊断输出的位置。至少让它成为一个选项,这样您就可以有一个具有DOS窗口的调试构建。

In my experience, the startup overhead for a compiled standalone Matlab program happens before control transfers to user M-code, so a splash screen will need to be done in an external program, or hooked in to the C wrapper that mcc generates. You could use Michael J's suggestion of writing a launcher. You're not looking for matlab.exe or a Matlab desktop window, though, since this is a standalone app. To detect when the Matlab program has started, have your M-code write out a little temp file as the first thing the program does, and have your launcher watch for that.

根据我的经验,一个编译的独立的Matlab程序的启动开销是在控制转移到用户m代码之前发生的,所以一个启动屏幕需要在一个外部程序中完成,或者连接到mcc生成的C包装器。你可以用Michael J的建议来写一个发射器。你不是在找matlab。exe或Matlab桌面窗口,因为这是一个独立的应用程序。要检测Matlab程序何时启动,请让你的M-code写一个小的临时文件,作为程序的第一件事,并让你的启动程序监视它。

#1


2  

With regard to making a splash screen, there are a few submissions on The MathWorks File Exchange that deal with just that:

关于创建一个启动屏幕,在MathWorks文件交换中有一些提交文件可以处理以下问题:

I haven't used any of them personally, but they should at the very least give you some guidance if you want to design your own splash screen functionality.

我还没有亲自使用过它们中的任何一个,但是如果您想设计自己的splash界面功能,它们至少应该给您一些指导。

#2


0  

You can write a "launcher" program.

您可以编写一个“启动程序”。

The launcher would

发射器将

  1. Create the splash screen
  2. 创建一个启动画面
  3. Launch the matlab exe using CreateProcess() or some other method.
  4. 使用CreateProcess()或其他方法启动matlab exe。
  5. Wait until the matlab exe has opened properly
  6. 等待matlab exe正确打开
  7. Exit
  8. 退出

The tricky bit will be determining when the matlab program has started. One method might be to call EnumWindows() and GetWindowText() in a loop, looking for the matlab window title, but you might be able to come up with a better way given knowledge of what the matlab program does.

棘手的一点是确定matlab程序何时开始。一种方法可能是在循环中调用EnumWindows()和GetWindowText(),查找matlab窗口的标题,但是如果了解matlab程序的功能,您可能可以找到更好的方法。

You would probably need to keep checking that the matlab process hasn't died, in case something goes wrong.

您可能需要继续检查matlab进程是否没有死,以防出现问题。

#3


0  

To get rid of the DOS window, use mcc -e instead of mcc -m. See "MATLAB Compiler > Function Reference" in the online documentation, brought up by doc(). You might not want to do that, though: the DOS window is the output of last resort; it's where unhandled exceptions, core dumps, and other diagnostic output go. At least make it an option so you can have a debug build that has the DOS window.

要摆脱DOS窗口,使用mcc -e而不是mcc -m。在在线文档中看到“MATLAB编译器>功能参考”,由doc()提出。但是,您可能不想这样做:DOS窗口是last resort的输出;这是未处理的异常、核心转储和其他诊断输出的位置。至少让它成为一个选项,这样您就可以有一个具有DOS窗口的调试构建。

In my experience, the startup overhead for a compiled standalone Matlab program happens before control transfers to user M-code, so a splash screen will need to be done in an external program, or hooked in to the C wrapper that mcc generates. You could use Michael J's suggestion of writing a launcher. You're not looking for matlab.exe or a Matlab desktop window, though, since this is a standalone app. To detect when the Matlab program has started, have your M-code write out a little temp file as the first thing the program does, and have your launcher watch for that.

根据我的经验,一个编译的独立的Matlab程序的启动开销是在控制转移到用户m代码之前发生的,所以一个启动屏幕需要在一个外部程序中完成,或者连接到mcc生成的C包装器。你可以用Michael J的建议来写一个发射器。你不是在找matlab。exe或Matlab桌面窗口,因为这是一个独立的应用程序。要检测Matlab程序何时启动,请让你的M-code写一个小的临时文件,作为程序的第一件事,并让你的启动程序监视它。