1

I have a WINMAIN application say hello world.

i used

-mwindows 

switch option in linker to make sure it does GUI application. But when i execute some system commands like

system("dir");

from the C code it pops out a console.

Is there a option to supress the console window??

Please guide. Below is the hello world code using Mingw GCC

#include <windows.h>

int WINAPI
WinMain (HINSTANCE hInstance, HINSTANCE hPrevInst, LPTSTR lpCmdLine, int nShowCmd)
{
  MessageBoxW (NULL, L"Hello World!", L"hello", MB_OK | MB_ICONINFORMATION);
  system("dir");
  system("dir");
  system("dir");
  system("dir");
  Sleep(1000);
  return 0;
}
Ragav
  • 942
  • 4
  • 19
  • 37
  • Use CreateProcess and hide the window. – Retired Ninja Nov 07 '13 at 19:55
  • @RetiredNinja :: i am very to windows GUI apps can you get a reference for the same. – Ragav Nov 07 '13 at 19:58
  • 1
    Don't use system. If you want to list the files in a directory, check out this [Link](http://msdn.microsoft.com/en-us/library/windows/desktop/aa365200%28v=vs.85%29.aspx) – Carl Nov 07 '13 at 20:29

1 Answers1

1

You are calling dir, but dir is not a program like ls in Unix. It is a command.

So to execute dir, a CMD.exe has to be spawn, hence the console window.

Use FindFirstFile as suggested by @carl to list files in a directory.

ixe013
  • 9,559
  • 3
  • 46
  • 77