显示/隐藏应用程序控制台 [英] show / hide the application console

查看:85
本文介绍了显示/隐藏应用程序控制台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在托管的C ++控制台应用程序中,
如何简单地显示或隐藏控制台窗口?

最好的问候.

In a managed C++ console application,
how to simply show or hide the console window ?

Best regards.

推荐答案

我尝试了以下代码:

I tried the following code :

#include "stdafx.h"
#include
 
void Utilities::showConsole(
    bool show ) {
 
    HWND hWnd = GetConsoleWindow();
    if (hWnd != 0) {
        ShowWindow( hWnd, show ? SW_SHOW : SW_HIDE);
        }
    }



GetConsoleWindow()在链接步骤解析,但ShowWindow()不能解析.



GetConsoleWindow() is resolved at link step, but ShowWindow() is not.
How to solve that ?


所以,我独自找到了解决方法.

在控制台C ++/CLI应用程序中,创建一个小的Utilities类:
Utilities.h:
So, I found alone the solution.

In a console C++/CLI application, create a small Utilities class :
Utilities.h :
public ref class Utilities abstract sealed {/* abstract sealed = static */

public:
    static void showConsole(
        bool show );
    };



Utilities.cpp:



Utilities.cpp :

//-------------------------------------
/** Utilities.cpp
    */
#include "stdafx.h"
#include "Utilities.h"
#include <windows.h>
void Utilities::showConsole(
	bool show ) {	

	HWND hWnd = GetConsoleWindow();
	if (hWnd != 0) {		
		ShowWindow( hWnd, show ? SW_SHOW : SW_HIDE);
		}
	}



并且不要忘了签入链接选项其他依赖项"父项目默认参数的继承"(然后取消关键字



And don''t forget to check in link option "Other dependencies" "herit of default parameter of parent project" (and then suppress keyword


(NOINHERIT),以便访问Windows ShowWindow的API.
效果很好.
(NOINHERIT), in order to access to windows API of ShowWindow.
It works perfectly.


这篇关于显示/隐藏应用程序控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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