-
Oct 4th, 2011, 04:34 PM
#1
Thread Starter
New Member
OLE Question
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.
-
Oct 4th, 2011, 04:39 PM
#2
-
Oct 4th, 2011, 04:41 PM
#3
Thread Starter
New Member
Re: OLE Question
:O Why?
I need to embed a .exe file into a form.... any other way of doing this?
-
Oct 4th, 2011, 04:44 PM
#4
Re: OLE Question
Originally Posted by SgtJulian
:O Why?
I need to embed a .exe file into a form.... any other way of doing this?
What are you trying to do as an end result? Embedding something is only part of a solution.
-
Oct 4th, 2011, 04:45 PM
#5
Thread Starter
New Member
Re: OLE Question
Originally Posted by kevininstructor
What are you trying to do as an end result? Embedding something is only part of a solution.
I'm trying to "embed" an exe into my project so that by pushing a button it appears in a form... Sorry if I don't explain myself well...
-
Oct 4th, 2011, 04:47 PM
#6
Re: OLE Question
Originally Posted by SgtJulian
I'm trying to "embed" an exe into my project so that by pushing a button it appears in a form... Sorry if I don't explain myself well...
What is the purpose of this executable?
Did you write it or someone else?
-
Oct 4th, 2011, 04:56 PM
#7
Thread Starter
New Member
Re: OLE Question
Originally Posted by kevininstructor
What is the purpose of this executable?
Did you write it or someone else?
Someone else wrote it... I'm trying to make like a swiss army knife sort of application...
-
Oct 4th, 2011, 05:06 PM
#8
Re: OLE Question
Originally Posted by SgtJulian
Someone else wrote it... I'm trying to make like a swiss army knife sort of application...
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.
-
Oct 4th, 2011, 05:21 PM
#9
Thread Starter
New Member
Re: OLE Question
Originally Posted by kevininstructor
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.
The thing is that the point of the app is that it is portable... How would I go about doing what you just said? Thanks for your help.
-
Oct 4th, 2011, 05:52 PM
#10
Re: OLE Question
Look up setparent API
Kris
-
Oct 4th, 2011, 08:44 PM
#11
Re: OLE Question
as i00 said, the setParent API will allow you to embed an executable in a container (form, panel, or something)
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 4th, 2011, 10:52 PM
#12
Re: OLE Question
Here is a working example of embedding an external app into a form
http://www.vbforums.com/showpost.php...24&postcount=2
-
Oct 5th, 2011, 09:58 AM
#13
Thread Starter
New Member
Re: OLE Question
Thanks for your help guys. I will post back with results.
-
Oct 5th, 2011, 10:46 AM
#14
Thread Starter
New Member
Re: OLE Question
Neither of those methods worked for me o_0.. I am lost :O
-
Oct 5th, 2011, 11:18 AM
#15
Re: OLE Question
Originally Posted by SgtJulian
Neither of those methods worked for me o_0.. I am lost :O
When you say neither method works nobody can help if you do not explain in detail what happened.
-
Oct 5th, 2011, 11:21 AM
#16
Re: OLE Question
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
-
Oct 5th, 2011, 11:32 AM
#17
Thread Starter
New Member
Re: OLE Question
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.
-
Oct 5th, 2011, 11:40 AM
#18
Re: OLE Question
Originally Posted by SgtJulian
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.
Change
Code:
SetParent(notepad_hWnd, Me.Handle)
To (change the name of the panel to the name of your panel)
Code:
SetParent(notepad_hWnd, Panel1.Handle)
-
Oct 5th, 2011, 12:11 PM
#19
Thread Starter
New Member
Re: OLE Question
Originally Posted by kevininstructor
Change
Code:
SetParent(notepad_hWnd, Me.Handle)
To (change the name of the panel to the name of your panel)
Code:
SetParent(notepad_hWnd, Panel1.Handle)
Man you are awesome!
EDIT: I got it!!! Made a new form and presto... weird fix o.0
Thank you so much kevininstructor and everyone else!!
Last edited by SgtJulian; Oct 5th, 2011 at 12:38 PM.
-
Oct 5th, 2011, 12:51 PM
#20
Re: OLE Question
Originally Posted by SgtJulian
Man you are awesome!
EDIT: I got it!!! Made a new form and presto... weird fix o.0
Thank you so much kevininstructor and everyone else!!
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
-
Oct 21st, 2011, 02:23 AM
#21
Lively Member
Re: OLE Question
Hi, Kevin,
I've tried your code with your exe and it works well.
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
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.
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|