Page 1 of 1
Only X coordinate of Window centered
Posted: Fri Jun 30, 2023 7:51 pm
by Jan2004
I want to have window x coordinate centered, but 50 pxls y coordinate (50 pxls from top of the screen). My code is below. Is simpler way to achieve it?
Code: Select all
Define Result
If OpenWindow(0, 0, 0, 1200, 700, "PureBasic Window", #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
Result = WindowX(0 ,#PB_Window_FrameCoordinate)
ResizeWindow(0, Result, 50, #PB_Ignore, #PB_Ignore )
;
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_CloseWindow ; If the user has pressed on the close button
Quit = 1
EndIf
Until Quit = 1
EndIf
End
Re: Only X coordinate of Window centered
Posted: Fri Jun 30, 2023 7:59 pm
by jassing
Jan2004 wrote: Fri Jun 30, 2023 7:51 pm
I want to have window x coordinate centered, but 50 pxls y coordinate (50 pxls from top of the screen). My code is below. Is simpler way to achieve it?
I think that's a good way to go. I would create the window with #PB_Window_Invisible, then use HideWindow(..., #False) to show it afte you move it; that way there's no chance of flicker or user seeing the window move.
Re: Only X coordinate of Window centered
Posted: Sat Jul 01, 2023 3:20 am
by RASHAD
Hi Jan2004
Your code is fine
Next is another way to do it from beginning
Code: Select all
Define Result
ExamineDesktops()
x = DesktopWidth(0)/2 -600
y = 50
If OpenWindow(0, x,y, 1200, 700, "PureBasic Window", #PB_Window_MinimizeGadget)
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_CloseWindow ; If the user has pressed on the close button
Quit = 1
EndIf
Until Quit = 1
EndIf
End
Re: Only X coordinate of Window centered
Posted: Sat Jul 01, 2023 3:22 pm
by Jan2004
Thanks to my colleagues for the tips. I follow RASHAD. I thought that with high resolution, the top of the window should be further away from the top of the window, so I changed the code (taking into account the suggestions of RASHAD). Here is the new code for most screen resolutions:
Code: Select all
Enumeration
#WINDOW_Main
EndEnumeration
ExamineDesktops()
x_coord = DesktopWidth(0)/2 -600
y_DesktopHeight = DesktopHeight(0)
If OpenWindow(#WINDOW_Main, 0,0, 1200, 700, "PureBasic Window", #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
If y_DesktopHeight > 770 ; for desktop height 800 - 20 pixels from the top
Result_win = WindowX(#WINDOW_Main ,#PB_Window_FrameCoordinate)
ResizeWindow(#WINDOW_Main, x_coord, 20, #PB_Ignore, #PB_Ignore)
EndIf
If y_DesktopHeight > 810 ; for desktop height 900 and 864 - 50 pixels from the top
Result_win = WindowX(#WINDOW_Main ,#PB_Window_FrameCoordinate)
ResizeWindow(#WINDOW_Main, x_coord, 50, #PB_Ignore, #PB_Ignore )
EndIf
; For 768, 720, 600 window will be centered - as in If OpenWindow(#WINDOW_Main, 0,0, 1200, 700, "PureBasic Window", #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_CloseWindow ; If the user has pressed on the close button
Quit = 1
EndIf
Until Quit = 1
EndIf
End
Re: Only X coordinate of Window centered
Posted: Sat Jul 01, 2023 3:54 pm
by RASHAD
Hi Jan2004
I think you should do the next change to avoid resizing the Window twice
Code: Select all
If y_DesktopHeight > 770 And y_DesktopHeight < 800; for desktop height 800 - 20 pixels from the top
Result_win = WindowX(#WINDOW_Main ,#PB_Window_FrameCoordinate)
ResizeWindow(#WINDOW_Main, x_coord, 20, #PB_Ignore, #PB_Ignore)
EndIf
If y_DesktopHeight >= 800 ; for desktop height 900 and 864 - 50 pixels from the top
Result_win = WindowX(#WINDOW_Main ,#PB_Window_FrameCoordinate)
ResizeWindow(#WINDOW_Main, x_coord, 50, #PB_Ignore, #PB_Ignore )
EndIf
Re: Only X coordinate of Window centered
Posted: Sat Jul 01, 2023 6:56 pm
by Jan2004
RASHAD: Hi again!
Yes. It is the best solution. The final code is as follows:
Code: Select all
Enumeration
#WINDOW_Main
EndEnumeration
ExamineDesktops()
x_coord = DesktopWidth(0)/2 -600
y_DesktopHeight = DesktopHeight(0)
If OpenWindow(#WINDOW_Main, 0,0, 1200, 700, "PureBasic Window", #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
If y_DesktopHeight < = 770 ; For desktop height 768, 720, 600 - 0 pixels from the top
Result_win = WindowX(#WINDOW_Main ,#PB_Window_FrameCoordinate)
ResizeWindow(#WINDOW_Main, x_coord, 0, #PB_Ignore, #PB_Ignore)
EndIf
If y_DesktopHeight > 770 And y_DesktopHeight = < 800; for desktop height 800 - 20 pixels from the top
Result_win = WindowX(#WINDOW_Main ,#PB_Window_FrameCoordinate)
ResizeWindow(#WINDOW_Main, x_coord, 20, #PB_Ignore, #PB_Ignore)
EndIf
If y_DesktopHeight > 800 ; for desktop height 900 and 864 - 50 pixels from the top
Result_win = WindowX(#WINDOW_Main ,#PB_Window_FrameCoordinate)
ResizeWindow(#WINDOW_Main, x_coord, 50, #PB_Ignore, #PB_Ignore )
EndIf
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_CloseWindow ; If the user has pressed on the close button
Quit = 1
EndIf
Until Quit = 1
EndIf
End