Sign in to follow this  
avocados

specify SDL window location?

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;
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this