[英]C++ simple hooks and hiding command prompt
I am new to C++ and have just learned about hooks so I have a C++ program which runs a function when a KeyEvent occurs: 我是C ++的新手,刚刚学习了钩子,所以我有一个C ++程序,它在KeyEvent发生时运行一个函数:
LRESULT WINAPI KeyEvent(int nCode, WPARAM wParam, LPARAM lParam)
{
//Do C++ stuff
}
This is my only hook so far. 到目前为止,这是我唯一的钩子。
However I want to hide the command prompt which pops up when executing my code. 但是我想隐藏执行代码时弹出的命令提示符。
I was told I can use this snippet to hide it: 我被告知我可以使用这个片段来隐藏它:
HWND Stealth;
AllocConsole();
Stealth = FindWindowA("ConsoleWindowClass", NULL);
ShowWindow(Stealth,0);
However if I place it in the hook it will not hide the prompt until a key is pressed (not ideal) and if I place it above the hook (near top of program) I get an error... 但是,如果我将它放在钩子中,它将不会隐藏提示,直到按下一个键(不理想),如果我把它放在钩子上方(程序顶部附近)我得到一个错误...
So my question is, is there any other types of hooks which I can place the snippet in to hide the command prompt once program is ran? 所以我的问题是,是否还有其他类型的钩子,我可以在程序运行后将片段放入隐藏命令提示符中? -Or is there any other way like my snippet to hide command prompts which I can use? - 或者有其他方式像我的片段隐藏我可以使用的命令提示吗?
Thanks alot. 非常感谢。
You can always use the WM_CREATE msg to do what you want. 您始终可以使用WM_CREATE消息来执行您想要的操作。 And inside it call: 在里面打电话:
if(MSG == WM_CREATE)
ShowWindow( GetConsoleWindow(), SW_HIDE );
That might work for you, and if you need the console again just change SW_HIDE to SW_SHOW. 这可能适合您,如果您再次需要控制台,只需将SW_HIDE更改为SW_SHOW即可。
Usually you would use a switch statement for the message type. 通常,您将对消息类型使用switch语句。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.