Quote Originally Posted by andrecito77 View Post
What I want is for "notepad" to open up maximized and without a border. I already have it maximized, but I want the border gone.

How can I do this?
Also how can I make my current form the same size as the process?
Use the GetWindowRect API to get the size of a window.
As far as removing notepads border you might want to look at the Get/SetWindowLong APIs and their flags, then to make notepad fit inside the form (maximized ) I just used MoveWindow.

I tried it like this in WinXP-32 and Win7-64 and seemed to work OK when compiled for x86...

Code:
Public Class Form1

    Dim notepad_hWnd As IntPtr = IntPtr.Zero

    Private Const GWL_STYLE As Integer = (-16)
    Private Const WS_BORDER As Integer = &H800000
    Private Declare Function IsWindow Lib "user32" Alias "IsWindow" (ByVal hwnd As IntPtr) As Integer
    Private Declare Function SetParent Lib "user32" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As IntPtr
    Private Declare Function MoveWindow Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal X As Int32, ByVal Y As Int32, ByVal nWidth As Int32, ByVal nHeight As Int32, ByVal bRepaint As Boolean) As Boolean
    Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer
    Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As IntPtr, ByVal nIndex As Integer) As Integer

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

        Dim MyPSI As New ProcessStartInfo("notepad.exe")
        Try
            Dim MyProcess As Process = Process.Start(MyPSI)
            MyProcess.WaitForInputIdle()
            notepad_hWnd = MyProcess.MainWindowHandle

            If notepad_hWnd <> IntPtr.Zero Then
                Me.Text = MyProcess.MainWindowTitle
                ' set parent
                SetParent(notepad_hWnd, Me.Handle)
                ' remove notepad border
                SetWindowLong(notepad_hWnd, GWL_STYLE, GetWindowLong(notepad_hWnd, GWL_STYLE) + WS_BORDER)
                ' size notepad to forms client size
                MoveWindow(notepad_hWnd, 0, 0, Me.ClientSize.Width, Me.ClientSize.Height, True)
            End If
        Catch ex As Exception
            MessageBox.Show("Unable to launch notepad.exe", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try

    End Sub

    Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

        ' if notepad still running put it on the desktop or it will be running in background!
        If notepad_hWnd <> IntPtr.Zero Then
            If IsWindow(notepad_hWnd) <> 0 Then
                ' re-enable notepad border?
                SetWindowLong(notepad_hWnd, GWL_STYLE, GetWindowLong(notepad_hWnd, GWL_STYLE) + WS_BORDER)
                ' move notepad to desktop
                SetParent(notepad_hWnd, IntPtr.Zero)
            End If
        End If

    End Sub

End Class