12

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.

genpfault
  • 51,148
  • 11
  • 85
  • 139
Matěj Zábský
  • 16,909
  • 15
  • 69
  • 114

5 Answers5

10

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
);
ron
  • 9,262
  • 4
  • 40
  • 73
kungfooman
  • 4,473
  • 1
  • 44
  • 33
7

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);
ColacX
  • 3,928
  • 6
  • 34
  • 36
5

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);
Community
  • 1
  • 1
Judge Maygarden
  • 26,961
  • 9
  • 82
  • 99
  • 1
    This is justa simultion, not the real thing. The real maximized window has no left and right border and the "minimize" icon instead of the "maximize" one in the header. – Matěj Zábský Nov 25 '08 at 19:39
0

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.

Peter Shinners
  • 3,686
  • 24
  • 24
-1

SDL_FULLSCREEN is the option you're looking for:

flags |= SDL_FULLSCREEN;
screen = SDL_SetVideoMode(..., flags);
MattyT
  • 6,531
  • 2
  • 20
  • 17
  • I'm looking for a way how to maximize the window, not make it fullscreen. – Matěj Zábský Nov 23 '08 at 16:42
  • Sorry, my bad - that'll teach me for working on these issues when I'm half asleep! I'll try and come up with a solution that *maximises* the screen tonight. – MattyT Nov 24 '08 at 00:14