Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Hijacking another application window

Hijacking another application window

Scheduled Pinned Locked Moved .NET (Core and Framework)
graphicshelp
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TheIdleProgrammer
    wrote on last edited by
    #1

    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.

    A 2 Replies Last reply
    0
    • T TheIdleProgrammer

      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.

      A Offline
      A Offline
      AndrewVos
      wrote on last edited by
      #2

      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).


      www.wickedorange.com www.andrewvos.com

      T 1 Reply Last reply
      0
      • T TheIdleProgrammer

        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.

        A Offline
        A Offline
        AndrewVos
        wrote on last edited by
        #3

        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

        R 1 Reply Last reply
        0
        • A AndrewVos

          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).


          www.wickedorange.com www.andrewvos.com

          T Offline
          T Offline
          TheIdleProgrammer
          wrote on last edited by
          #4

          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.

          A 1 Reply Last reply
          0
          • T TheIdleProgrammer

            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.

            A Offline
            A Offline
            AndrewVos
            wrote on last edited by
            #5

            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.


            www.wickedorange.com www.andrewvos.com

            1 Reply Last reply
            0
            • A AndrewVos

              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

              R Offline
              R Offline
              Rajesh Anuhya
              wrote on last edited by
              #6

              hey 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 <--

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups