我想知道如何在控制台窗口启动时隐藏它。
这是一个键盘记录程序,但我无意破解某人。这是一个小学校项目,我想展示黑客的危险。
到目前为止,这是我的代码:
#include <cstdlib>
#include <iostream>
#include <Windows.h>
using namespace std;
int main()
{
cout << "Note. This program is only created to show the risk of being unaware of hackers." << endl;
cout << "This program should never be used to actually hack someone." << endl;
cout << "Therefore this program will never be avaiable to anyone, except me." << endl;
FreeConsole();
system("PAUSE");
return 0;
}
我看到窗口出现并在启动时立即消失。之后似乎立即打开了一个新控制台,它只是空白。 (空白是指“按任意键继续..”我想知道它是否与 system("PAUSE")
)
所以我想知道为什么它会打开一个新的控制台,而不是只创建和隐藏第一个控制台。
谢谢。 :)
最佳答案
要根据需要隐藏/显示控制台窗口,您可以使用以下函数: 可以使用 ShowWindow 隐藏/显示控制台. GetConsoleWindow检索控制台使用的窗口句柄。 IsWindowVisible可用于检查窗口(在这种情况下为控制台)是否可见。
#include <Windows.h>
void HideConsole()
{
::ShowWindow(::GetConsoleWindow(), SW_HIDE);
}
void ShowConsole()
{
::ShowWindow(::GetConsoleWindow(), SW_SHOW);
}
bool IsConsoleVisible()
{
return ::IsWindowVisible(::GetConsoleWindow()) != FALSE;
}
关于C++ 如何在启动时隐藏控制台窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18260508/