1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| <DllImport("user32.dll")> _
Private Shared Function SetWindowLong(ByVal hWnd As IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer
End Function
<DllImport("User32.dll", EntryPoint:="GetWindowLong")> _
Private Shared Function GetWindowLong(ByVal HWND As IntPtr, ByVal Index As Integer) As Integer
End Function
<DllImport("user32.dll")> _
Private Shared Function SetWindowPos(ByVal hWnd As IntPtr, ByVal hWndInsertAfter As IntPtr, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, _
ByVal uFlags As UInteger) As Boolean
End Function
Const WS_MAXIMIZE As Integer = &H1000000
Const GWL_STYLE As Integer = -16
Const WM_SYSCOMMAND As Integer = &H112
Const SC_MAXIMIZE As Integer = &HF030
Const SC_RESTORE As Integer = &HF120
Private HWND_TOP As IntPtr = CType(0, IntPtr)
Const SWP_SHOWWINDOW As Integer = &H40
Const SWP_NOZORDER As Integer = &H4
Const SWP_NOMOVE As Integer = &H2
Const SWP_DRAWFRAME As Integer = &H20
Protected Overrides Sub WndProc(ByRef m As Message)
If m.Msg = WM_SYSCOMMAND Then
If CInt(m.WParam) = SC_MAXIMIZE Then
'MessageBox.Show("Maximized!!")
Dim iStyle As Integer = GetWindowLong(Me.Handle, GWL_STYLE)
SetWindowLong(Me.Handle, GWL_STYLE, iStyle Or WS_MAXIMIZE)
SetWindowPos(Me.Handle, HWND_TOP, 0, 0, Me.Width + 50, Me.Height + 50, _
SWP_DRAWFRAME Or SWP_NOMOVE Or SWP_NOZORDER Or SWP_SHOWWINDOW)
Return
End If
If CInt(m.WParam) = SC_RESTORE Then
'MessageBox.Show("Restored down!!")
Dim iStyle As Integer = GetWindowLong(Me.Handle, GWL_STYLE)
SetWindowLong(Me.Handle, GWL_STYLE, iStyle And Not WS_MAXIMIZE)
SetWindowPos(Me.Handle, HWND_TOP, 0, 0, Me.Width - 50, Me.Height - 50, _
SWP_DRAWFRAME Or SWP_NOMOVE Or SWP_NOZORDER Or SWP_SHOWWINDOW)
Return
End If
End If
MyBase.WndProc(m)
End Sub |
Partager