Window Decorations and Borders

Resizable borderless windows in SDL2

Can I create a borderless window that still has a resizable frame?

Abstract art representing computer programming

Unfortunately, SDL2 does not natively support creating a borderless window with a resizable frame.

The SDL_WINDOW_BORDERLESS flag removes all decorations, including resize handles. The SDL_WINDOW_RESIZABLE flag, which allows resizing, only applies to windows with decorations.

If you need a resizable borderless window, you must implement the resizing functionality yourself by handling window resizing events (SDL_WINDOWEVENT_RESIZED) and manually adjusting the window size. You can also combine this with custom rendering to simulate resize handles.

Example of handling resize events:

#include <SDL.h>
#include <iostream>

int main() {
  SDL_Init(SDL_INIT_VIDEO);

  SDL_Window* Window{SDL_CreateWindow(
    "Resizable Borderless",
    SDL_WINDOWPOS_CENTERED,
    SDL_WINDOWPOS_CENTERED,
    800, 600,
    SDL_WINDOW_BORDERLESS 
  )};

  SDL_Event Event;
  bool Running{true};
  while (Running) {
    while (SDL_PollEvent(&Event)) {
      if (Event.type == SDL_QUIT) {
        Running = false;
      } else if (
        Event.type == SDL_WINDOWEVENT &&
        Event.window.event == SDL_WINDOWEVENT_RESIZED
      ) {
        int NewWidth = Event.window.data1;
        int NewHeight = Event.window.data2;
        std::cout << "Window resized to: "
          << NewWidth << "x" << NewHeight << "\n";
      }
    }
  }

  SDL_DestroyWindow(Window);
  SDL_Quit();
}
Window resized to: 1024x768

If resizing is critical, consider using platform-specific APIs to add custom resize handles. Another option is to use higher-level libraries like Dear ImGui that support customizable windowing.

This Question is from the Lesson:

Window Decorations and Borders

An introduction to managing SDL2 window decorations, borders, and client areas.

Answers to questions are automatically generated and may not have been reviewed.

This Question is from the Lesson:

Window Decorations and Borders

An introduction to managing SDL2 window decorations, borders, and client areas.

sdl2-promo.jpg
Part of the course:

Game Dev with SDL2

Learn C++ and SDL development by creating hands on, practical projects inspired by classic retro games

Free, unlimited access

This course includes:

  • 67 Lessons
  • 100+ Code Samples
  • 91% Positive Reviews
  • Regularly Updated
  • Help and FAQ
Free, Unlimited Access

Professional C++

Comprehensive course covering advanced concepts, and how to use them on large-scale projects.

Screenshot from Warhammer: Total War
Screenshot from Tomb Raider
Screenshot from Jedi: Fallen Order
Contact|Privacy Policy|Terms of Use
Copyright © 2024 - All Rights Reserved