Placement of window

Hi All,
I’m new to the list, and searching the archives has
proven a little troublesome… my questoin:

I want to be able to place the window that appears in
an exact position… is this possible? when I do the
following:
screen = SDL_SetVideoMode(320, 240, 8,
SDL_SWSURFACE|SDL_ANYFORMAT|SDL_NOFRAME);

it creates a window and displays it on the screen…
I’d like to force that window to be in a certain x-y
position on the screen…

Thanks,
Michael__________________________________________________
Do You Yahoo!?
Send FREE Valentine eCards with Yahoo! Greetings!
http://greetings.yahoo.com

Hello!

I’d like to force that window to be in a certain x-y
position on the screen…

If you are using ms windows, have a look at the following code.
(How long do i have to pray until this goes into the FAQ? :slight_smile: )

Ciao,
Eike-------------------------------------------------------------------

#include “SDL_syswm.h”

static void SDL_center_window(SDL_Surface *screen)
{
SDL_SysWMinfo info;
SDL_VERSION(&info.version);

if ( SDL_GetWMInfo(&info) > 0 ) {
int x, y;
int w, h;

#ifdef unix

  if ( info.subsystem == SDL_SYSWM_X11 ) {
     info.info.x11.lock_func();
     w = DisplayWidth(info.info.x11.display,
                 DefaultScreen(info.info.x11.display));
     h = DisplayHeight(info.info.x11.display,
                 DefaultScreen(info.info.x11.display));
     x = (w - screen->w)/2;
     y = (h - screen->h)/2;
     XMoveWindow(info.info.x11.display, info.info.x11.wmwindow, x,

y);
info.info.x11.unlock_func();
}

#elif defined(WIN32)

  RECT windowRect, desktopRect;
	
  HWND desktop = GetDesktopWindow();
  GetWindowRect(desktop, &desktopRect);
  GetWindowRect(info.window, &windowRect);
	
  int desktopWidth = desktopRect.right - desktopRect.left;
  int desktopHeight = desktopRect.bottom - desktopRect.top;
  w = windowRect.right - windowRect.left;
  h = windowRect.bottom - windowRect.top;
  x = (desktopWidth - w) / 2;
  y = (desktopHeight - h) / 2;
	
  MoveWindow(info.window, x, y, w, h, true);

#else

#warning Need to implement these functions for other systems

#endif
}
}

“Eike R. Sauer” wrote:

#warning Need to implement these functions for other systems

#warning’ isn’t standard C, although some compilers accept it

#warning’ isn’t standard C, although some compilers accept it

This was copied from the FAQ, as well as the unix part. :slight_smile:

Eike

Hello Eike,

ERS> #elif defined(WIN32)

#elseif, surely? :wink:

Neil.

Neil Griffiths <n.griffiths at virgin.net> wrote:

ERS> #elif defined(WIN32)

#elseif, surely? :wink:

oh dear

Hi,

#elseif, surely? :wink:

ME> oh dear

Yes, yes, I know… I thought it was funny. Sorry. =)

Neil.