C++ How do I hide a console window on startup?

后端 未结 9 800
悲哀的现实
悲哀的现实 2021-02-01 05:43

I want to know how to hide a console window when it starts.

It\'s for a keylogger program, but it\'s not my intention to hack someone. It\'s for a littl

9条回答
  •  南旧
    南旧 (楼主)
    2021-02-01 05:43

    #include 
    ShowWindow(GetConsoleWindow(), SW_HIDE); //SW_RESTORE to bring back
    

    This will return a windows handle (HWND) to ShowWindow() which will in turn hide it. This solution is for windows systems only.

    This is the correct answer to the question, even if its not marked as it.

    edit: A possible solution/hack could be to set (in visual studio) Linker->System->SubSystem to "Windows (/SUBSYSTEM:WINDOWS)" instead of "Console (/SUBSYSTEM:CONSOLE)". This is probably not optimal however.

提交回复
热议问题