|
|
Title | Get and set another application's placement |
Keywords | application, position, placement, move, size |
Categories | API |
|
|
Use the FindWindow API function to get the application's window handle. To get the application's position, use GetPlacement. To set its position, use SetWindowPlacement.
|
|
' Get the window's placement.
Private Sub Command1_Click()
Dim target_hwnd As Long
Dim wp As WINDOWPLACEMENT
target_hwnd = FindWindow(vbNullString, txtCaption.Text)
wp.Length = Len(wp)
GetWindowPlacement target_hwnd, wp
If wp.flags And WPF_RESTORETOMAXIMIZED Then
chkRestoreToMaximized.Value = vbChecked
Else
chkRestoreToMaximized.Value = vbUnchecked
End If
If wp.flags And WPF_SETMINPOSITION Then
chkSetMinPosition.Value = vbChecked
Else
chkSetMinPosition.Value = vbUnchecked
End If
optState(wp.showCmd).Value = True
txtMinX.Text = wp.ptMinPosition.X
txtMinY.Text = wp.ptMinPosition.Y
txtMaxX.Text = wp.ptMaxPosition.X
txtMaxY.Text = wp.ptMaxPosition.Y
txtNormalLeft.Text = wp.rcNormalPosition.Left
txtNormalRight.Text = wp.rcNormalPosition.Right
txtNormalTop.Text = wp.rcNormalPosition.Top
txtNormalBottom.Text = wp.rcNormalPosition.Bottom
End Sub
' Set the window's placement.
Private Sub Command2_Click()
Dim target_hwnd As Long
Dim wp As WINDOWPLACEMENT
Dim i As Integer
wp.Length = Len(wp)
wp.flags = 0
If chkRestoreToMaximized.Value = vbChecked Then
wp.flags = wp.flags Or WPF_RESTORETOMAXIMIZED
End If
If chkSetMinPosition.Value = vbChecked Then
wp.flags = wp.flags Or WPF_SETMINPOSITION
End If
For i = 0 To optState.UBound
If optState(i).Value Then
wp.showCmd = i
Exit For
End If
Next i
wp.ptMinPosition.X = CLng(txtMinX.Text)
wp.ptMinPosition.Y = CLng(txtMinY.Text)
wp.ptMaxPosition.X = CLng(txtMaxX.Text)
wp.ptMaxPosition.Y = CLng(txtMaxY.Text)
wp.rcNormalPosition.Left = CLng(txtNormalLeft.Text)
wp.rcNormalPosition.Right = CLng(txtNormalRight.Text)
wp.rcNormalPosition.Top = CLng(txtNormalTop.Text)
wp.rcNormalPosition.Bottom = CLng(txtNormalBottom.Text)
target_hwnd = FindWindow(vbNullString, txtCaption.Text)
SetWindowPlacement target_hwnd, wp
End Sub
|
|
|
|
|
|