Snap you app to the side of the screen (like ICQ does.. Resizing desktop.. not just moving the form)
This code uses the SystemParametersInfo API to change the work space area of the desktop. You can make you app 'lock' to either top/bottom/left or right of the screen very simply.
AI
Resumo por IA: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
Código fonte
Sub UnDockForm(vbForm As Form)
' This sub does the opposite of DockForm basicly.
Dim Desktop As RECT
' Get the Work space area of the desktop
SystemParametersInfo SPI_GETWORKAREA, 0&, Desktop, 0&
With Desktop ' change the values back to normal
Select Case LastDock
Case DockBottom
.Bottom = .Bottom + DockAmount
Case DockLeft
.Left = .Left - DockAmount
Case DockTop
.Top = .Top - DockAmount
Case DockRight
.Right = .Right + DockAmount
Case Else
Exit Sub ' no dock performed
End Select
End With
' Now set the form back to normal
With vbFormOldRect
vbForm.Move .vbLeft, .vbTop, .vbWidth, .vbHeight
End With
' Now, update the SystemParams again..
SystemParametersInfo SPI_SETWORKAREA, 0&, Desktop, SPIF_SENDWININICHANGE
' And clear LastDock
LastDock = 0
' And thats it. Should all be good =]
End Sub
Sub DockForm(vbForm As Form, DockPos As DockTypes)
' Notes - YOU *MUST* run UnDock before closing program
' otherwise the desktop will remain 'clipped'
If LastDock <> 0 Then
' form is already docked... you really don't want to dock it somewhere else
MsgBox "Please don't re-dock without un-docking.", vbOKOnly, "Docking aborted"
Exit Sub
End If
' FIRST, save the RECT of vbForm
With vbFormOldRect
.vbHeight = vbForm.Height
.vbLeft = vbForm.Left
.vbTop = vbForm.Top
.vbWidth = vbForm.Width
End With
Dim Desktop As RECT
'Get the Current Desktop Work Area
SystemParametersInfo SPI_GETWORKAREA, 0&, Desktop, 0&
' Now, resize the form to what we want it to be
Dim V As vbRECT
V = vbFormOldRect ' (aka current window size)
With V
Select Case DockPos
Case DockLeft
.vbTop = (Desktop.Top * 15)
.vbLeft = (Desktop.Left * 15)
.vbHeight = (Desktop.Bottom * 15) - .vbTop
Case DockRight
.vbTop = (Desktop.Top * 15)
.vbLeft = (Desktop.Right * 15) - .vbWidth
.vbHeight = (Desktop.Bottom * 15) - .vbTop
Case DockBottom
.vbTop = (Desktop.Bottom * 15) - .vbHeight
.vbLeft = (Desktop.Left * 15)
.vbWidth = (Desktop.Right * 15) - .vbLeft
Case DockTop
.vbTop = (Desktop.Top * 15)
.vbLeft = (Desktop.Left * 15)
.vbWidth = (Desktop.Right * 15) - .vbLeft
Case Else
Exit Sub
End Select
End With
' Now, Modify the Desktop values
With Desktop
Select Case DockPos
Case DockBottom
DockAmount = (vbForm.Height / 15)
.Bottom = .Bottom - DockAmount
Case DockRight
DockAmount = (vbForm.Width / 15)
.Right = .Right - DockAmount
Case DockTop
DockAmount = (vbForm.Height / 15)
.Top = .Top + DockAmount
Case DockLeft
DockAmount = (vbForm.Width / 15)
.Left = .Left + DockAmount
End Select
End With
' Now all is needed is to Update the sysParams..
SystemParametersInfo SPI_SETWORKAREA, 0&, Desktop, SPIF_SENDWININICHANGE
' Note: SPIF_SENDWININICHANGE saves us from using
' SendMessage HWND_BROADCAST, WM_SETTINGSCHANGE, SPI_SETWORKAREA, Desktop
' to update all the windows.
With V
vbForm.Move .vbLeft, .vbTop, .vbWidth, .vbHeight
End With
' Cool, and it's that simple. Now set the LastDock variable for UnDock.
LastDock = DockPos
End Sub
Comentários originais (3)
Recuperado do Wayback Machine