如何最小化控制台窗口? [英] How to minimize console window?

查看:261
本文介绍了如何最小化控制台窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行C ++控制台应用程序,
一段时间,

我想最小化运行我的应用程序的窗口。

例如。我从cmd启动myApp.exe。然后在新窗口中启动。

那么可以最小化运行应用程序窗口的库是什么。

应用程序没有任何GUI

I am running a C++ console application, for some period of time,
I want to minimize the window in which my application is running.
for eg. I launch myApp.exe from cmd. Then its launched in new window.
So what are libraries which can minimize the window in which application is running.
Application doesnt have any GUI

推荐答案

我想您的应用程序正在Windows上运行(这不可移植)跨不同的操作系统)。

I suppose your application is running on Windows (this is not portable across different operating systems).

您必须首先使用 GetConsoleWindow()函数,则可以使用 ShowWindow()可以根据需要隐藏/显示它。不要忘记包含 windows.h

You have first to get handle of your Console window with GetConsoleWindow() function, then you can use ShowWindow() to hide/show it as required. Ddon't forget to include windows.h:

ShowWindow(GetConsoleWindow(), SW_MINIMIZE);

您可以使用<$代替 SW_MINIMIZE c $ c> SW_HIDE 完全隐藏它(但是应用程序刚启动时它将闪烁一次)。

Instead of SW_MINIMIZE you can use SW_HIDE to completely hide it (but it'll flash visible once when application just started).

请注意,如果您有控制流程的创建,您可以将其创建为 DETACHED_PROCESS :分离的控制台应用程序没有控制台窗口。 CreateProcess()函数还具有您可能感兴趣的其他解决方法(例如,您可以创建子进程以输出...)

Note that if you have control over process creation you can create it as DETACHED_PROCESS: a detached console application does not have a console window. CreateProcess() function has also other workarounds you may be interested in (for example you may create a child process for outputting...)

更新:作为 Patrick答案的后续操作,您可以更改子系统从控制台到Windows,然后,如果需要编写控制台,请使用 AllocConsole

UPDATE: as follow-up of Patrick's answer you may change the subsystem from Console to Windows and then, if you require to write to console, create a new one using AllocConsole:

if (AllocConsole()) {
    printf("Now I can print to console...\n");
    FreeConsole();
}

这篇关于如何最小化控制台窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆