How to remove command line from a compiled program

2019-08-15 18:57发布

I have recently started a tutorial to learn how to code GUI using Windows API and I have come upon an unexpected question which I think is kind of silly. I am using Code::Blocks with OpenWatcom compiler as default and I have created a simple GUI program compiling and linking well. The problem is when I try to launch the program, even from the release version something like the command line shows up behind the window of my program, like I tried to run it through the compile & run option of the Code::Blocks. Is there any way to remove the command line from showing up?This is how it looks like when I run it.

EDIT: It is not a problem with my main definition. This is my main definition: |

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)    

3条回答
乱世女痞
2楼-- · 2019-08-15 19:00

This is controlled by the /SUBSYSTEM linker option. It is currently set to CONSOLE and you need to change it to WINDOWS. The documentation mandates how the main needs to be changed:

Application does not require a console, probably because it creates its own windows for interaction with the user. If WinMain or wWinMain is defined for native code, or WinMain(HISTANCE *, HINSTANCE *, char *, int) or wWinMain(HINSTANCE *, HINSTANCE *, wchar_t *, int) is defined for managed code, WINDOWS is the default.

Specifically for Code::Blocks, the linker option can be changed by this process:

In Code::Blocks simply open the Project->Properties dialog, switch to the "Build Targets" tab and change the "Type" of the build targets you want to modify to "GUI Application" or "Console Application". No need to worry about the "main" function.

查看更多
放我归山
3楼-- · 2019-08-15 19:08

Instead of a main function, you need to use Win32's standard entry point WinMain:

int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow);

See: http://sol.gfxile.net/wintut/ch2.html

Or, if you can't recompile, in Windows 7 you can just do:

START myProgram {enter}

See: http://support.microsoft.com/kb/126410

查看更多
家丑人穷心不美
4楼-- · 2019-08-15 19:10

In Windows, the PE executable format has a flag that indicates whether the executable mode is "console mode" or "GUI mode". If "console mode", then the OS will attach a console window (opening a new one if necessary) whenever the program is run.

There will be a linker setting somewhere in your build environment that controls whether the EXE you generate is marked as console or GUI.

查看更多
登录 后发表回答