Search code examples
cwindowsdlportability

Maximize SDL window


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.


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);