Jump to content
  • Advertisement
Sign in to follow this  
avocados

specify SDL window location?

This topic is 3530 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

Advertisement
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;
GetClientRect(GetDesktopWindow(),&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;
SDL_VERSION(&windowInfo.version);
if(SDL_GetWMInfo(&windowInfo))
{
HWND handle = windowInfo.window;

//Finally, move the window to the calculated position, using the WIN32 function 'SetWindowPos'.
if(SetWindowPos(handle, NULL, posX, posY, 0, 0, SWP_NOREPOSITION|SWP_NOZORDER|SWP_NOSIZE|SWP_NOACTIVATE) == FALSE)
{
printf("Error occured centering window on the screen using the WIN32 function SetWindowPos()");
}
}
else
{
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:
SDL_putenv("SDL_VIDEO_CENTERED=center");

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!