Note that there are some explanatory texts on larger screens.

plurals
  1. POGet focus on third party application and return
    text
    copied!<p>I'm writing in C#.</p> <p>I have a process that lunches a third party application embedded within my program. I also have a RichTextBox in which I write text and then it shown in the embedded application real time. Everything works but I need to move the mouse, for the application will get focus and then refresh and show me the changes.</p> <p>This is the process: </p> <pre><code>private void button2_Click(object sender, EventArgs e) { System.IO.File.WriteAllText(@"ForParsing.txt", textBox1.Text); pdf.StartInfo.FileName = @"yap.exe"; pdf.StartInfo.Arguments = "ForParsing.dvi"; pdf.Start(); pdf.WaitForInputIdle(-1); SetParent(pdf.MainWindowHandle, this.splitContainer2.Panel1.Handle); SetWindowPos(pdf.MainWindowHandle, HWND_TOP, this.splitContainer2.Panel1.ClientRectangle.Left, this.splitContainer2.Panel1.ClientRectangle.Top, this.splitContainer2.Panel1.ClientRectangle.Width, this.splitContainer2.Panel1.ClientRectangle.Height, SWP_NOACTIVATE | SWP_SHOWWINDOW); } </code></pre> <p>I have a key press handler below for the TextBox. When key is pressed, I Focus on a third party application that is embedded in my program.</p> <pre><code>private void richTextBox1_TextChanged(object sender, EventArgs e) { System.IO.File.WriteAllText(@"ForParsing.txt", textBox1.Text); //Focus on third party application SetForegroundWindow(pdf.MainWindowHandle); } </code></pre> <p>So far so good. Now the problem: I want the focus instantly returned to the same place the courser was in the TextBox. I want to be able to keep on writing in the TextBox like nothing happened except the real time refreshing of the embedded application.</p> <p>In simple words, I need the third party application to refresh (gain focus) instantly and me be able to type without interference, at the current position I stopped, in the TextBox. </p> <p>Is it possible to so? Is there a better, more simple solution for this? would happily listen to any advice. </p> <p>As I'm not allowed to answer my own questions, I will write it here:</p> <p>I've found a solution tinkering with people's problems</p> <p>Here is what I've done:</p> <p>private void richTextBox1_TextChanged(object sender, EventArgs e) { System.IO.File.WriteAllText(@"ForParsing.txt", textBox1.Text);</p> <pre><code> //Focus on third party application SetForegroundWindow(pdf.MainWindowHandle); //Restore focus pdf.WaitForInputIdle(); SetForegroundWindow(this.Handle); this.Focus(); </code></pre> <p>}</p> <p>Thanks for the help everyone</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload