Window Decorations and Borders

Can I remove only the title bar?

Can I remove only the title bar but keep the borders?

Abstract art representing computer programming

SDL2 does not natively support removing only the title bar while keeping the borders. When you use the SDL_WINDOW_BORDERLESS flag, all decorations, including the title bar and borders, are removed.

If you need this functionality, you’ll need to use platform-specific APIs to modify the window style directly. For example, on Windows, you could use the Win32 API to customize the WS_BORDER and WS_CAPTION flags of the window.

However, this approach bypasses SDL2’s abstraction and ties your code to a specific platform.

Here’s an example of creating a completely borderless window in SDL2 (no title bar or borders):

#include <SDL.h>

int main() {
  SDL_Init(SDL_INIT_VIDEO);

  SDL_Window* Window{SDL_CreateWindow(
    "No Title Bar",
    SDL_WINDOWPOS_CENTERED,
    SDL_WINDOWPOS_CENTERED,
    800, 600,
    SDL_WINDOW_BORDERLESS 
  )};

  SDL_Delay(3000);
  SDL_DestroyWindow(Window);
  SDL_Quit();
}

To keep the borders but remove the title bar, a workaround is to simulate borders using custom rendering inside the client area. Alternatively, look into platform-specific APIs if this functionality is critical.

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