Page 1 of 1
[Implemented] Center Windows
Posted: Mon Sep 09, 2002 1:29 pm
by BackupUser
Restored from previous forum. Originally posted by blueb.
I've seen this method used in other languages and I think would be
handy in PureBasic as well.
Instead of "having" to enter the x and y values to position a window..
Example:
If OpenWindow(0,150,150,450,200,#PB_Window_SystemMenu,"Test")
Set PureBasic so that if the user leaves x and y 'blank'
it is assumed that he/she wants the window centered on the screen.
Example:
If OpenWindow(0,,,450,200,#PB_Window_SystemMenu,"Test")
centers the window in the users screen.
This would save a lot of time calculating (and allowing)
for different screens, etc. The window placement would be 'automatic'.
Thanks,
blueb
Posted: Mon Sep 09, 2002 2:58 pm
by BackupUser
Restored from previous forum. Originally posted by PB.
> This would save a lot of time calculating (and allowing) for different
> screens, etc. The window placement would be 'automatic'.
I know what you're saying, but in Windows you can always have the window
centered, with no need for calculations, by opening it like so:
Code: Select all
WinW=450 : WinH=200 ; Window sizes.
If OpenWindow(0,GetSystemMetrics_(#SM_CXSCREEN)-WinW)/2,GetSystemMetrics_(#SM_CYSCREEN)-WinH)/2,WinW,WinH,#PB_Window_SystemMenu,"Test")
You can also move it to the center at any time using those API calls.
Still, this isn't a solution for Amiga/Linux compatibility, but I'm
sure they both have screen size commands which would easily adapt.
PB - Registered PureBasic Coder
Posted: Mon Sep 09, 2002 3:01 pm
by BackupUser
Restored from previous forum. Originally posted by fred.
Good idea, which is already on my todo list

. It will have two centered methods:
#PB_Window_WindowCentered ; center inside the parent window
#PB_Window_ScreenCentered ; center inside the whole screen
for both x,y
Is the constants name ok or should them be different ? (PB_Window_ prefix must remain of course).
Fred - AlphaSND
Posted: Mon Sep 09, 2002 3:14 pm
by BackupUser
Restored from previous forum. Originally posted by MrVainSCL.
Hi Fred
Mhhh... GetSystemMetrics_() is really easy to use... still wonder a bit that this will now implent to as standard... but ok...
I would prefer:
- #PB_WindowCentered ; center inside the parent window
- #PB_ScreenCentered ; center inside the whole screen
Still looking forward for something like OpenMDIWindow() for future versions...
Keep on ya work...
PIII450, 256MB Ram, 6GB HD, RivaTNT, DirectX8.1, SB AWE64, Win2000 + all Updates...
greetz
MrVainSCL! aka Thorsten
Posted: Mon Sep 09, 2002 5:39 pm
by BackupUser
Restored from previous forum. Originally posted by fred.
Originally posted by MrVainSCL
- #PB_WindowCentered ; center inside the parent window
- #PB_ScreenCentered ; center inside the whole screen
Are you blind or what ?
Fred - AlphaSND
Posted: Mon Sep 09, 2002 6:08 pm
by BackupUser
Restored from previous forum. Originally posted by PB.
> Fred wrote: #PB_Window_ScreenCentered
> MrVainSCL wrote: #PB_ScreenCentered
So I don't think MrVainSCL is blind, Fred...
PB - Registered PureBasic Coder
Posted: Mon Sep 09, 2002 6:49 pm
by BackupUser
Restored from previous forum. Originally posted by fred.
Yes and I wrote :
(PB_Window_ prefix must remain of course) 
. So it's the same.
Fred - AlphaSND
Posted: Mon Sep 09, 2002 7:00 pm
by BackupUser
Restored from previous forum. Originally posted by PB.
> Yes and I wrote :
(PB_Window_ prefix must remain of course) 
. So it's the same.
Okay.

I thought you didn't realise, that's all.
PB - Registered PureBasic Coder
Posted: Tue Sep 10, 2002 1:56 am
by BackupUser
Restored from previous forum. Originally posted by blueb.
Sorry Guys,
The simplest method has to be:
If OpenWindow(0,,,450,200,#PB_Window_SystemMenu,"Test")
Other than blanking the 2 above fields...nothing to remember.
No - GetSystemMetrics_(#SM_CXSCREEN)-WinW
No - #PB_Window_ScreenCentered
Regards,
--blueb
Posted: Tue Sep 10, 2002 3:38 pm
by BackupUser
Restored from previous forum. Originally posted by MrVainSCL.
Hi blueb
Sorry guy.. but i personaly dont like the idea of "(0,,,450)" ... Have you ever seen any other coding language where you will write ",,,,," ??? not for me... sorry, i dont agree with this!
If you want something optional what about:
OpenWindow(0,150,150,450,200,#PB_Window_SystemMenu,"Test",[#flag],[flag])
If the flag is set to "-1" or whatever, your window will automatical centered... Fred, what do you think about this? But in my opinion the optional feature is not really needed... (due fact i dont know why you dont use the SystemMetrics_() command - very easy!)
PIII450, 256MB Ram, 6GB HD, RivaTNT, DirectX8.1, SB AWE64, Win2000 + all Updates...
greetz
MrVainSCL! aka Thorsten
Posted: Tue Sep 10, 2002 3:50 pm
by BackupUser
Restored from previous forum. Originally posted by plouf.
A bit out of topic ,sorry guys,but wondering
how could this be made with a constand ?????
i mean constands are tranformed to a number/string
if am not wrong after compilation ,the screen can change resolution whenerever the user likes to !?!?!?
Christos
Posted: Tue Sep 10, 2002 4:14 pm
by BackupUser
Restored from previous forum. Originally posted by Danilo.
The constant is for example "-30000".
Now in the ASM code for OpenWindow, it checks for -30000.
If found -30000, the Command automatically calculates
the right position to center the window on screen.
Using ",,," without values is a syntax error in the PureBasic language.
This are rules that cant/shouldnt be changed easily.
(there must be rules for syntax)
cya,
...Danilo
(registered PureBasic user)
Posted: Tue Sep 10, 2002 5:14 pm
by BackupUser
Restored from previous forum. Originally posted by freak.
> OpenWindow(0,150,150,450,200,#PB_Window_SystemMenu,"Test",[#flag],[flag])
Why more Flags, OpenWindow allready has a Flags parameter.
Fred, why not add #PB_Window_WindowCentered and #PB_Window_ScreenCentered to those Flags, and
if they are set, just ignore the x,y parameters?
Could look like this:
OpenWindow(0,0,0,450,200,#PB_Window_SystemMenu | #PB_Window_WindowCentered,"Test")
Would make more sense to me.
Timo
Posted: Tue Sep 10, 2002 5:37 pm
by BackupUser
Restored from previous forum. Originally posted by fred.
freak: Exactly what I will do. Good idea.
Fred - AlphaSND
Posted: Wed Sep 11, 2002 7:22 am
by BackupUser
Restored from previous forum. Originally posted by fweil.
Fred ... and everybody,
I agree with freak's idea you made yours.
This allow parametric call of OpenWindow using a variable containgin optional flag. I think it is a good way to have either sized or centered windows with a simple formula.
Rgrds
Francois Weil
14, rue Douer
F64100 Bayonne