Snippet
Imports System.Windows.Forms
Friend Class m2s87
Inherits System.Windows.Forms.Form
Public Declare Function GetWindowPlacement Lib "User32" (ByVal hWnd As Integer, ByRef lpwndpl As WINDOWPLACEMENT) As Integer
Public Declare Function DrawFrameControl Lib "User32" (ByVal hdc As Integer, ByRef lpRect As RECT, ByVal un1 As Integer, ByVal un2 As Integer) As Integer
Public Declare Function SetRect Lib "User32" (ByRef lpRect As RECT, ByVal X1 As Integer, ByVal Y1 As Integer, ByVal X2 As Integer, ByVal Y2 As Integer) As Integer
Public Declare Function GetCursorPos Lib "User32" (ByRef lpPoint As POINTAPI) As Integer
Private Declare Function SHAppBarMessage Lib "Shell32" (ByVal dwMessage As ABM_, ByRef pData As APPBARDATA) As Integer
Private Declare Function SetWindowPos Lib "User32" (ByVal hWnd As Integer, ByVal hwndInsertAfter As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer
Event m2s87Load(ByVal x As Object)
Public Structure RECT
Dim Left As Integer
Dim Top As Integer
Dim Right As Integer
Dim Bottom As Integer
End Structure
Structure POINTAPI
Dim X As Integer
Dim Y As Integer
End Structure
Structure WINDOWPLACEMENT
Dim Length As Integer
Dim flags As Integer
Dim ShowCmd As Integer
Dim ptMinPosition As POINTAPI
Dim ptMaxPosition As POINTAPI
Dim rcNormalPosition As RECT
End Structure
Structure APPBARDATA
Dim cbSize As Integer
Dim hWnd As Integer
Dim uCallbackMessage As Integer
Dim uEdge As Integer
Dim rc As RECT
Dim lParam As Integer
End Structure
Public Enum DockWhere As Integer
LEFT = &H0S
TOP = &H1S
RIGHT = &H2S
BOTTOM = &H3S
NONE = -1
End Enum
Public Enum ABM_ As Integer
_NEW = &H0S
_REMOVE = &H1S
_SETPOS = &H3S
_GETTASKBARPOS = &H5S
End Enum
Const HWND_TOPMOST As Short = -1
Const SWP_NOSIZE As Short = &H1S
Const SWP_NOMOVE As Short = &H2S
Public Const DFC_BUTTON As Short = 4
Public Const DFCS_BUTTON3STATE As Short = &H10S
Public Ymin, Xmin, Xmax, Ymax As Integer
Public Docked As Boolean
Public WPL As WINDOWPLACEMENT
Public PxSense As Integer = 20
Public DockMode As DockWhere
Dim APD As APPBARDATA
Dim vaba As Rectangle = System.Windows.Forms.Screen.PrimaryScreen.Bounds
Dim WithEvents taimer As New System.Windows.Forms.Timer
Private components As System.ComponentModel.IContainer
Friend myY As Integer = 212
Friend myX As Integer = 212
Public Sub New()
taimer.Interval = 50
taimer.Enabled = True
Xmin = PxSense
Ymin = PxSense
Xmax = CInt(vaba.Width - PxSense)
Ymax = CInt(vaba.Height - PxSense)
End Sub
Private Sub InitializeComponent()
Me.SuspendLayout()
'
'm2s87
'
Me.ClientSize = New System.Drawing.Size(292, 268)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "m2s87"
Me.ShowInTaskbar = False
Me.ResumeLayout(False)
End Sub
Private Sub Hetk(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles taimer.Tick
If Docked Then Exit Sub
taimer.Enabled = False
WPL.Length = Len(WPL)
Call GetWindowPlacement(Me.Handle.ToInt32, WPL)
If DockMode <> DockWhere.NONE Then
Call InitAppBar()
End If
taimer.Enabled = True
End Sub
Public Sub InitAppBar()
Dim X, Y As Integer
Dim Fw, Fx, Fy, Fh As Integer
Dim TPos As APPBARDATA
Docked = True
Call SHAppBarMessage(ABM_._GETTASKBARPOS, TPos)
Y = myY
X = myX
Call SHAppBarMessage(ABM_._NEW, APD)
Select Case DockMode
Case DockWhere.LEFT : With APD
.uEdge = DockWhere.LEFT
.rc.Top = 0
.rc.Left = 0
.rc.Right = X
.rc.Bottom = TPos.rc.Top
End With
Fx = 0
Fy = 0
Fw = X
Fh = TPos.rc.Top
Case DockWhere.TOP : With APD
.uEdge = DockWhere.TOP
.rc.Top = 0
.rc.Left = 0
.rc.Right = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width
.rc.Bottom = Y
End With
Fx = 0
Fy = 0
Fw = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width
Fh = Y
Case DockWhere.RIGHT : With APD
.uEdge = DockWhere.RIGHT
.rc.Top = 0
.rc.Left = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width - X '- FrameX
.rc.Right = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width
.rc.Bottom = Y
End With
Fx = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width - X
Fy = 0
Fw = X
Fh = TPos.rc.Top
Case DockWhere.BOTTOM : With APD
.uEdge = DockWhere.BOTTOM
.rc.Top = TPos.rc.Top - Y
.rc.Left = 0
.rc.Right = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width
.rc.Bottom = TPos.rc.Top
End With
Fx = 0
Fy = TPos.rc.Top - Y
Fw = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width
Fh = Y
End Select
Call SHAppBarMessage(ABM_._SETPOS, APD)
System.Windows.Forms.Application.DoEvents()
With Me
'.Show()
Call SetWindowPos(.Handle.ToInt32, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE)
.Top = Fy
.Left = Fx
.Width = Fw
.Height = Fh
End With
End Sub
Public Sub ExitAppBar()
taimer.Enabled = False
If Docked Then Call SHAppBarMessage(ABM_._REMOVE, APD)
Docked = False
DockMode = DockWhere.NONE
End Sub
Private Sub m2s87_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.DoubleClick
End Sub
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
ExitAppBar()
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
MyBase.Dispose(disposing)
End Sub
End Class
Copy & Paste
|