Jump to content
  • Advertisement
Sign in to follow this  

specify SDL window location?

This topic is 3616 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

You can't select the position of the window, nor can you move it, using SDL.

However... if you want to toss in some Windows-specific code...

//Retrieve the monitor resolution size. (AKA the size of the desktop in pixels)
RECT rect;
int monitorWidth = rect.right;
int monitorHeight = rect.bottom;

//Calculate the new window position.
//'Screen' in this case refers to the window size, and not the monitor/desktop size.
int posX = (monitorWidth - ScreenWidth) / 2;
int posY = (monitorHeight - ScreenHeight) / 2;

//Grab a handle to the window.
SDL_SysWMinfo windowInfo;
HWND handle = windowInfo.window;

//Finally, move the window to the calculated position, using the WIN32 function 'SetWindowPos'.
printf("Error occured centering window on the screen using the WIN32 function SetWindowPos()");
printf("SDL_GetWMInfo(): %s", SDL_GetError());

The above was taken from a old engine I was working on. The code came after the SDL window was already created.

You must include <windows.h>, and preferably #define 'WIN32_LEAN_AND_MEAN' right before including it.

Share this post

Link to post
Share on other sites
Actually, there is a portable way. Try using this before initializing SDL:

There are other things you can do by setting environment variables like this. This is just a quick sample.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!