|
■No96167 (とっちゃん さん) に返信
おお、こんないい方法があったのですね。知りませんでした。
とっちゃんさん、ありがとうございます。
順番を逆にするサンプルを書いてみました。
childForm.Left, childForm.Top, childForm.Width, childForm.Height の部分は回復する位置・大きさに修正してください。
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
Private Shared Function GetWindow(ByVal hWnd As IntPtr, ByVal uCmd As GetWindowType) As IntPtr
End Function
Private Enum GetWindowType As UInteger
GW_HWNDFIRST = 0
GW_HWNDLAST = 1
GW_HWNDNEXT = 2
GW_HWNDPREV = 3
GW_OWNER = 4
GW_CHILD = 5
GW_ENABLEDPOPUP = 6
End Enum
<DllImport("user32.dll", SetLastError:=True)>
Private Shared Function BeginDeferWindowPos(nNumWindows As Integer) As IntPtr
End Function
Private Enum ShowWindowPosition As UInteger
SWP_NOSIZE = &H1
SWP_NOMOVE = &H2
SWP_NOZORDER = &H4
SWP_NOREDRAW = &H8
SWP_NOACTIVATE = &H10
SWP_DRAWFRAME = &H20
SWP_FRAMECHANGED = &H20
SWP_SHOWWINDOW = &H40
SWP_HIDEWINDOW = &H80
SWP_NOCOPYBITS = &H100
SWP_NOOWNERZORDER = &H200
SWP_NOREPOSITION = &H200
SWP_NOSENDCHANGING = &H400
SWP_DEFERERASE = &H2000
SWP_ASYNCWINDOWPOS = &H4000
End Enum
<DllImport("user32.dll", SetLastError:=True)>
Private Shared Function DeferWindowPos(
hWinPosInfo As IntPtr,
hWnd As IntPtr,
hWndInsertAfter As Integer,
x As Integer, y As Integer,
cx As Integer, cy As Integer,
uFlags As ShowWindowPosition) As IntPtr
End Function
<DllImport("user32.dll", SetLastError:=True)>
Private Shared Function EndDeferWindowPos(hWinPosInfo As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
Private Sub ToolStripButton2_Click(sender As Object, e As EventArgs) Handles ToolStripButton2.Click
If Me.MdiChildren.Count > 0 Then
Dim orderList As New List(Of Form)
Dim childHwnd As IntPtr = GetWindow(Me.MdiChildren(0).Handle, GetWindowType.GW_HWNDLAST)
While childHwnd <> IntPtr.Zero
Dim childForm As Form = Control.FromHandle(childHwnd)
orderList.Add(childForm)
childHwnd = GetWindow(childHwnd, GetWindowType.GW_HWNDPREV)
End While
Dim dwp As IntPtr = BeginDeferWindowPos(orderList.Count)
Dim prev As IntPtr = IntPtr.Zero
For Each childForm As Form In orderList
childForm.WindowState = FormWindowState.Normal
DeferWindowPos(dwp, childForm.Handle, prev, childForm.Left, childForm.Top, childForm.Width, childForm.Height, 0)
prev = childForm.Handle
Next
EndDeferWindowPos(dwp)
End If
End Sub
|