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. Windows Forms
  4. Needs to update WinForm (seperate process) to render newly created customized controls

Needs to update WinForm (seperate process) to render newly created customized controls

Scheduled Pinned Locked Moved Windows Forms
helpcsharpannouncement
6 Posts 5 Posters 1 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.
  • G Offline
    G Offline
    glitteringsound
    wrote on last edited by
    #1

    Hello, I am facing a strange problem, I have launched a seperate Win Form based process with the help of Process.Start from another process. That process just dispatched an object which actually contains .NET controls(e.g button,textbox,label,radio button etc) as information (control information I just collected from Injecting other running managed processes). After dispatching , I need to draw these controls on that process having WinForm as main window( as its form based process). BUT THESE CONTROLS ARE NOT RENDERING ON MAIN FORM WINDOW. Main problem is having with parent control information which is not correct to me. Take a look at Code =================== public partial class TestController: Form, IApplicationEventsSink { static bool m_ControllerLoadedFirstTime = true; ITestControl m_TakoControlHandler = null; public Controller() { if (m_ControllerLoadedFirstTime == true) { MessageBox.Show("TAKOController called first time"); InitializeComponent(); m_ControllerLoadedFirstTime = false; } else MessageBox.Show("TAKOController called second time"); } private void Form1_Load(object sender, EventArgs e) { MessageBox.Show("Form1_Load"); initEnvironment(); bool bSubscriptionCreated = createSubscription(); if (bSubscriptionCreated == false) throw new Exception(String.Format("Controller failed to create subscription with Simulator process!!")); } public ITestControl CreateControl(CustomControl a_CustomControl) { ITestControl TakoControlHandler = Factory.CreateControl(a_CustomControl); m_TakoControlHandler = TakoControlHandler; return TakoControlHandler; } private void SetProperties(CustomControl a_CustomControl) { m_TakoControlHandler.setPropeties(a_CustomControl); } public void OnProcess(CustomControl a_CustomControl) { MessageBox.Show("OnProcess"); ITestControl TakoHandler = CreateControl(a_CustomControl); if (TakoHandler != null) { SetProperties(a_CustomControl); m_TakoControlHandler.SetParentHandle(base.Handle); } base.Refresh(); base.

    P B L L 4 Replies Last reply
    0
    • G glitteringsound

      Hello, I am facing a strange problem, I have launched a seperate Win Form based process with the help of Process.Start from another process. That process just dispatched an object which actually contains .NET controls(e.g button,textbox,label,radio button etc) as information (control information I just collected from Injecting other running managed processes). After dispatching , I need to draw these controls on that process having WinForm as main window( as its form based process). BUT THESE CONTROLS ARE NOT RENDERING ON MAIN FORM WINDOW. Main problem is having with parent control information which is not correct to me. Take a look at Code =================== public partial class TestController: Form, IApplicationEventsSink { static bool m_ControllerLoadedFirstTime = true; ITestControl m_TakoControlHandler = null; public Controller() { if (m_ControllerLoadedFirstTime == true) { MessageBox.Show("TAKOController called first time"); InitializeComponent(); m_ControllerLoadedFirstTime = false; } else MessageBox.Show("TAKOController called second time"); } private void Form1_Load(object sender, EventArgs e) { MessageBox.Show("Form1_Load"); initEnvironment(); bool bSubscriptionCreated = createSubscription(); if (bSubscriptionCreated == false) throw new Exception(String.Format("Controller failed to create subscription with Simulator process!!")); } public ITestControl CreateControl(CustomControl a_CustomControl) { ITestControl TakoControlHandler = Factory.CreateControl(a_CustomControl); m_TakoControlHandler = TakoControlHandler; return TakoControlHandler; } private void SetProperties(CustomControl a_CustomControl) { m_TakoControlHandler.setPropeties(a_CustomControl); } public void OnProcess(CustomControl a_CustomControl) { MessageBox.Show("OnProcess"); ITestControl TakoHandler = CreateControl(a_CustomControl); if (TakoHandler != null) { SetProperties(a_CustomControl); m_TakoControlHandler.SetParentHandle(base.Handle); } base.Refresh(); base.

      P Offline
      P Offline
      Philippe Mori
      wrote on last edited by
      #2

      See [WinForms - How do I access/call methods in UI thread from a separate thread without passing a delegate?] Generally the simplest way to do multithreading in a WinForms application is to uses a BackgroundWorker to do the processing and uses the ReportProgress mechanism to send data to the UI. Alternatively, Invoke could also be used for inter-thread communication. The control itself should be on the same thread as the Form. Most other ways to do things need a deep understanding on how things works and some trials...

      Philippe Mori

      G 1 Reply Last reply
      0
      • P Philippe Mori

        See [WinForms - How do I access/call methods in UI thread from a separate thread without passing a delegate?] Generally the simplest way to do multithreading in a WinForms application is to uses a BackgroundWorker to do the processing and uses the ReportProgress mechanism to send data to the UI. Alternatively, Invoke could also be used for inter-thread communication. The control itself should be on the same thread as the Form. Most other ways to do things need a deep understanding on how things works and some trials...

        Philippe Mori

        G Offline
        G Offline
        glitteringsound
        wrote on last edited by
        #3

        Its inter-process communication. Thread which actually launches the WinForm process is in seperate process and runs independently the execution of WinForm process. But it just launches it and dispatches the custom object to it that's it. Now inside the WinForm process , when object dispatched to it, this cross process thread(the thread which just came from other process) actually tries to render the controls on its main Form( the Form which actually created by this process). Note : I think you are right, as the thread which actually renders the controls in other process , is the thread of another process, and I have to create seperate thread inside Form process and needs to take the data from incoming thread while making the incoming thread back to its own process immediately without doing any thing. Regards Usman

        1 Reply Last reply
        0
        • G glitteringsound

          Hello, I am facing a strange problem, I have launched a seperate Win Form based process with the help of Process.Start from another process. That process just dispatched an object which actually contains .NET controls(e.g button,textbox,label,radio button etc) as information (control information I just collected from Injecting other running managed processes). After dispatching , I need to draw these controls on that process having WinForm as main window( as its form based process). BUT THESE CONTROLS ARE NOT RENDERING ON MAIN FORM WINDOW. Main problem is having with parent control information which is not correct to me. Take a look at Code =================== public partial class TestController: Form, IApplicationEventsSink { static bool m_ControllerLoadedFirstTime = true; ITestControl m_TakoControlHandler = null; public Controller() { if (m_ControllerLoadedFirstTime == true) { MessageBox.Show("TAKOController called first time"); InitializeComponent(); m_ControllerLoadedFirstTime = false; } else MessageBox.Show("TAKOController called second time"); } private void Form1_Load(object sender, EventArgs e) { MessageBox.Show("Form1_Load"); initEnvironment(); bool bSubscriptionCreated = createSubscription(); if (bSubscriptionCreated == false) throw new Exception(String.Format("Controller failed to create subscription with Simulator process!!")); } public ITestControl CreateControl(CustomControl a_CustomControl) { ITestControl TakoControlHandler = Factory.CreateControl(a_CustomControl); m_TakoControlHandler = TakoControlHandler; return TakoControlHandler; } private void SetProperties(CustomControl a_CustomControl) { m_TakoControlHandler.setPropeties(a_CustomControl); } public void OnProcess(CustomControl a_CustomControl) { MessageBox.Show("OnProcess"); ITestControl TakoHandler = CreateControl(a_CustomControl); if (TakoHandler != null) { SetProperties(a_CustomControl); m_TakoControlHandler.SetParentHandle(base.Handle); } base.Refresh(); base.

          B Offline
          B Offline
          BobJanova
          wrote on last edited by
          #4

          Controls contain lots of low level native stuff (window handles, fonts, images etc) which are linked to their host process. I don't think you can 'rehome' them in this way. I know I couldn't find a way to make it work when I tried to host plugins for my lobby client within the main window, and that is just cross-AppDomain, not cross-process.

          1 Reply Last reply
          0
          • G glitteringsound

            Hello, I am facing a strange problem, I have launched a seperate Win Form based process with the help of Process.Start from another process. That process just dispatched an object which actually contains .NET controls(e.g button,textbox,label,radio button etc) as information (control information I just collected from Injecting other running managed processes). After dispatching , I need to draw these controls on that process having WinForm as main window( as its form based process). BUT THESE CONTROLS ARE NOT RENDERING ON MAIN FORM WINDOW. Main problem is having with parent control information which is not correct to me. Take a look at Code =================== public partial class TestController: Form, IApplicationEventsSink { static bool m_ControllerLoadedFirstTime = true; ITestControl m_TakoControlHandler = null; public Controller() { if (m_ControllerLoadedFirstTime == true) { MessageBox.Show("TAKOController called first time"); InitializeComponent(); m_ControllerLoadedFirstTime = false; } else MessageBox.Show("TAKOController called second time"); } private void Form1_Load(object sender, EventArgs e) { MessageBox.Show("Form1_Load"); initEnvironment(); bool bSubscriptionCreated = createSubscription(); if (bSubscriptionCreated == false) throw new Exception(String.Format("Controller failed to create subscription with Simulator process!!")); } public ITestControl CreateControl(CustomControl a_CustomControl) { ITestControl TakoControlHandler = Factory.CreateControl(a_CustomControl); m_TakoControlHandler = TakoControlHandler; return TakoControlHandler; } private void SetProperties(CustomControl a_CustomControl) { m_TakoControlHandler.setPropeties(a_CustomControl); } public void OnProcess(CustomControl a_CustomControl) { MessageBox.Show("OnProcess"); ITestControl TakoHandler = CreateControl(a_CustomControl); if (TakoHandler != null) { SetProperties(a_CustomControl); m_TakoControlHandler.SetParentHandle(base.Handle); } base.Refresh(); base.

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            I don't really understand what you are asking here. However, if it fits your needs, you can have one process host the main window of another process, by having the former call SetParent to the latter's main windows. That would take a bit of P/Invoke, passing the second process' Handle as a parameter. Warning: the result is mostly cosmetic, the second process would show up inside the confines of a first process' window, but they would otherwise remain two distinct and unrelated processes. :)

            Luc Pattyn [My Articles] Nil Volentibus Arduum

            The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
            Please use <PRE> tags for code snippets, they improve readability.
            CP Vanity has been updated to V2.3

            1 Reply Last reply
            0
            • G glitteringsound

              Hello, I am facing a strange problem, I have launched a seperate Win Form based process with the help of Process.Start from another process. That process just dispatched an object which actually contains .NET controls(e.g button,textbox,label,radio button etc) as information (control information I just collected from Injecting other running managed processes). After dispatching , I need to draw these controls on that process having WinForm as main window( as its form based process). BUT THESE CONTROLS ARE NOT RENDERING ON MAIN FORM WINDOW. Main problem is having with parent control information which is not correct to me. Take a look at Code =================== public partial class TestController: Form, IApplicationEventsSink { static bool m_ControllerLoadedFirstTime = true; ITestControl m_TakoControlHandler = null; public Controller() { if (m_ControllerLoadedFirstTime == true) { MessageBox.Show("TAKOController called first time"); InitializeComponent(); m_ControllerLoadedFirstTime = false; } else MessageBox.Show("TAKOController called second time"); } private void Form1_Load(object sender, EventArgs e) { MessageBox.Show("Form1_Load"); initEnvironment(); bool bSubscriptionCreated = createSubscription(); if (bSubscriptionCreated == false) throw new Exception(String.Format("Controller failed to create subscription with Simulator process!!")); } public ITestControl CreateControl(CustomControl a_CustomControl) { ITestControl TakoControlHandler = Factory.CreateControl(a_CustomControl); m_TakoControlHandler = TakoControlHandler; return TakoControlHandler; } private void SetProperties(CustomControl a_CustomControl) { m_TakoControlHandler.setPropeties(a_CustomControl); } public void OnProcess(CustomControl a_CustomControl) { MessageBox.Show("OnProcess"); ITestControl TakoHandler = CreateControl(a_CustomControl); if (TakoHandler != null) { SetProperties(a_CustomControl); m_TakoControlHandler.SetParentHandle(base.Handle); } base.Refresh(); base.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              As far as I know, UI elements are attached to the process they're created on and cannot be transferred 'on the fly' to a different process. The only exception is that you can use the SetParent Windows API to show a process's main window inside another process's window. I have achieved this with little success. I don't think you can use this technique with controls though.

              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