Code: Select all
Global oldProc, offset
Procedure WndCallback(hWnd, Msg, wParam, lParam)
Select Msg
Case #WM_NCCALCSIZE
Protected ret = DefWindowProc_(hWnd, Msg, wParam, lParam)
If wParam = 0 : ProcedureReturn 0 : EndIf
If offset
Protected *ncc.NCCALCSIZE_PARAMS = lParam
GetClientRect_(hWnd, cRect.RECT)
MapWindowPoints_(hWnd, 0, cRect, 2)
If *ncc\lppos
*ncc\rgrc[2]\left = cRect\left
*ncc\rgrc[2]\top = cRect\top - offset
*ncc\rgrc[2]\right = cRect\right
*ncc\rgrc[2]\bottom = cRect\bottom
EndIf
EndIf
ProcedureReturn ret
EndSelect
ProcedureReturn CallWindowProc_(oldProc, hWnd, Msg, wParam, lParam)
EndProcedure
Procedure IsAeroSnapEnabled()
deskWidth = GetSystemMetrics_(0)
deskHeight = GetSystemMetrics_(1)
If WindowWidth(0, #PB_Window_FrameCoordinate) = deskWidth/2
ProcedureReturn #True
EndIf
ProcedureReturn #False
EndProcedure
OpenWindow(0, 0, 0, 800, 500, "demo by chi : ) ", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_ScreenCentered|#PB_Window_Invisible)
oldProc = SetWindowLongPtr_(WindowID(0), #GWL_WNDPROC, @WndCallback())
ButtonGadget(0, 10, 10, 100, 30, "Toggle Toolbar")
ButtonGadget(1, 110, 10, 100, 30, "Toggle Menu")
ButtonGadget(2, 210, 10, 100, 30, "Toggle Statusbar")
ListViewGadget(3, 10, 50, WindowWidth(0)-20, WindowHeight(0)-60)
HideWindow(0, #False)
Repeat
event = WaitWindowEvent()
Select event
Case #PB_Event_Gadget
Select EventGadget()
Case 0 ; "Toggle Toolbar"
If IsToolBar(0) = 0
CreateToolBar(0, WindowID(0))
ToolBarStandardButton(0, #PB_ToolBarIcon_New)
ToolBarStandardButton(1, #PB_ToolBarIcon_Open)
ToolBarStandardButton(2, #PB_ToolBarIcon_Save)
offset = ToolBarHeight(0)
If IsZoomed_(WindowID(0)) = 0
If IsAeroSnapEnabled() = 0
SetWindowPos_(WindowID(0), #HWND_TOP, 0, 0, WindowWidth(0, #PB_Window_FrameCoordinate), WindowHeight(0, #PB_Window_FrameCoordinate) + offset, #SWP_NOMOVE|#SWP_NOZORDER)
Else
SetWindowPos_(WindowID(0), #HWND_TOP, 0, 0, WindowWidth(0, #PB_Window_FrameCoordinate), WindowHeight(0, #PB_Window_FrameCoordinate) + 1 , #SWP_NOMOVE|#SWP_NOZORDER)
offset = 0
SetWindowPos_(WindowID(0), #HWND_TOP, 0, 0, WindowWidth(0, #PB_Window_FrameCoordinate), WindowHeight(0, #PB_Window_FrameCoordinate) - 1 , #SWP_NOMOVE|#SWP_NOZORDER)
EndIf
Else
wp.WINDOWPLACEMENT\Length = SizeOf(WINDOWPLACEMENT)
GetWindowPlacement_(WindowID(0), wp)
wp\rcNormalPosition\bottom + offset
SetWindowPlacement_(WindowID(0), wp)
offset/2
ShowWindow_(WindowID(0), #SW_SHOWMINIMIZED)
ShowWindow_(WindowID(0), #SW_SHOWMAXIMIZED)
EndIf
Else
offset = -ToolBarHeight(0)
FreeToolBar(0)
If IsZoomed_(WindowID(0)) = 0
If IsAeroSnapEnabled() = 0
SetWindowPos_(WindowID(0), #HWND_TOP, 0, 0, WindowWidth(0, #PB_Window_FrameCoordinate), WindowHeight(0, #PB_Window_FrameCoordinate) + offset, #SWP_NOMOVE|#SWP_NOZORDER)
Else
SetWindowPos_(WindowID(0), #HWND_TOP, 0, 0, WindowWidth(0, #PB_Window_FrameCoordinate), WindowHeight(0, #PB_Window_FrameCoordinate) + 1 , #SWP_NOMOVE|#SWP_NOZORDER)
offset = 0
SetWindowPos_(WindowID(0), #HWND_TOP, 0, 0, WindowWidth(0, #PB_Window_FrameCoordinate), WindowHeight(0, #PB_Window_FrameCoordinate) - 1 , #SWP_NOMOVE|#SWP_NOZORDER)
EndIf
Else
wp.WINDOWPLACEMENT\Length = SizeOf(WINDOWPLACEMENT)
GetWindowPlacement_(WindowID(0), wp)
wp\rcNormalPosition\bottom + offset
SetWindowPlacement_(WindowID(0), wp)
offset/2
ShowWindow_(WindowID(0), #SW_SHOWMINIMIZED)
ShowWindow_(WindowID(0), #SW_SHOWMAXIMIZED)
EndIf
EndIf
If IsStatusBar(0) And IsZoomed_(WindowID(0))
If IsMenu(0)
menuheight = MenuHeight()
Else
menuheight = 0
EndIf
SetWindowPos_(StatusBarID(0), #HWND_TOP, 0, WindowHeight(0) - menuheight - StatusBarHeight(0), 0, 0, #SWP_NOSIZE|#SWP_NOZORDER)
EndIf
offset = 0
Case 1 ; "Toggle Menu"
If IsMenu(0) = 0
CreateMenu(0, WindowID(0))
MenuTitle(" File ")
If IsZoomed_(WindowID(0)) = 0
If IsAeroSnapEnabled() = 0
SetWindowPos_(WindowID(0), #HWND_TOP, 0, 0, WindowWidth(0, #PB_Window_FrameCoordinate), WindowHeight(0, #PB_Window_FrameCoordinate) + MenuHeight(), #SWP_NOMOVE|#SWP_NOZORDER)
Else
SetWindowPos_(WindowID(0), #HWND_TOP, 0, 0, WindowWidth(0, #PB_Window_FrameCoordinate), WindowHeight(0, #PB_Window_FrameCoordinate) + 1 , #SWP_NOMOVE|#SWP_NOZORDER)
offset = 0
SetWindowPos_(WindowID(0), #HWND_TOP, 0, 0, WindowWidth(0, #PB_Window_FrameCoordinate), WindowHeight(0, #PB_Window_FrameCoordinate) - 1 , #SWP_NOMOVE|#SWP_NOZORDER)
EndIf
Else
wp.WINDOWPLACEMENT\Length = SizeOf(WINDOWPLACEMENT)
GetWindowPlacement_(WindowID(0), wp)
wp\rcNormalPosition\bottom + MenuHeight()
SetWindowPlacement_(WindowID(0), wp)
ShowWindow_(WindowID(0), #SW_SHOWMINIMIZED)
ShowWindow_(WindowID(0), #SW_SHOWMAXIMIZED)
EndIf
Else
If IsZoomed_(WindowID(0)) = 0
If IsAeroSnapEnabled() = 0
SetWindowPos_(WindowID(0), #HWND_TOP, 0, 0, WindowWidth(0, #PB_Window_FrameCoordinate), WindowHeight(0, #PB_Window_FrameCoordinate) - MenuHeight(), #SWP_NOMOVE|#SWP_NOZORDER)
Else
SetWindowPos_(WindowID(0), #HWND_TOP, 0, 0, WindowWidth(0, #PB_Window_FrameCoordinate), WindowHeight(0, #PB_Window_FrameCoordinate) + 1 , #SWP_NOMOVE|#SWP_NOZORDER)
offset = 0
SetWindowPos_(WindowID(0), #HWND_TOP, 0, 0, WindowWidth(0, #PB_Window_FrameCoordinate), WindowHeight(0, #PB_Window_FrameCoordinate) - 1 , #SWP_NOMOVE|#SWP_NOZORDER)
EndIf
Else
wp.WINDOWPLACEMENT\Length = SizeOf(WINDOWPLACEMENT)
GetWindowPlacement_(WindowID(0), wp)
wp\rcNormalPosition\bottom - MenuHeight()
SetWindowPlacement_(WindowID(0), wp)
ShowWindow_(WindowID(0), #SW_SHOWMINIMIZED)
ShowWindow_(WindowID(0), #SW_SHOWMAXIMIZED)
EndIf
FreeMenu(0)
EndIf
Case 2 ; "Toggle Statusbar"
If IsStatusBar(0) = 0
CreateStatusBar(0, WindowID(0))
If IsZoomed_(WindowID(0)) = 0
If IsAeroSnapEnabled() = 0
SetWindowPos_(WindowID(0), #HWND_TOP, 0, 0, WindowWidth(0, #PB_Window_FrameCoordinate), WindowHeight(0, #PB_Window_FrameCoordinate) + StatusBarHeight(0), #SWP_NOMOVE|#SWP_NOZORDER)
Else
SetWindowPos_(WindowID(0), #HWND_TOP, 0, 0, WindowWidth(0, #PB_Window_FrameCoordinate), WindowHeight(0, #PB_Window_FrameCoordinate) + 1 , #SWP_NOMOVE|#SWP_NOZORDER)
offset = 0
SetWindowPos_(WindowID(0), #HWND_TOP, 0, 0, WindowWidth(0, #PB_Window_FrameCoordinate), WindowHeight(0, #PB_Window_FrameCoordinate) - 1 , #SWP_NOMOVE|#SWP_NOZORDER)
EndIf
Else
wp.WINDOWPLACEMENT\Length = SizeOf(WINDOWPLACEMENT)
GetWindowPlacement_(WindowID(0), wp)
wp\rcNormalPosition\bottom + StatusBarHeight(0)
SetWindowPlacement_(WindowID(0), wp)
ShowWindow_(WindowID(0), #SW_SHOWMINIMIZED)
ShowWindow_(WindowID(0), #SW_SHOWMAXIMIZED)
EndIf
Else
If IsZoomed_(WindowID(0)) = 0
If IsAeroSnapEnabled() = 0
SetWindowPos_(WindowID(0), #HWND_TOP, 0, 0, WindowWidth(0, #PB_Window_FrameCoordinate), WindowHeight(0, #PB_Window_FrameCoordinate) - StatusBarHeight(0), #SWP_NOMOVE|#SWP_NOZORDER)
Else
SetWindowPos_(WindowID(0), #HWND_TOP, 0, 0, WindowWidth(0, #PB_Window_FrameCoordinate), WindowHeight(0, #PB_Window_FrameCoordinate) + 1 , #SWP_NOMOVE|#SWP_NOZORDER)
offset = 0
SetWindowPos_(WindowID(0), #HWND_TOP, 0, 0, WindowWidth(0, #PB_Window_FrameCoordinate), WindowHeight(0, #PB_Window_FrameCoordinate) - 1 , #SWP_NOMOVE|#SWP_NOZORDER)
EndIf
Else
wp.WINDOWPLACEMENT\Length = SizeOf(WINDOWPLACEMENT)
GetWindowPlacement_(WindowID(0), wp)
wp\rcNormalPosition\bottom - StatusBarHeight(0)
SetWindowPlacement_(WindowID(0), wp)
ShowWindow_(WindowID(0), #SW_SHOWMINIMIZED)
ShowWindow_(WindowID(0), #SW_SHOWMAXIMIZED)
EndIf
FreeStatusBar(0)
EndIf
EndSelect
EndSelect
Until event = #PB_Event_CloseWindow