Open In App

How to Lock Window Resize C++ sfml?

Last Updated : 02 Jan, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Multimedia components in computers can be easily interfaced using SFML (Simple and Fast Multimedia Library), a cross-platform library for software development. The software runs on Windows, Linux, Mac OS X, iOS, and Android operating systems. Video games and graphical programs can be developed quickly and easily with SFML’s set of tools. Among its features are graphics, audio, networking, and system functions. In addition, it provides classes for managing windows and for capturing user input. 

In order to prevent a window from being resized in SFML, you can use the sf::Window::setSize method to set the window’s size to a fixed value. 

Before using sf::Window::setSize:

Example:

C++




// C++ Program To Lock Window Resize C++ sfml
#include <SFML/Window.hpp>
#include <iostream>
  
int main()
{
    // Create the window
    sf::Window window(sf::VideoMode(600, 600), "SFML WORK!");
  
    // Set the window's size to a fixed value (600 x 600)
    window.setSize(sf::Vector2u(600, 600));
  
    // Run the main loop
    while (window.isOpen()) {
        // Process events
        sf::Event event;
        while (window.pollEvent(event)) {
            // Close the window if requested
            if (event.type == sf::Event::Closed) {
                window.close();
            }
        }
  
        // Clear the window
        window.clear();
  
        // Display the window's contents on the screen
        window.display();
    }
  
    return 0;
}


Output:

Explanation: In this example, we create a window with a size of 600 x 600 pixels, and then use the setSize method to set the window’s size to the same value. This effectively prevents the user from resizing the window.


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads