WindowBounds() + #PB_Default [no bug, OS behaviour]

Just starting out? Need help? Post your questions and find answers here.
User avatar
HeX0R
Addict
Addict
Posts: 980
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

WindowBounds() + #PB_Default [no bug, OS behaviour]

Post by HeX0R »

I tried to limit the max width of a window to make sure it will not span accross the entire screen when being maximized.
But somehow, now the height of the window doesn't take the taskbar into account when maximized?
Shouldn't #PB_Default make sure, that the systems default behaviour will be used?

Code: Select all

OpenWindow(0, 0, 0, 600, 800, "Maximize me", #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SystemMenu)
CreateStatusBar(0, WindowID(0)) ;Add Statusbar to see the bottom part of the window
AddStatusBarField(400)
StatusBarText(0, 0, "BLA")
WindowBounds(0, #PB_Ignore, #PB_Ignore, 1000, #PB_Default)
;Maximize it, and the statusbar will be hidden behind the taskbar (in case your taskbar is located at the bottom)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Last edited by HeX0R on Tue Sep 07, 2021 10:07 pm, edited 1 time in total.
User avatar
jacdelad
Addict
Addict
Posts: 1431
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: WindowBounds() + #PB_Default

Post by jacdelad »

Code: Select all

  Procedure GetTaskBarHeight()
    Protected ABD.APPBARDATA,height=0
    SHAppBarMessage_(#ABM_GETTASKBARPOS,ABD)
    Select ABD\uEdge
      Case #ABE_BOTTOM
        height=ABD\rc\bottom-ABD\rc\top
      Case #ABE_TOP
        height=ABD\rc\bottom
      Case #ABE_LEFT
        height=ABD\rc\right-ABD\rc\left
      Case #ABE_RIGHT
        height=ABD\rc\right-ABD\rc\left
    EndSelect
    ProcedureReturn height
  EndProcedure
This doesn't change the behaviour of WindowBounds(), but you can calculate it yourself into the bounds.
Though, I don't see this as a bug.
Edit: I just realized who posted it, and I am sure you know how to...
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
User avatar
HeX0R
Addict
Addict
Posts: 980
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: WindowBounds() + #PB_Default

Post by HeX0R »

in fact, it seems to be some Windows bug/feature, don't know how the other OS behave here.
Here is the API way, with the very same effect:

Code: Select all

Procedure MyCallBack(Win, Msg, wParam, lParam)
	Protected *SizeTracking.MINMAXINFO, Result = #PB_ProcessPureBasicEvents
	
	If Msg = #WM_GETMINMAXINFO
		*SizeTracking = lParam
		*SizeTracking\ptMaxTrackSize\x = 1000
		;keep all the others at default values
	EndIf
	
	ProcedureReturn Result
EndProcedure

OpenWindow(0, 0, 0, 600, 800, "Maximize me", #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SystemMenu)
CreateStatusBar(0, WindowID(0)) ;Add Statusbar to see the bottom part of the window
AddStatusBarField(400)
StatusBarText(0, 0, "BLA")
SetWindowCallback(@MyCallBack())
;Maximize it, and the statusbar will be hidden behind the taskbar (in case your taskbar is located at the bottom)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
I didn't touch the \ptMaxTrackSize\y at all, it should be still the very same value, as if I didn't handle the WM_GETMINMAXINFO message at all.
But somehow, as soon as you change only one parameter, windows behaves different.

PB should not try to circumvent strange OS behaviours, therefore I'd say it is no PB bug.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: WindowBounds() + #PB_Default [no bug, OS behaviour]

Post by RASHAD »

Hi HeXOR
No PB bug as you mentioned
This is the peculiar way that MS Windows treat the StatusBar
It adds it's height to Windows Height

Code: Select all


Procedure winCB(hWnd, uMsg, wParam, lParam)
  Protected WORKAREA.RECT
  result = #PB_ProcessPureBasicEvents
  Select uMsg
    Case #WM_GETMINMAXINFO
      *mminfo.MINMAXINFO = lParam
      *mminfo\ptMinTrackSize\x =  2*GetSystemMetrics_(#SM_CXFRAME)
      *mminfo\ptMinTrackSize\y =  GetSystemMetrics_(#SM_CYMINTRACK)
      *mminfo\ptMaxTrackSize\x = 1000 + 2*GetSystemMetrics_(#SM_CXFRAME)
      SystemParametersInfo_(#SPI_GETWORKAREA, 0, @WORKAREA, 0)
      *mminfo\ptMaxTrackSize\y = WORKAREA\bottom+2*GetSystemMetrics_(#SM_CYFRAME)
      result=0
  EndSelect
  ProcedureReturn result
EndProcedure

OpenWindow(0,0,0,400,400,"Min & Max size Restriction",#PB_Window_SystemMenu| #PB_Window_MaximizeGadget| #PB_Window_SizeGadget| #PB_Window_ScreenCentered)
CreateStatusBar(0, WindowID(0)) ;Add Statusbar to see the bottom part of the window
AddStatusBarField(400)
StatusBarText(0, 0, "BLA")
SetWindowCallback(@winCB())

Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
Egypt my love
User avatar
HeX0R
Addict
Addict
Posts: 980
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: WindowBounds() + #PB_Default [no bug, OS behaviour]

Post by HeX0R »

I came-up with a quite similar solution than you, but mine respects different monitors :wink:

Code: Select all

Procedure MyWindowCallBack(Win, Msg, wParam, lParam)
	Protected *SizeTracking.MINMAXINFO, Result = #PB_ProcessPureBasicEvents, w, h
	Protected Monitor, MI.MONITORINFO
		
	If Msg = #WM_GETMINMAXINFO
		Monitor = MonitorFromWindow_(Win, #MONITOR_DEFAULTTONEAREST)
		If Monitor
			MI\cbSize = SizeOf(MONITORINFO)
			If GetMonitorInfo_(Monitor, @MI)
				w = MI\rcWork\right - MI\rcWork\left
				w + GetSystemMetrics_(#SM_CXFRAME) * 2
				h = MI\rcWork\bottom - MI\rcWork\top
				h + GetSystemMetrics_(#SM_CYFRAME) * 2
			EndIf
			*SizeTracking = lParam
			*SizeTracking\ptMaxTrackSize\x = w / 2
			*SizeTracking\ptMaxTrackSize\y = h
		EndIf
	EndIf
		
	ProcedureReturn Result
EndProcedure

OpenWindow(0,0,0,400,400,"Min & Max size Restriction",#PB_Window_SystemMenu| #PB_Window_MaximizeGadget| #PB_Window_SizeGadget| #PB_Window_ScreenCentered)
CreateStatusBar(0, WindowID(0)) ;Add Statusbar to see the bottom part of the window
AddStatusBarField(400)
StatusBarText(0, 0, "BLA")
SetWindowCallback(@MyWindowCallBack())

Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
Post Reply