Window To Start Centred

BlitzMax Forums/BlitzMax Programming/Window To Start Centred

I usually create the window off-screen. Then the menus and other gadget paraphernalia is added and at the end the window is moved into the center of the desktop with the help of the SetGadgetShape function. No jumping, no flickering, works for me all the time.

Here's a quick example:
SuperStrict

Local style:Int = WINDOW_TITLEBAR|WINDOW_RESIZABLE|WINDOW_MENU|WINDOW_STATUS

Local MyWindow:TGadget
Local filemenu:TGadget
Local editmenu:TGadget
Local helpmenu:TGadget

Const MENU_NEW:Int=101
Const MENU_OPEN:Int=102
Const MENU_SAVE:Int=103
Const MENU_CLOSE:Int=104
Const MENU_EXIT:Int=105

Const MENU_CUT:Int=106
Const MENU_COPY:Int=107
Const MENU_PASTE:Int=108

Const MENU_ABOUT:Int=109


Global WinWidth:Int=320
Global WinHeight:Int=240

'Create a centered window with client size WinWidth, WinHeight

Local wx:Int=(ClientWidth(Desktop())-WinWidth)/2
Local wy:Int=(ClientHeight(Desktop())-WinHeight)/2

MyWindow=CreateWindow("This is centered window", -5000,-5000,WinWidth,WinHeight,Null,style)

filemenu=CreateMenu("&File",0,WindowMenu(MyWindow))
CreateMenu"&New",MENU_NEW,filemenu,KEY_N,MODIFIER_COMMAND
CreateMenu"&Open",MENU_OPEN,filemenu,KEY_O,MODIFIER_COMMAND
CreateMenu"&Close",MENU_CLOSE,filemenu,KEY_W,MODIFIER_COMMAND
CreateMenu"",0,filemenu
CreateMenu"&Save",MENU_SAVE,filemenu,KEY_S,MODIFIER_COMMAND
CreateMenu"",0,filemenu
CreateMenu"E&xit",MENU_EXIT,filemenu,KEY_F4,MODIFIER_COMMAND

editmenu=CreateMenu("&Edit",0,WindowMenu(MyWindow))
CreateMenu "Cu&t",MENU_CUT,editmenu,KEY_X,MODIFIER_COMMAND
CreateMenu "&Copy",MENU_COPY,editmenu,KEY_C,MODIFIER_COMMAND
CreateMenu "&Paste",MENU_PASTE,editmenu,KEY_V,MODIFIER_COMMAND

helpmenu=CreateMenu("&Help",0,WindowMenu(MyWindow))
CreateMenu "&About",MENU_ABOUT,helpmenu

UpdateWindowMenu MyWindow


Local MyButton:TGadget=CreateButton("Click me",140,60,80,40,MyWindow)

SetGadgetShape(MyWindow,wx,wy,WinWidth,WinHeight)

While True
	WaitEvent 
	Local text$=  "Current window size (w,h) is " + ClientWidth(MyWindow)+ "," + ClientHeight(MyWindow)
	Select EventID()
		Case EVENT_WINDOWCLOSE
			End
		Case EVENT_MENUACTION
			Select EventData()
				Case MENU_EXIT
					End
				Case MENU_ABOUT
					Notify "A non-jumping centered window example created by Barney"
			End Select
	End Select
Wend

End

Hope this will help...

Barney