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 46
|
Imports System.Runtime.InteropServices
Public Class Form1
Private myProcess As Process
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'Dim pi As New ProcessStartInfo
'pi.FileName = "notepad"
'myProcess = New Process
'myProcess.StartInfo = pi
'myProcess.Start()
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
StartProcess()
If myProcess Is Nothing Then Return
myProcess.WaitForInputIdle()
Dim handle As IntPtr = myProcess.MainWindowHandle
If handle <> IntPtr.Zero Then
SetWindowPos(handle, 0, 150, 0, 400, 250, 0)
End If
End Sub
Private Sub StartProcess()
Dim pi As New ProcessStartInfo
pi.FileName = "notepad"
myProcess = New Process
myProcess.StartInfo = pi
myProcess.Start()
End Sub
Private Sub Form1_FormClosing(sender As System.Object, e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
If myProcess IsNot Nothing Then
myProcess.WaitForExit()
myProcess.CloseMainWindow()
End If
End Sub
<DllImport("user32.dll", EntryPoint:="SetWindowPos")>
Public Shared Function SetWindowPos(HWND As IntPtr,
hWndInsertAfter As IntPtr,
Xpos As Integer, Ypos As Integer, xSize As Integer, ySize As Integer, wFlags As Integer) As IntPtr
End Function
End Class |
Partager