Page 1 of 1

[solved] centerWindow (*window) or getFrameSize (*window)

Posted: Sat Mar 03, 2018 9:52 am
by es_91
Hi Fred


PureBasic is not the newest invention on the marked. Sadly, there is still no way to achieve a proper PB-native frame-measure-return when it comes to resizing windows or centering them using desktopHeight (*desktop) and desktopWidth (*desktop).


Correct centering without using API-functions is impossible when not init-applied to the window on openWindow function.

// HideWindow and windowWidth/windowHeight do

Re: centerWindow (*window) or getFrameSize (*window)

Posted: Sat Mar 03, 2018 6:37 pm
by kenmo
PB already added WindowWidth(Win, #PB_Window_FrameCoordinate) and WindowHeight(Win, #PB_Window_FrameCoordinate), those can help.

But a CenterWindow() function would be nice, and maybe flags for DesktopHeight to get the USABLE heights without API (minus taskbar, etc).

Also, what the OS considers "centered" is not always mathematically centered, for example when you tell MacOS to "center" a window it places it slightly higher than center (for aesthetics).

setWindowFlags (*window, flags)

Posted: Sat Mar 03, 2018 10:50 pm
by es_91
I agree, think the center function should really center on screen by default.

I am sorry, jeever, to omit remembering the #frameCoordinates constants as you mentioned.

Sorry, they DO that job.

It's by the way always sad to have no option to change the flags of a window. Apart from my previous topic titled above, changing the window flags by PB could become as crucial as replacing a window to the screen center.

Is there an approach existing in PB already?

// notice the topic-reachon change

Re: centerWindow (*window) or getFrameSize (*window)

Posted: Sat Mar 03, 2018 11:45 pm
by Sicro
es_91 wrote:Correct centering without using API-functions is impossible when not init-applied to the window on openWindow function.

Code: Select all

HideWindow(Window, #False, #PB_Window_ScreenCentered)

Re: centerWindow (*window) or getFrameSize (*window)

Posted: Mon Mar 05, 2018 2:47 pm
by es_91
Then I'm sorry. Very sorry not studying the changes.

Thanks, Sicro

Re: centerWindow (*window) or getFrameSize (*window)

Posted: Mon Mar 05, 2018 2:57 pm
by kenmo
HideWindow(Window, #False, #PB_Window_ScreenCentered)
But this Center only works when un-hiding the window from hidden... I don't know why, OS/API reason?

Re: centerWindow (*window) or getFrameSize (*window)

Posted: Mon Mar 05, 2018 9:08 pm
by Blue
kenmo wrote:
HideWindow(Window, #False, #PB_Window_ScreenCentered)
But this Center only works when un-hiding the window from hidden... I don't know why, OS/API reason?
Did you try it, kenmo ?
In Windows, it works even if the window is not currently hidden.

Code: Select all

winH = 120
winW = 300

If OpenWindow(0, 100, 200, winW, winH, "PureBasic Window", #PB_Window_SystemMenu)
   SetWindowColor(0,#Yellow)
   TextGadget(0, 20,20,200,20,"Window not centered")
   SetGadgetColor(0,#PB_Gadget_BackColor, #Yellow)
   gW = 120
   gH = 20
   ButtonGadget(1,winW-gW-10,winH-gH-10, gW, gH, "Center the window")

   Repeat
      event = WaitWindowEvent()
      Select event
         Case #PB_Event_CloseWindow : Break
         Case #PB_Event_Gadget : 
            HideWindow(0, #False,#PB_Window_ScreenCentered)
            SetGadgetText(0, "the Window is now centered")
            DisableGadget(1,1)
    EndSelect
   ForEver
EndIf
End

Re: centerWindow (*window) or getFrameSize (*window)

Posted: Mon Mar 05, 2018 9:32 pm
by kenmo
I did not try it :lol: Oops. That's just how I understood the help:
#PB_Window_ScreenCentered: the window will be screen centered (only valid when un-hiding the window).