Game Development Community

Set Initial Window Position

by Brandon Maness · 04/24/2005 (6:54 pm) · 6 comments

Open your winOGLVideo.cc file located in the ./engine/platformWin32 folder of your TGE source files. Around line 836 you will see this code:

// Center the window on the desktop:
      U32 xPos = ( winState.desktopWidth - adjWidth ) / 2;
      U32 yPos = ( winState.desktopHeight - adjHeight ) / 2;

Right after it paste in this code:

// Code change starts here <---------------------
		const char* resString = Con::getVariable( "$pref::Video::initialWindowPos" );
		char* tempBuf = new char[dStrlen( resString ) + 1];
		dStrcpy( tempBuf, resString );
		char* temp = dStrtok( tempBuf, " x[[4f398416d6955]]" );
		xPos = ( temp ? dAtoi( temp ) : 1 );
		temp = dStrtok( NULL, " x[[4f398416d6955]]" );
		yPos = ( temp ? dAtoi( temp ) : 1 );
		delete [] tempBuf;
		// ends here <-------------------

Recompile your exe and then load up the prefs.cs file located in your ./client/ folder. Now add this varible definition:

$pref::Video::initialWindowPos = "100 50";

That will tell the game window to load up 100 pixels to the right and 50 pixels down from the top left of your screen. Set these values to where you want your window to be and again, this is only good for Windows systems using the openGL video mode. I haven't tested it in any other mode, so your mileage may vary.

NOTE: the code segment that pulls the numbers from the console variable came from winWindow.cc... I admit I was too lazy to type it myself, and just copied/pasted it with changes I needed. Thanks GG for making and maintaining an awsome engine!

#1
04/24/2005 (10:26 pm)
This is pretty cool. I'll have to review this for HEAD inclusion.
#2
04/25/2005 (2:49 am)
Just a minor gripe...
Quote:
Open your winOGLVideo.cc file located in the ./platform/platformWin32 folder of your TGE

That directory and file doesn't exist.

Maybe you mean....
/engine/platformWin32/winOGLVideo.cc
#3
04/25/2005 (2:55 am)
@Ben if you review this and decide to include it in HEAD, could you please add functionality like this for Linux and Mac as well?
#4
04/25/2005 (7:03 am)
@Dreamer: You're right! oops.. My visual studio solution window shows the structure the way I typed it... I'll edit it, thanks.

B--
#5
03/15/2006 (12:46 am)
Rockin! :)
#6
12/28/2006 (2:05 am)
Good resource, work like a candy...