specify SDL window location?

Started by
1 comment, last by grimfang4 15 years, 2 months ago
I don't see anything in the spec, did they omit this function? Currently my window is created partly off-screen.
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.
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.

This topic is closed to new replies.

Advertisement