code_junkie

User32's ShowWindow doesn't act as expected

Nov 13th, 2011
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. [DllImport("User32")]
  2. private static extern int ShowWindow(int hwnd, int nCmdShow); //this will allow me to hide a window
  3.  
  4. public ConsoleForm(Process p) {
  5. this.p = p;
  6. p.Start();
  7. ShowWindow((int)p.MainWindowHandle, 0); //0 means to hide the window. See User32.ShowWindow documentation SW_HIDE
  8.  
  9. this.inStream = p.StandardInput;
  10. this.outStream = p.StandardOutput;
  11. this.errorStream = p.StandardError;
  12.  
  13. InitializeComponent();
  14.  
  15. wr = new watcherReader(watchProc);
  16. wr.BeginInvoke(this.outStream, this.txtOut, null, null);
  17. wr.BeginInvoke(this.errorStream, this.txtOut2, null, null);
  18. }
  19.  
  20. private delegate void watcherReader(StreamReader sr, RichTextBox rtb);
  21. private void watchProc(StreamReader sr, RichTextBox rtb) {
  22. string line = sr.ReadLine();
  23. while (line != null && !stop && !p.WaitForExit(0)) {
  24. //Console.WriteLine(line);
  25. line = stripColors(line);
  26. rtb.Text += line + "n";
  27.  
  28. line = sr.ReadLine();
  29. }
  30. }
  31.  
  32. public void start(string[] folders, string serverPath) {
  33.  
  34. this.inStream.WriteLine("chdir C:\cygwin\bin");
  35. //this.inStream.WriteLine("bash --login -i");
  36. this.inStream.WriteLine("");
  37. }
  38.  
  39. private void ConsoleForm_FormClosed(object sender, FormClosedEventArgs e) {
  40. this.stop = true;
  41. try {
  42. this.p.Kill();
  43. this.p.CloseMainWindow();
  44. } catch (InvalidOperationException) {
  45. return;
  46. }
  47. }
  48.  
  49. public ConsoleForm(Process p) {
  50. this.p = p;
  51. p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
  52. p.StartInfo.CreateNoWindow = true;
  53. p.Start();
  54.  
  55. this.inStream = p.StandardInput;
  56. this.outStream = p.StandardOutput;
  57. this.errorStream = p.StandardError;
  58.  
  59. InitializeComponent();
  60.  
  61. wr = new watcherReader(watchProc);
  62. wr.BeginInvoke(this.outStream, this.txtOut, null, null);
  63. wr.BeginInvoke(this.errorStream, this.txtOut2, null, null);
  64. }
Add Comment
Please, Sign In to add comment