Page 1 of 2
How do I get window height minus takbar height
Posted: Wed Aug 13, 2014 4:56 am
by leodh
Hi all,
I have some users that have the taskbar showing and some have it hidden and some have it on the side. How do I open a window that takes all the possible layouts into account?
They are all using Windows 7.
Thanks
Leo
Re: How do I get window height minus takbar height
Posted: Wed Aug 13, 2014 5:31 am
by JHPJHP
Something else to consider, the use of more then one taskbar.
http://msdn.microsoft.com/en-us/library ... s.85).aspx
Code: Select all
wa.RECT
SystemParametersInfo_(#SPI_GETWORKAREA, 0, @wa, 0)
Debug wa\bottom
Debug wa\right
Re: How do I get window height minus takbar height
Posted: Wed Aug 13, 2014 6:27 am
by RASHAD
Code: Select all
OpenWindow(0,0,0,800,600,"Window & TaskBar",#PB_Window_SystemMenu| #PB_Window_MaximizeGadget| #PB_Window_ScreenCentered)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_MaximizeWindow|#PB_Event_Repaint
SystemParametersInfo_(#SPI_GETWORKAREA,0,r.RECT,0)
MoveWindow_(WindowID(0),r\left,r\top,r\right-r\left,r\bottom-r\top,1)
EndSelect
Until Quit = 1
Re: How do I get window height minus takbar height
Posted: Wed Aug 13, 2014 10:53 pm
by JHPJHP
Not sure what this adds, otherwise it's the same answer
- events are not activated in this context (PureBasic 5.30)
Code: Select all
#PB_Event_MaximizeWindow|#PB_Event_Repaint
Re: How do I get window height minus takbar height
Posted: Wed Aug 13, 2014 11:03 pm
by IdeasVacuum
Not sure what this adds, otherwise it's the same answer
If the app has been moved from one Monitor to another........
Re: How do I get window height minus takbar height
Posted: Wed Aug 13, 2014 11:12 pm
by Danilo
RASHAD wrote:Code: Select all
Case #PB_Event_MaximizeWindow|#PB_Event_Repaint
Shouldn't that be separated by comma instead 'binary Or'? "Case value1, value2, value3"
Re: How do I get window height minus takbar height
Posted: Wed Aug 13, 2014 11:14 pm
by RASHAD
Hi JHPJHP
How do I open a window that takes all the possible layouts into account?
Code: Select all
#PB_Event_MaximizeWindow|#PB_Event_Repaint
For PB 5.22 LTS
And a little bit more for satisfaction
Right click for Show - Hide TaskBar
Code: Select all
#ABM_SETSTATE = $A
tb.AppBarData
tb\cbSize = SizeOf(tb)
OpenWindow(0,0,0,800,600,"Window & TaskBar",#PB_Window_SystemMenu| #PB_Window_MaximizeGadget| #PB_Window_ScreenCentered)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_RightClick
If SHAppBarMessage_(#ABM_GETSTATE,tb) = 0
tb\lParam = 1
SHAppBarMessage_(#ABM_SETSTATE,tb)
ElseIf SHAppBarMessage_(#ABM_GETSTATE,tb) = 1
tb\lParam = 0
SHAppBarMessage_(#ABM_SETSTATE,tb)
EndIf
Case #PB_Event_MaximizeWindow|#PB_Event_Repaint
If SHAppBarMessage_(#ABM_GETSTATE,tb) = 0
SystemParametersInfo_(#SPI_GETWORKAREA,0,rc.RECT,0)
MoveWindow_(WindowID(0),rc\left,rc\top,rc\right-rc\left,rc\bottom-rc\top,1)
ElseIf SHAppBarMessage_(#ABM_GETSTATE,tb) = 1
GetWindowRect_(GetDesktopWindow_(),r.RECT)
MoveWindow_(WindowID(0),0,0,r\right-r\left,r\bottom-r\top,1)
EndIf
EndSelect
Until Quit = 1
Edit :Hi Danilo yes it should be like you mentioned but it did not work with 5.22 and I did not want to use callback
Test it yourself
Try to move the TaskBar from position to another while the Window is opened
PB 5.22 x86 Windows 8.1 x64
Re: How do I get window height minus takbar height
Posted: Thu Aug 14, 2014 12:53 am
by Danilo
SystemParametersInfo_(#SPI_GETWORKAREA,0,rc.RECT,0) is used to get the work area. That's the area between any taskbars/appbars.
If you want a window to fill the whole work area, you simply maximize it.
When you move a taskbar/appbar to another side, while a window is maximized, the window gets automatically re-sized by Windows and receives #WM_WINDOWPOSCHANGED / #WM_MOVE / #WM_SIZE messages.
Re: How do I get window height minus takbar height
Posted: Thu Aug 14, 2014 1:27 am
by RASHAD
That is what I was telling you I do not want to use Windows callback
No #WM_WINDOWPOSCHANGED and alike
Amazingly every thing works now as expected even without #PB_Event_Repaint
I think I have a weird problems lately with Win 8.1
Some of the code do not work while the debugger is on [not the well known threaded windows]
While everything works fine with Win 7
I do not want to reinstall it again

Re: How do I get window height minus takbar height
Posted: Thu Aug 14, 2014 2:07 am
by Danilo
RASHAD
Don't worry, there is nothing wrong with your Windows 8.1. Your code "#PB_Event_MaximizeWindow|#PB_Event_Repaint" just doesn't make any sense.

Using PB5.22 x86 and x64, the window always stays at 800x600. Nothing happens. Latest Win8.1 updates installed (today is MS patch day).
Re: How do I get window height minus takbar height
Posted: Thu Aug 14, 2014 2:15 am
by RASHAD
Are you serious Danilo about 800x600 ?
You are killing me
Edit :You are serious
I think I am out of order
I need some rest
Re: How do I get window height minus takbar height
Posted: Thu Aug 14, 2014 2:28 am
by Danilo
It works with maximized windows:
Code: Select all
#ABM_SETSTATE = $A
tb.AppBarData
tb\cbSize = SizeOf(tb)
OpenWindow(0,0,0,800,600,"Window & TaskBar",#PB_Window_SystemMenu| #PB_Window_MaximizeGadget| #PB_Window_Maximize| #PB_Window_ScreenCentered)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_RightClick
If SHAppBarMessage_(#ABM_GETSTATE,tb) = 0
tb\lParam = 1
SHAppBarMessage_(#ABM_SETSTATE,tb)
ElseIf SHAppBarMessage_(#ABM_GETSTATE,tb) = 1
tb\lParam = 0
SHAppBarMessage_(#ABM_SETSTATE,tb)
EndIf
EndSelect
Until Quit = 1
Right-click = hide/show taskbar, window is automatically resized.
Also when moving taskbar to another side, maximized window gets resized to new work area. (users usually don't move the taskbar very often)
No need to make it more complicated.
Re: How do I get window height minus takbar height
Posted: Thu Aug 14, 2014 3:04 am
by RASHAD
Yes you are right
But a problem raised with windows XP
I will look for it tomorrow
After hiding the Taskbar windows do not cover the the TaskBar area
(Using VirtualBox XP)
I am sleepy can not go ahead any more
Remember you added #PB_Window_Maximize and that made the trick
I am not sure about any thing at the moment

Re: How do I get window height minus takbar height
Posted: Fri Aug 15, 2014 5:49 am
by leodh
Hi Guys,
I think I did not explain myself well enough.
I want to open a screen, so I can use as much of the screen (independent of resolution) as possible, but leave the Taskbar visible.
ie. opensreen from the very to of the window to just above the Taskbar
( just like how the PureBasic IDE opens up)
Thanks
Re: How do I get window height minus takbar height
Posted: Fri Aug 15, 2014 9:12 am
by RASHAD
I think you need Windowed Screen in this case
Maybe the next snippet will help
- F1 to Release - Capture Mouse
- Escape to exit
Code: Select all
If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
MessageRequester("Error", "Can't open the sprite system", 0)
End
EndIf
SystemParametersInfo_(#SPI_GETWORKAREA, 0, @d.RECT, 0)
If OpenWindow(0, d\left,d\top, d\right, d\bottom, "Gadget and sprites!", #PB_Window_BorderLess)
If OpenWindowedScreen(WindowID(0), d\left,d\top, d\right, d\bottom, 0, 0, 0)
LoadSprite(0, "g:\PureBasicLogo.bmp")
Else
MessageRequester("Error", "Can't open windowed screen!", 0)
End
EndIf
EndIf
direction = 1
playerX = 1
playerY = 1
AddKeyboardShortcut(0,#PB_Shortcut_F1,10)
Repeat
Repeat
; ;Always process all the events To flush the queue at every frame
Event = WindowEvent()
;
Select Event
Case #PB_Event_Menu
Select EventMenu()
Case 10
Run ! 1
If Run = 1
ReleaseMouse(#True)
InputReleased = 1
Else
ReleaseMouse(#False)
InputReleased = 0
EndIf
EndSelect
; Case #WM_KEYDOWN
; If EventwParam() = 112
; Run ! 1
; If Run = 1
; ReleaseMouse(#True)
; InputReleased = 1
; Else
; ReleaseMouse(#False)
; InputReleased = 0
; EndIf
; EndIf
EndSelect
;
Until Event = 0 ; Quit the event loop only when no more events are available
If InputReleased = 0
ExamineMouse()
; do the sprite & screen management at every frame
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Up) And playerY > 0 : playerY -3 : EndIf
If KeyboardPushed(#PB_Key_Down) And playerY < d\bottom-SpriteHeight(0) : playerY +3 : EndIf
If KeyboardPushed(#PB_Key_Left) And playerX > 0 : playerX -3 : EndIf
If KeyboardPushed(#PB_Key_Right) And playerX < d\right-SpriteWidth(0) : playerX +3 : EndIf
EndIf
; Clear the screen and draw our sprites
ClearScreen(RGB(0,0,0))
ClipSprite(0, 0, 0, x, x/8)
DisplaySprite(0, x, 100)
DisplaySprite(0, x, x)
DisplaySprite(0, 300-x, x)
DisplaySprite(0, playerX, playerY)
x + direction
If x > 300 : direction = -1 : EndIf ; moving back to the left with negative value
If x < 0 : direction = 1 : EndIf ; moving to the right with positive value
FlipBuffers() ; Inverse the buffers (the back become the front (visible)... and we can do the rendering on the back
Until KeyboardPushed(#PB_Key_Escape)