BMX1.12: Center Window in windowed mode?

BlitzMax Forums/BlitzMax Beginners Area/BMX1.12: Center Window in windowed mode?

Grisu(Posted 2005) [#1]
Hi!

I guess the topic says it all.

Why does BMX 1.12 NOT center the app window on the desktop.
This should be "default"... shouldn't it?

Thanks.


FlameDuck(Posted 2005) [#2]
Why does BMX 1.12 NOT center the app window on the desktop.
Because you're createing it incorrectly.

This should be "default"... shouldn't it?
No.
Strict

Const WIDTH:Int = 400
Const HEIGHT:Int = 300
Const NAME:String = "Whatever.."
Const WINDOW_FLAGS = WINDOW_TITLEBAR | WINDOW_CLIENTCOORDS

Local myGadget:TGadget = CreateWindow ( NAME , (Desktop().width - WIDTH) /2 , (Desktop().height - HEIGHT)/2 , WIDTH , HEIGHT , WINDOW_FLAGS)

While CurrentEvent.ID <> EVENT_WINDOWCLOSE
	WaitEvent()
EndWhile



Grisu(Posted 2005) [#3]
Sorry, I mean a normal non-gui! window:

"Graphics 800,600,0"


FlameDuck(Posted 2005) [#4]
Sorry, I mean a normal non-gui! window:
Ah, in that case, I'm indifferent. :o>


Hotcakes(Posted 2005) [#5]
Have a look at dxgraphics.mod/dxd7graphics.bmx --> Function CreateHWND(line 49) --> If fullscreen Else (line 69, dude!)... it seems to be handled there.

As a side note, I spy a dxd9graphics.bmx!


Grisu(Posted 2005) [#6]
ok, you might be right though I don't understand how to modify it so it reactes on different desktop resolutions.

If someone wants to try:

Function CreateHWND(width,height,fullscreen)
Local hinst=GetModuleHandleA(0)
Local wc:WNDCLASS=New WNDCLASS
Local style,ex_style,hwnd

wc.hInstance=hinst
wc.lpfnWndProc=WndProc
wc.hCursor=LoadCursorA( Null,Byte Ptr IDC_ARROW )
wc.lpszClassName=DX_CLASS_NAME.ToCString()
Local res=RegisterClassA( wc )
If Not res
MemFree wc.lpszClassName
Throw "Failed to register window class"
EndIf

Local wndTitle:Byte Ptr=AppTitle.ToCString()

If fullscreen
style=WS_VISIBLE|WS_POPUP
hwnd=CreateWindowExA( 0,wc.lpszClassName,wndTitle,style,0,0,width,height,0,0,hinst,Null )
Else
style=WS_VISIBLE|WS_CAPTION|WS_SYSMENU
Local rect[]=[0,0,width,height]
AdjustWindowRect rect,style,0
width=rect[2]-rect[0]
height=rect[3]-rect[1]
hwnd=CreateWindowExA( 0,wc.lpszClassName,wndTitle,style,CW_USEDEFAULT,CW_USEDEFAULT,width,height,0,0,hinst,Null )
EndIf
MemFree wndTitle
MemFree wc.lpszClassName
If Not hwnd Throw "Failed to create window"
Return hwnd
End Function


Perturbatio(Posted 2005) [#7]
If x is set to CW_USEDEFAULT, Windows selects the default position for the window's upper-left corner and ignores the y parameter. CW_USEDEFAULT is valid only for overlapped windows; if it is specified for a pop-up or child window, the x and y parameters are set to zero.


I suspect this may be so that if someone's graphics drivers has the ability to set the default window opening position, it will work correctly (I could be wrong of course).


Proger(Posted 2005) [#8]
Heh )))

Extern "win32"
Function GetSystemMetrics(Param)
End Extern
GetSystemMetrics(0) - Get Desctop Width
GetSystemMetrics(1) Get Desctop Height

in dx module:
...
Local x = (GetSystemMetrics(0)/2) - width/2
Local y = (GetSystemMetrics(1)/2) - height/2
...
hwnd=CreateWindowExA( 0,wc.lpszClassName,wndTitle,style, x, y,width,height,0,0,hinst,Null )



Grisu(Posted 2005) [#9]
Can't get this working... :/


Eikon(Posted 2005) [#10]
BlitzMax window framework
I also have code in the archives to give it a task icon if you need that too


Grisu(Posted 2005) [#11]
Thanks Eikon!

I think I got the older code from you as well, but it broke with the new bmx release.
Also, delete the "flushmem()" from the source code.
So pure newbies can compile the example right away.

btw:
Currently I'm busy fixing bugs in cardwar due to bp1.42.
Because I'd like to ship an updated version before 2006. :)