Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Public Module MDIUtil
#Region " Bordo interno (sunken) "
<DllImport("user32.dll")> _
Private Function GetWindowLong(hWnd As IntPtr, nIndex As Integer) As Integer
End Function
<DllImport("user32.dll")> _
Private Function SetWindowLong(hWnd As IntPtr, nIndex As Integer, dwNewLong As Integer) As Integer
End Function
<DllImport("user32.dll", ExactSpelling:=True)> _
Private Function SetWindowPos(hWnd As IntPtr, hWndInsertAfter As IntPtr, X As Integer, Y As Integer, cx As Integer, cy As Integer, _
uFlags As UInteger) As Integer
End Function
Private Const GWL_EXSTYLE As Integer = -20
Private Const WS_EX_CLIENTEDGE As Integer = &H200
Private Const SWP_NOSIZE As UInteger = &H1
Private Const SWP_NOMOVE As UInteger = &H2
Private Const SWP_NOZORDER As UInteger = &H4
Private Const SWP_NOREDRAW As UInteger = &H8
Private Const SWP_NOACTIVATE As UInteger = &H10
Private Const SWP_FRAMECHANGED As UInteger = &H20
Private Const SWP_SHOWWINDOW As UInteger = &H40
Private Const SWP_HIDEWINDOW As UInteger = &H80
Private Const SWP_NOCOPYBITS As UInteger = &H100
Private Const SWP_NOOWNERZORDER As UInteger = &H200
Private Const SWP_NOSENDCHANGING As UInteger = &H400
''' <summary>
''' Consente di rimuovere il bordo 3D interno della form MDI (sunken).
''' Vedi post: http://stackoverflow.com/questions/7752696/how-to-remove-3d-border-sunken-from-mdiclient-component-in-mdi-parent-form
''' Oppure articolo: http://www.codeproject.com/Articles/8489/Getting-a-quot-Handle-quot-on-the-MDI-Client#Changing%20the%20Border%20Styles:
''' </summary>
''' <param name="form"></param>
''' <param name="show">False per rimuovere il sunken (3D interno), True per mostrarlo</param>
''' <returns></returns>
<System.Runtime.CompilerServices.Extension>
Public Function SetBevel(form As Form, show As Boolean) As Boolean
For Each c As Control In form.Controls
Dim client As MdiClient = TryCast(c, MdiClient)
If client IsNot Nothing Then
Dim windowLong As Integer = GetWindowLong(c.Handle, GWL_EXSTYLE)
If show Then
windowLong = windowLong Or WS_EX_CLIENTEDGE
Else
windowLong = windowLong And Not WS_EX_CLIENTEDGE
End If
SetWindowLong(c.Handle, GWL_EXSTYLE, windowLong)
' Update the non-client area.
SetWindowPos(client.Handle, IntPtr.Zero, 0, 0, 0, 0, _
SWP_NOACTIVATE Or SWP_NOMOVE Or SWP_NOSIZE Or SWP_NOZORDER Or SWP_NOOWNERZORDER Or SWP_FRAMECHANGED)
Return True
End If
Next
Return False
End Function
#End Region
End Module