Link to home
Start Free TrialLog in
Avatar of cobolinx1
cobolinx1

asked on

How to set the window size of a process to the size of a panel

I'm embedding notepad (it could be any executable) in a panel and I'm trying to set the size of the process to the size of the panel with no luck. Is it possible to maximize the process so it fills in the whole panel?


Private Declare Function SetParent Lib "user32" Alias "SetParent" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) 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
    Private Const SWP_NOSIZE As Integer = &H1
 
 
'load wordpad in the panel
        Dim p As Process = Process.Start("wordpad")
        p.WaitForInputIdle()
        SetParent(p.MainWindowHandle, Panel1.Handle)
'try and set wordpad equal to the size of the panel        
 Dim hWnd As Integer
        hWnd = p.Handle.ToInt32 ' however you get your hWnd...
 
       SetWindowPos(hWnd, 0, Panel1.Size.Width.ToString, Panel1.Size.Height.ToString(), 0, 0, SWP_NOSIZE)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Snarf0001
Snarf0001
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cobolinx1
cobolinx1

ASKER

perfect