SDL Window opening with Console Window

This is a discussion on SDL Window opening with Console Window within the Windows Programming forums, part of the Platform Specific Boards category; Hi, I am using MinGW on Win32 and when I compile the following code, it works as expected. But when ...

  1. #1
    Registered User carrotcake1029's Avatar
    Join Date
    Apr 2008
    Posts
    398

    SDL Window opening with Console Window

    Hi, I am using MinGW on Win32 and when I compile the following code, it works as expected. But when I open the resulting executable, I get both a console window and the SDL window I created. Any reason why I get this console window?

    Code:
    gcc main.c -o main.exe -Wall -lSDL -lSDLmain
    Code:
    #include <windows.h>
    #include <SDL/SDL.h>
    
    int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    { 
    	SDL_Surface *screen;
    	SDL_Event event;
    
    	if (SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0) 
    	{
    		fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
    		exit(1);
    	}
    	
    	screen = SDL_SetVideoMode(640, 480, 16, SDL_SWSURFACE);
    	if (screen == NULL) 
    	{
    		fprintf(stderr, "Unable to set 640x480 video: %s\n", SDL_GetError());
    		exit(1);
    	}
    	
    	SDL_WaitEvent(&event);
    	
    	while(1) 
    	{
    		while(SDL_PollEvent(&event)) 
    		{      
    			switch (event.type) 
    			{
    				case SDL_QUIT:
    					exit(0);
    					break;
    			}
    		}
    	}
    	
    	SDL_Quit();
    
    	return 0;
    }
    Sorry, the codebox screwed up some of my indents.
    Last edited by carrotcake1029; 12-22-2008 at 03:37 PM.

  2. #2
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    612
    You need to specify that you want a Windowed application, not a command line one.

    gcc main.c -o main.exe -Wall -mwindows -lSDL -lSDLmain

  3. #3
    Registered User carrotcake1029's Avatar
    Join Date
    Apr 2008
    Posts
    398
    Thanks, a little green with gcc if you didn't notice.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Just starting Windows Programming, School me!
    By Shamino in forum Windows Programming
    Replies: 17
    Last Post: 02-22-2008, 08:14 AM
  2. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 11:50 AM
  3. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 01:34 PM
  4. Selectively opening a new window
    By Driver in forum Windows Programming
    Replies: 0
    Last Post: 09-27-2004, 02:42 AM
  5. Adding colour & bmps to a Win 32 Window??
    By carey_sizer in forum Windows Programming
    Replies: 4
    Last Post: 09-04-2004, 06:55 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21