Title | Restore a window to a known position if you can't find it in Visual Basic 2005 |
Description | This example shows how to restore a window to a known position if you can't find it in Visual Basic 2005. |
Keywords | restore window, window size, window position, FindWindow, SetWindowPos, Visual Basic, Visual Basic 2005, VB .NET |
Categories | Controls, Software Engineering |
|
Private Declare Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName As String, ByVal _
lpWindowName As String) As Integer
Private Declare Function SetWindowPos Lib "user32" Alias _
"SetWindowPos" (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
' Find the target window and restore it.
Private Sub btnGo_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnGo.Click
' Find the target.
Dim app_hwnd As Long = FindWindow(vbNullString, _
txtTitle.Text)
If app_hwnd = 0 Then
MessageBox.Show("Cannot find application " & _
txtTitle.Text, _
"Application Not Found", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
Exit Sub
End If
' Position the window.
SetWindowPos(app_hwnd, 0, _
Val(txtLeft.Text), _
Val(txtTop.Text), _
Val(txtWidth.Text), _
Val(txtHeight.Text), _
0)
End Sub
|