GCC / C how to hide console window?

前端 未结 1 1425
温柔的废话
温柔的废话 2020-12-16 00:42

****C newbie alert**** How do I compile a C app so that it runs without showing a console window on Windows? I\'m using Windows XP and GCC 3.4.5 (mingw-vista special r3).

相关标签:
1条回答
  • 2020-12-16 01:01

    Retain the -mwindows flag and use this:

    #include <windows.h>
    #include <process.h>
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
        execl("c:\\winnt\\system32\\notepad.exe", 0);
        // or: execlp("notepad.exe", 0);
    }
    

    Note: you need the full path for the execl() call but not the execlp() one.

    Edit: a brief explanation of why this works - using system() starts a shell (like cmd.exe) to exec the command which produces a console window. Using execl doesn't.

    0 讨论(0)
提交回复
热议问题