|
|
Comments and Discussions
|
|
 |
|

|
Hi, i have tried to host an application inside a web panel of a form and all works except that thebuttons and textbox are not invoking the methods corresponding to its events
It works fine if i dont bind it with panel
Some one could help me ???
plzzz
|
|
|
|

|
i tryed with windows 7 and dont works.. Some1 have a solution?
|
|
|
|

|
Please help me, how to open External exe application in a WPF Window. Thanks...
Below is the code...sample right now..i am using.. let me know what i need to modify in the code below..to work for external exe to launch in WPF window. This is opening application in separately not in WPF Window.
namespace WpfApplication_Blend
{
///
/// Interaction logic for Window1.xaml
///
public partial class Window1 : Window
{
public IntPtr MainWindowHandle { get; set; }
[DllImport("user32.dll", SetLastError = true)]
private static extern long SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
//[DllImport("user32.dll", SetLastError = true)]
//private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
public Window1()
{
InitializeComponent();
try
{
//External exe inside WPF Window
System.Windows.Forms.Panel _pnlSched = new System.Windows.Forms.Panel();
WindowsFormsHost windowsFormsHost1 = new WindowsFormsHost();
windowsFormsHost1.Child = _pnlSched;
_Grid.Children.Add(windowsFormsHost1);
ProcessStartInfo psi = new ProcessStartInfo(@"C:\Program Files\Atwin\Atwin2k2.exe");
psi.WindowStyle = ProcessWindowStyle.Normal;
Process PR = Process.Start(psi);
PR.WaitForInputIdle(); // true if the associated process has reached an idle state.
SetParent(PR.MainWindowHandle, _pnlSched.Handle); // loading exe to the wpf window.
}
catch (Exception ex)
{
//Nothing...
}
}
}
}
modified 27 May '12 - 13:12.
|
|
|
|

|
I tried running the exes it does not work in WIndows 7.
Need different way of handling it.
Any suggestion will be much appreciated.
|
|
|
|

|
Some programs can take a second or two to start.
When this happens, you get the program flash up and an entry for it in the taskbar.
It then gets re-parented properly.
Any ideas to stop this?
(Win7 with sleep fix).
|
|
|
|

|
Hi, i have tried to host an application inside a windows forms on Win7 (with the bug fix corrected) and all works except that the menus and toolbar don't works.
Some one could help me ???
Thanks in advance
Stefano
|
|
|
|
|
|

|
I know this is an old article, but I was wondering if/how you could implement something like this but reversed. That is run an application inside a web page instead of a browser inside of an application.
Thanks
|
|
|
|

|
Instead of using System.Threading.Thread.Sleep(1000), I fixed the error by following code:
while( p.MainWindowHandle == IntPtr.Zero || !IsWindowVisible(p.MainWindowHandle))
{
System.Threading.Thread.Sleep(10);
p.Refresh();
}
p.WaitForInputIdle();
You have to declare the IsWindowVisible within the same class:
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool IsWindowVisible(IntPtr hWnd);
Hope the above help.
|
|
|
|

|
I am working with VC# 2008. Powerpoint viewer application does not seem to work with this.
Furthermore, I tried retrieving the parent handle after SetParent using GetParent.
The parent handle is different from this.Handle.
Does this mean that it parent control functions have been disabled on the exe or am I misiing something ?
Abi
|
|
|
|

|
I finnaly run the application. just commented //PostMessage(appWin, WM_CLOSE, 0, 0); and // SetWindowLong(appWin, GWL_STYLE, WS_VISIBLE); in appcontrol.
Now I have other problem, I cannot start the application then a form is already opened. so if i put all working code to Form_Load function it doesn't work. It works only in InitializeComponent() function.
what should i do ?
thnx
|
|
|
|

|
what should i fix if i recieve folowing error ? it happens when this string executing "this.Controls.Add(this.applicationControl1);"
PInvokeStackImbalance was detected
A call to PInvoke function 'AppControl!AppControl.ApplicationControl::SetWindowLong' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.
|
|
|
|

|
With the following "bug fix" your code works perfectly, Jay!
"Bug fix" to solve problem that the external application is opened in a new window instead of being hosted/integrated in Form1:
http://www.codeproject.com/Messages/3169714/Re-Vista-incompatibility.aspx
Furthermore you can set the property "Enabled" of applicationControl1 (included in Form1) to False to dissallow any interaction with the hosted application - that's exactly what I wanted.
Thank you so much
|
|
|
|

|
Hello,
Can some please help me with this code?
The explorer dosen't open if the application,
What i'm doing wrong???
|
|
|
|

|
Hi,
Good Shot....nice article.....
But running the Code, for my self I found it;s launching the custom control and IE .. separately
I tried to run the code and as a result .. running WindowsApplication1 application ..it is not launching the IE inside the user control..
But what is happing is the UI form having nothing launching first .. then the IE is launching separately outside the user control...not inside the control.
Have anyone noticed that.. But as per my understanding the IE shud launch inside the form as it is a Custom control.
Jay, can you please help me why it is happing like this ..Do I need to do something else.
I tried with VS 2005 and VS 2008 and release and debug mode of dlls...getting the same results.
Actually treating the example as a sample, I want to create one user control which would launch the Adobe Photoshop.
modified on Thursday, May 28, 2009 1:11 PM
|
|
|
|

|
Hi.. Thanks for creating this user control.. Im just wondering how do i set the autoscroll property for this control?
After ive created the control, im setting the autoscroll property to true but when i tried launching it, it does not autoscroll:
e.g.
AppControl.ApplicationControl newApp = new AppControl.ApplicationControl();
newApp.AutoScroll = true;
does anyone know how to add autoscroll to this user control?
|
|
|
|

|
Hi I'm attempting to write my own version of carPC software using other peoples compiled .exe files.
Your project is great for making a tabbed notepad editor and other apps the like.
Do you know of any way to add winamp and make it work properly inside your control when i tried it it adds the "controls" part but the play list is completely separate as is the Eq.
Thanks in advance
-noka03
|
|
|
|

|
The code to get the main handle ( appWin = p.MainWindowHandle; ) sometimes returns 0. That means the code (p.WaitForInputIdle(); ) doesn’t work well. In this case, the EXE application is a separate window, not hosted by the control. Any suggestion for this?
|
|
|
|

|
This is sweet! Thanks for sharing it.
Here is one question I have:
I'm using this to open Textpad.exe on a panel (actually multiple instances of Textpad on separate panels -- one instance per panel) and everything works great (opening files, saving files, etc.) except in the case where I make changes to a file and don't save the changes before closing the form. Normally, Textpad asks the user if they want to save the changes if changes have been made. When running it through the C# app, the save changes message pops up and quickly disappears, and then it crashes ("SEND ERROR REPORT TO MICROSOFT" or "DON'T SEND") when I close the form. Everything closes just fine if there are no changes to save. Does anyone know what I can do to let the user answer the save changes question before the form actually closes?
|
|
|
|

|
I've used this sample to create a Windows Home Server Add-In that hosts another exe file. Works fint except for one thing. The application in questions apparently uses a timer to refresh it's content. When running standalone there is no problem, but when running inside a WinForm using the code from this article the applications "flickers" once a second. I assume this is some kind of refresh thread/timer doing something.
Is there any double buffering or other technique I can use that might help?
|
|
|
|

|
Could the control be rewritten so that it doesnt try to run the process from within the Designer and only during runtime?
|
|
|
|

|
you mentiond it is possible to communicate to a method in the application hosted within control. any insight into that, can you shed?
|
|
|
|

|
Hi!
You know it's like you read my mind, Excellent control, Excellent Article, Just When I needed it!
Thanks!
MrWolfy
|
|
|
|

|
hey Im new to VS C# and tried loading the demo into VS C# Express 2008 but it doen't run?
|
|
|
|

|
This is exactly what I was looking for.
Is there a way to keep the app in "exename" from starting in design mode? Not a problem, per se, but I only want to start the app at runtime.
Will this work in Vista?
Thanks for your great component. It has made my app much easier to use!
John Byrne
|
|
|
|

|
Does not work on Vista. The application is opened in a separate window. Otherwise, cool article
|
|
|
|

|
I use this applicacion to host an exe (like notepad) in a form called 'form1'.
My problem is that, when I call “form1.hide ();" or "form1.visible=false" , the .exe process contained in this form is destroyed. Method "handledestroyed" for this process is automatically called. However, I dont want to kill it. Only hide.
So, how can I hide the form maintaining the process associated with it?
Regards
putzol
|
|
|
|

|
This is really cool, thanks so much for posting this.
Andres Becerra
|
|
|
|

|
I've applied this to a figure window in matlab but it appears the the background does not get erased after resize or overlap of another window.
Any ideas?
Greg
|
|
|
|

|
A call to PInvoke function 'AppControl!AppControl.ApplicationControl::SetWindowLong' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.
How does this get a fix?
Steve
|
|
|
|

|
1.can't start programe that have login window.
2.How sart a progame with command line.
Thanks,
Tsewang
caixrz
|
|
|
|

|
Can I get the code for AppControl dll
|
|
|
|

|
Hi, thank you for this example. I have tried to lunch it with visual cSgarp, but he doesn't work. He return me an error at this line:
this.Controls.Add(this.applicationControl1);
Can you help me?
I have also tried to insert your code in my application, but he return me n error at this code:
SetWindowLong(appWin, GWL_STYLE, WS_VISIBLE);
thank you
|
|
|
|

|
Here's the "translation" of the file "AppControl.cs" in VB.Net : '********************************************************************** Imports System Imports System.Collections imports System.ComponentModel imports System.Diagnostics imports System.Drawing imports System.Data imports System.Windows.Forms imports System.Runtime.InteropServices Public Class AppControl Inherits System.Windows.Forms.Panel Private Shadows created As Boolean = False Private appWin As IntPtr Private sExeName As String = "" Public Property ExeName() As String Get Return sExeName End Get Set(ByVal value As String) sExeName = value End Set End Property #Region "External Definition + Constants" <DllImport("user32.dll", EntryPoint:="GetWindowThreadProcessId", SetLastError:=True, CharSet:=CharSet.Unicode, ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> Private Shared Function GetWindowThreadProcessId(ByVal hWnd As Long, ByVal lpdwProcessId As Long) As Long End Function <DllImport("user32.dll", SetLastError:=True)> Private Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr End Function <DllImport("user32.dll", SetLastError:=True)> Private Shared Function SetParent(ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Long End Function <DllImport("user32.dll", EntryPoint:="GetWindowLongA", SetLastError:=True)> Private Shared Function GetWindowLong(ByVal hwnd As IntPtr, ByVal nIndex As Integer) As Long End Function <DllImport("user32.dll", EntryPoint:="SetWindowLongA", SetLastError:=True)> Private Shared Function SetWindowLong(ByVal hwnd As IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As IntPtr) As IntPtr End Function <DllImport("user32.dll", SetLastError:=True)> Private Shared Function SetWindowPos(ByVal hwnd As IntPtr, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long End Function <DllImport("user32.dll", SetLastError:=True)> Private Shared Function 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 End Function <DllImport("user32.dll", EntryPoint:="PostMessageA", SetLastError:=True)> Private Shared Function PostMessage(ByVal hwnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer End Function Private Const SWP_NOOWNERZORDER As Integer = 512 Private Const SWP_NOREDRAW As Integer = 8 Private Const SWP_NOZORDER As Integer = 4 Private Const SWP_SHOWWINDOW As Integer = 64 Private Const WS_EX_MDICHILD As Integer = 64 Private Const SWP_FRAMECHANGED As Integer = 32 Private Const SWP_NOACTIVATE As Integer = 16 Private Const SWP_ASYNCWINDOWPOS As Integer = 16384 Private Const SWP_NOMOVE As Integer = 2 Private Const SWP_NOSIZE As Integer = 1 Private Const GWL_STYLE As Integer = (-16) Private Const WS_VISIBLE As Integer = 268435456 Private Const WM_CLOSE As Integer = 16 Private Const WS_CHILD As Integer = 1073741824 #End Region #Region "Overrides functions" Protected Overrides Sub OnSizeChanged(ByVal e As EventArgs) Me.Invalidate() MyBase.OnSizeChanged(e) End Sub Protected Overrides Sub OnVisibleChanged(ByVal e As EventArgs) ''// If control needs to be initialized/created If (created = False) Then ''// Mark that control is created created = True '// Initialize handle value to invalid appWin = IntPtr.Zero '// Start the remote application Dim p As Process Try '// Start the process p = System.Diagnostics.Process.Start(Me.ExeName) '// Wait for process to be created and enter idle condition p.WaitForInputIdle() '// Get the main handle appWin = p.MainWindowHandle Catch ex As Exception MessageBox.Show(Me, ex.Message, "Error") End Try '// Put it into this form SetParent(appWin, Me.Handle) '// Remove border and whatnot SetWindowLong(appWin, GWL_STYLE, WS_VISIBLE) '// Move the window to overlay it on this window MoveWindow(appWin, 0, 0, Me.Width, Me.Height, True) End If MyBase.OnVisibleChanged(e) End Sub Protected Overrides Sub OnHandleDestroyed(ByVal e As EventArgs) '// Stop the application If (appWin <> IntPtr.Zero) Then '// Post a close message PostMessage(appWin, WM_CLOSE, 0, 0) '// Delay for it to get the message System.Threading.Thread.Sleep(1000) '// Clear internal handle appWin = IntPtr.Zero End If MyBase.OnHandleDestroyed(e) End Sub Protected Overrides Sub OnResize(ByVal e As EventArgs) If (Me.appWin <> IntPtr.Zero) Then MoveWindow(appWin, 0, 0, Me.Width, Me.Height, True) End If MyBase.OnResize(e) End Sub #End Region End Class '********************************************************************** Hope that can be help somebody
|
|
|
|

|
i have now a form with multiple tabs
on each tab is a iexplore.
now my problem: how can i retrieve the current folder of each single iexplore instance ?
cause as soon as i host them , they do not update their maintitle property.
thanx
jj
|
|
|
|

|
iexplore was started but not placed in the panel
p.mainwindowhandle did not work due to:
process performance counter disabled
do you have any ideas ?
i'm running xp sp2
thanks
jan
|
|
|
|

|
This control fits the bill for a project I'm working on.
I've got it working fine for VC++ built apps, but I can't get any VB6 apps to play inside the control space. The VB6 exe gets kicked off, but is floating outside of the WinForm holding the AppControl. The control communicates with my VB6 window, (minimizing & shutdown work fine), but the resizing does not.
Has anyone had any luck using it for VB6 built apps or thoughts on what the problem might be?
Thanks in advance!
.. john ...
|
|
|
|

|
Does anybody knows how to implement the same in Visual C++?
|
|
|
|

|
me trying to embed console application,
but unable to remove the border and the caption bar,
is there any idea on this?
or is it possible to set embed application as MDi Child form?
thnx a lot
|
|
|
|

|
I am trying to embed an exe into my app, I tried the appcontrol, the iexplore worked fine, but the exe I need embed always run in a seperated window, I traced the code and found the MainWdinowHandler is 0, I think that could explain it. but why it is 0, how could I embed it in my app?
Thanks!
|
|
|
|

|
Thanks, its a nice control. It worked for me.
One thing, to get rid of the initial flashing of the external application may be:
1)Executing the external application using ShellExecute with last property as SW_HIDE
2)host grabs the external application
3)Calling ShowWindow with SW_SHOW parameter
|
|
|
|

|
Hi,
I could'n have the demo running properly.... it opens the extern application but outside de AppControl and a few seconds later it raises a message box saying "Couldn't get process information from remote machine".
I will test it under XP, I currently using Windows 2003 Server...
Thanks... this is a very good idea!!
Matías
|
|
|
|

|
Looks good... I have tried the same with following apps.
Notepad (notepad starts somewhere and then comes to winform.)
Excel (some exceptions while closing form)
Word (works good)
DevEnv( Failed to load VS.NET inside the form...VS.NET runs seperately)
Sreejumon
www.sreesharp.com
|
|
|
|

|
When I add Excel to this Control some error report by excel . May be you can help us !
thanks all;P
|
|
|
|

|
That's pretty neat, good work
This space for rent!
|
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
|
A custom control to launch and embed an EXE into a WinForm based application.
| Type | Article |
| Licence | |
| First Posted | 21 Dec 2004 |
| Views | 191,730 |
| Bookmarked | 121 times |
|
|