Hijacking another application window
-
Hi Guys, I want to launch another application from my application, but I want to show it within my apps window. I appreciate it's very easy to launch the app, but I'm having difficulty finding a way to contain in within my app window. Has anybody got any ideas because I'm drawing a complete blank X|. I guess it may not be possible, but it's worth asking because it'd be the absolute Rolls Royce solution to my problem! Thanks, Chris Chambers.
-
Hi Guys, I want to launch another application from my application, but I want to show it within my apps window. I appreciate it's very easy to launch the app, but I'm having difficulty finding a way to contain in within my app window. Has anybody got any ideas because I'm drawing a complete blank X|. I guess it may not be possible, but it's worth asking because it'd be the absolute Rolls Royce solution to my problem! Thanks, Chris Chambers.
You're trying to hijack the command prompt right? I'm sure I saw this message somewhere else. Anyway, I'm thinking you would have to use some variation of SetParent (the windows api).
-
You're trying to hijack the command prompt right? I'm sure I saw this message somewhere else. Anyway, I'm thinking you would have to use some variation of SetParent (the windows api).
Hi Andrew, I'm not trying to get hold of the command prompt, but I guess the theory still applies. I'm working on an automotive diagnostic product, and I want run a separate technical data application from within a tab page in my application. Will SetParent() grab other application windows? I've never used it, so I'll investigate some more. Thanks for the heads up! Chris.
-
Hi Guys, I want to launch another application from my application, but I want to show it within my apps window. I appreciate it's very easy to launch the app, but I'm having difficulty finding a way to contain in within my app window. Has anybody got any ideas because I'm drawing a complete blank X|. I guess it may not be possible, but it's worth asking because it'd be the absolute Rolls Royce solution to my problem! Thanks, Chris Chambers.
Ok, I have created for you a horrible horrible hack... If you can make it elegant then it should work... Create a new project, and add a button to the form. Then add this code:
<DllImport("user32.dll", CharSet:=CharSet.Auto, ExactSpelling:=True)> Public Shared Function SetParent(ByVal hWnd As IntPtr, ByVal hWndParent As IntPtr) As IntPtr End Function Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Try System.Diagnostics.Process.Start("cmd") Dim process As Process = process.GetProcessesByName("cmd")(0) Do Until Not process.MainWindowHandle.Equals(IntPtr.Zero) process.Refresh() Loop Trace.WriteLine(process.MainWindowHandle) Me.SetParent(process.MainWindowHandle, Me.Handle) Catch ex As Exception Return End Try End Sub
www.wickedorange.com www.andrewvos.com -
Hi Andrew, I'm not trying to get hold of the command prompt, but I guess the theory still applies. I'm working on an automotive diagnostic product, and I want run a separate technical data application from within a tab page in my application. Will SetParent() grab other application windows? I've never used it, so I'll investigate some more. Thanks for the heads up! Chris.
You might want to do some checking to see if the window you parent is the right window too. Keep in mind you won't have much access to this window, unless you use apis.
-
Ok, I have created for you a horrible horrible hack... If you can make it elegant then it should work... Create a new project, and add a button to the form. Then add this code:
<DllImport("user32.dll", CharSet:=CharSet.Auto, ExactSpelling:=True)> Public Shared Function SetParent(ByVal hWnd As IntPtr, ByVal hWndParent As IntPtr) As IntPtr End Function Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Try System.Diagnostics.Process.Start("cmd") Dim process As Process = process.GetProcessesByName("cmd")(0) Do Until Not process.MainWindowHandle.Equals(IntPtr.Zero) process.Refresh() Loop Trace.WriteLine(process.MainWindowHandle) Me.SetParent(process.MainWindowHandle, Me.Handle) Catch ex As Exception Return End Try End Sub
www.wickedorange.com www.andrewvos.comhey I think this will help u..... Dim MyProcess As New System.Diagnostics.Process MyProcess.StartInfo.FileName = "edit" MyProcess.StartInfo.Arguments = "mytext.txt" MyProcess.StartInfo.UseShellExecute = False MyProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal 'Process.GetCurrentProcess() MyProcess.Start() MyProcess.WaitForExit() MyProcess.Close() thanks
Rajesh B --> A Poor Workman Blames His Tools <--