Snap to desktop height

Share your advanced PureBasic knowledge/code with the community.
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Snap to desktop height

Post by Tenaja »

I was frustrated with the lack of "Snap window height to desktop height" in my PB programs. Here is a little snippet that demonstrates a manual way to "restore" the feature.

Code: Select all

 Select event ;...

			Case #PB_Event_MoveWindow		; Window Height restore
					If OldWindowH
						ResizeWindow(#WIN1, #PB_Ignore, #PB_Ignore, #PB_Ignore, OldWindowH - #TaskBarHeight)
						OldWindowH = 0
					EndIf
					
			Case  #WM_EXITSIZEMOVE
					maximized = 0
					If GetWindowState(#WIN1) = #PB_Window_Maximize
						maximized = 1
					EndIf
					
					OldWindowH = 0
					If DesktopMouseY() = 0
						OldWindowH = WindowHeight(#WIN1)
						ResizeWindow(#WIN1, #PB_Ignore, 0, #PB_Ignore, DesktopHeight(0) - #TaskBarHeight)
					EndIf
					windowW = WindowWidth(#WIN1)
					windowH = WindowHeight(#WIN1)			;for saving in Prefs.
					ResizeGadget(#SPLITTER_Left,#PB_Ignore,#PB_Ignore,windowW, windowH-ToolBarH-StatusBarHeight(#STAT1) - MenuHeight())
It is lacking in a few ways:
--the #TaskBarHeight is set as a constant (mine is 67), so it may mess up with other sizes.
--there is no "preview"
--Does not do a GetCurrentDesktop() Assumes only 1 (number 0), so with two monitors of different sizes, there will be issues.
--Is not Cross-platform (?)

Right now, I like this better than not having the feature, so I thought I'd share. It took longer to make the code "pretty" than it took to actually implement it, since I stored the window sizes in my Prefs file.

If anybody cares to add missing features, I'm sure they will be appreciated as well.
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: Snap to desktop height

Post by Tenaja »

Added a height Restore. With a PB message, since it only comes after the move is done, you don't get a preview.
Post Reply