Hi all,
I have read several tutorials about an "OLE Container," but I've looked and looked and I can find no such thing in my Visual Basic (Part of Visual Studio 2010)
Can anyone help a noob?
Thanks in advance.
Printable View
Hi all,
I have read several tutorials about an "OLE Container," but I've looked and looked and I can find no such thing in my Visual Basic (Part of Visual Studio 2010)
Can anyone help a noob?
Thanks in advance.
It does not exists in VS2010 see the following http://msdn.microsoft.com/en-us/libr...(v=VS.90).aspx
:O Why?
I need to embed a .exe file into a form.... any other way of doing this?
Your best option is to include the executable in your installation, place it in a known folder and then call it using Process.Start which does not start it in your form but by itself.
Now lets say you wanted to embedded something that could be shown in a web browser you could easily do that but not an executable file.
Look up setparent API
Kris
as i00 said, the setParent API will allow you to embed an executable in a container (form, panel, or something)
Here is a working example of embedding an external app into a form
http://www.vbforums.com/showpost.php...24&postcount=2
Thanks for your help guys. I will post back with results.
Neither of those methods worked for me o_0.. I am lost :O
Here is an example which requires ColorCop to be in the same folder as the code executing below.
I have been using Color Cop for years now which is why I used it for the demo code below which works fine as with the code below.
One form, one button
Code:Public Class Form1
Dim notepad_hWnd As IntPtr = IntPtr.Zero
Public Const GWL_STYLE As Integer = (-16)
Public Const WS_BORDER As Integer = &H800000
Public Declare Function IsWindow Lib "user32" Alias "IsWindow" (ByVal hwnd As IntPtr) As Integer
Public Declare Function SetParent Lib "user32" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As IntPtr
Public 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
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As IntPtr, ByVal nIndex As Integer) As Integer
Private ProgramToEmbed As String = IO.Path.Combine(Application.StartupPath, "ColorCop.exe")
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MyPSI As New ProcessStartInfo(ProgramToEmbed)
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 program", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Button1.Enabled = IO.File.Exists(ProgramToEmbed)
End Sub
End Class
Got it. Sorry for not replying in detail. In the end I had to change the name of application.exe in the project's files, for some reason, VB was saving it as application.exe.deploy
Your previous code worked like a charm, kevininstructor.
Now I'm trying to figure out how to use it in a panel.
The real thanks should go to EdgeMeal for his solution here http://www.vbforums.com/showpost.php...24&postcount=2
Any ways glad you have a solution now :)
Hi, Kevin,
I've tried your code with your exe and it works well.
I have a folder with several someone else executables for simple calculations (total size is only 1,5 MB). I am not sure but it looks like a console application.Code:Private ProgramToEmbed As String = IO.Path.Combine(Application.StartupPath, "MENU.EXE")
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(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MyPSI As New ProcessStartInfo(ProgramToEmbed)
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 program", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Button1.Enabled = IO.File.Exists(ProgramToEmbed)
End Sub
Please look at attached picture. I have a two possibilities to start program:
- click on MENU.EXE , then select one from the list of 19 subprograms or
- click on one of other 19 executables (C2 - C38).
I don't know what is BASRUN.EXE and other two files in picture.
All these files I have copied to bin - debug folder of my project and I try your code with name of exe: MENU.EXE but I received an message: Unable to launch program.
I do not know if there is a chance to get this resolved. It appears to me that these executables somehow interconnected with each other.
Does anyone know the solution?
Onenew
http://img853.imageshack.us/img853/7122/programi.png