Question

How should I tell SDL to maximize the application window?

I'm creating the window with these flags: SDL_OPENGL | SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_RESIZABLE.

Was it helpful?

Solution

This functionality is controlled by the window manager when you use the SDL_RESIZABLE flag. To simulate the maximizing a window with SDL you would need to first determine the size the window would occupy when maximized. Then you would call SDL_SetVideoMode with this size after placing the window with the SDL_VIDEO_WINDOW_POS environment variable.

If you truly need the window to be maximized as if you had clicked on the maximize button, then you will have to access the underlying window manager directly (i.e. SDL won't help you).

For example, the ShowWindow function can be used to maximize a window using the Win32 API. To get a handle to the window created by SDL use the SDL_GetWMInfo function. The resulting SDL_SysWMinfo struct contains a window field of type HWND. This must be passed to the ShowWindow function along with the SW_MAXIMIZE flag.

SDL_SysWMinfo info;
SDL_VERSION(&info.version);
SDL_GetWMInfo(&info);
ShowWindow(info.window, SW_MAXIMIZE);

OTHER TIPS

In SDL2.0

sdl_window = SDL_CreateWindow("title", 10, 30, window_width, window_height, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
SDL_MaximizeWindow(sdl_window);
SDL_GetWindowSize(sdl_window, &window_width, &window_height);
sdl_gl_context = SDL_GL_CreateContext(sdl_window);
SDL_GL_MakeCurrent(sdl_window, sdl_gl_context);

All answers seem outdated, nowadays just specify SDL_WINDOW_MAXIMIZED as flag for SDL_CreateWindow.

window = SDL_CreateWindow(
    "Foobar",
    SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720,
    SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_MAXIMIZED
);

There are additional environment variables that can be set to control the display window. Unfortunately the sdl docs are down at the moment, so I can't look up what you need.

SDL_FULLSCREEN is the option you're looking for:

flags |= SDL_FULLSCREEN;
screen = SDL_SetVideoMode(..., flags);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top