?
Solved

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

Posted on 2008-11-12
2
Medium Priority
?
555 Views
Last Modified: 2013-11-08
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

0
Comment
Question by:cobolinx1
2 Comments
 
LVL 23

Accepted Solution

by:
Snarf0001 earned 2000 total points
ID: 22940064
I've had much better luck using MoveWindow in the past instead of SetWindowPos.

As well, i generally use the SetWindowLong to take off the window border of the embedded app, so the user can't move it around.

For some reason (not sure why), SetWindowLong doesn't seem to work well with the "declare function" import, you need to use the full DllImport, if you even want to take off the window border.
Private Declare Function SetParent Lib "user32" Alias "SetParent" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Integer
Private Declare Function MoveWindow Lib "user32" Alias "MoveWindow" (ByVal hWnd As IntPtr, ByVal x As Integer, ByVal y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal repaint As Boolean) As Boolean
Private Const GWL_STYLE As Integer = (-16)
Private Const WS_VISISBLE As Integer = &H10000000
 
 
<DllImport("user32.dll", EntryPoint:="SetWindowLongA", SetLastError:=True)> _
Private Shared Function SetWindowLong(ByVal hwnd As IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer
End Function
 
 
 
Dim p As Process = Process.Start("wordpad")
p.WaitForInputIdle()
 
'set the parent to the panel
SetParent(p.MainWindowHandle, Panel1.Handle)
 
'take off the window border
SetWindowLong(p.MainWindowHandle, GWL_STYLE, WS_VISISBLE)
 
'move to the dimensions of the panel
MoveWindow(p.MainWindowHandle, 0, 0, Panel1.Width, Panel1.Height, True)

Open in new window

0
 

Author Closing Comment

by:cobolinx1
ID: 31515928
perfect
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Is your organization moving toward a cloud and mobile-first environment? In this transition, your IT department will encounter many challenges, such as navigating how to: Deploy new applications and services to a growing team Accommodate employee…
Suggested Courses

616 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question