实现控制台的显示和隐藏,具体代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#include <windows.h> int main() { //获取控制台窗口句柄 HWND m_hConsole = FindWindowA("ConsoleWindowClass", NULL); //也可以这样获取控制台窗口句柄 //HWND m_hConsole = GetConsoleWindow(); //判断控制台是否可见,可见返回true if (IsWindowVisible(m_hConsole)) { //隐藏 ShowWindow(m_hConsole, SW_HIDE); } else { //显示 ShowWindow(m_hConsole, SW_SHOW); } return 0; } |