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
|
Imports System.Runtime.InteropServices
Public Class Form1
Private p As Process
<DllImport("user32.dll", SetLastError:=True)> _
Shared Function SetParent(ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As IntPtr
End Function
<DllImport("user32.dll")> _
Shared Function SetWindowPos(ByVal hWnd As IntPtr, ByVal hWndInsertAfter As IntPtr, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal uFlags As UInteger) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
Private Shared ReadOnly HWND_TOP As New IntPtr(0)
Public Const SWP_NOACTIVATE As Integer = &H10
Public Const SWP_SHOWWINDOW As Integer = &H40
'Public Function StartProcess(ByVal ProcessName As String, ByVal ContainerHandle As IntPtr, ByVal Rect As Rectangle) As Boolean
Public Function StartProcess(ByVal ProcessName As String, ByVal ContainerHandle As IntPtr) As Boolean
Try
p = New Process()
p.StartInfo.FileName = ProcessName
p.Start()
p.WaitForInputIdle(-1)
'SetWindowPos(p.MainWindowHandle, HWND_TOP, Rect.Left, Rect.Top, Rect.Width, Rect.Height, SWP_NOACTIVATE Or SWP_SHOWWINDOW)
SetWindowPos(p.MainWindowHandle, HWND_TOP, 0, 0, 1920, 1080, SWP_NOACTIVATE Or SWP_SHOWWINDOW)
SetWindowPos(p.MainWindowHandle, IntPtr.Zero, 50, 50, 60, 50, 0)
Catch ex As Exception
Return False
End Try
Return True
End Function
Public Function ParentResize(ByVal rect As Rectangle) As Boolean
Try
SetWindowPos(p.MainWindowHandle, HWND_TOP, rect.Left, rect.Top, rect.Width, rect.Height, SWP_NOACTIVATE Or SWP_SHOWWINDOW)
Catch ex As Exception
Return False
End Try
Return True
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
StartProcess("C:\Windows\System32\notepad.exe", Me.Handle)
End Sub
End Class |
Partager