2012-10-02 2 views
0

가능한 중복 :
SendMessage to .NET Console application콘솔 (cmd.exe를)에의 WinForm 응용 프로그램에서 메시지 또는 명령을 보내기

가 나는 메시지 또는 명령을 보낼 수있는 방법에 대해 묻고 싶다 콘솔 Winform 응용 프로그램에서. winform의 콘솔 응용 프로그램 (cmd.exe) 인 내 코드 정보 나는 winform 한판 승부에서 cmd.exe를 넣을 수있다. 나는 메시지 나 콘솔 (cmd.exe)에 명령을 보낼 수 없었다.

내 코드를보고 나를

void PictureBox1Click(object sender, EventArgs e) 
{ 
    System.Diagnostics.ProcessStartInfo start = new 
    System.Diagnostics.ProcessStartInfo(); 
    System.Diagnostics.Process bob = new System.Diagnostics.Process(); 
    bob.StartInfo.UseShellExecute = true; 
    bob.StartInfo.Arguments += " /K TITLE CMD"; 
    bob.StartInfo.FileName = "cmd"; 
    bob.Start(); 
    this.timer1.Enabled = true; 
} 


private void button1_Click(object sender, EventArgs e) 
{ 
    System.Diagnostics.Process bob = new System.Diagnostics.Process(); 
    bob.StartInfo.UseShellExecute = true; 
    bob.StartInfo.Arguments += " /K TITLE Command Prompt"; 
    bob.StartInfo.FileName = "CMD"; 
    bob.StartInfo.CreateNoWindow = true; 
    bob.Start(); 
    this.timer1.Enabled = true; 
} 


private void BtnSend_Click(object sender, EventArgs e) 
{ 
    System.IntPtr hwnd ; 
    hwnd = Usr32.FindWin("ConsoleWindowClass", "cmd"); 
    if (hwnd != System.IntPtr.Zero) 
    { 
     IntPtr hwndChild = IntPtr.Zero; 
     hwndChild = Usr32.FindWindowEx((IntPtr)hwnd, new IntPtr(0), null, null); 
     if (hwndChild != IntPtr.Zero) 
     { 
      Usr32.SendMessage(hwndChild, 0x000C, 0, "Hello Everyone"); 

     } 
     else 
     { 
      MessageBox.Show("Cannot Get the Child Handle :(!"); 
     } 
    } 
    else 

     MessageBox.Show("Application is not running"); 
} 
+0

문제가있는 콘솔 응용 프로그램에 따라 사용할 수있는 "해결 방법"은 일반 표준 입력 스트림을 사용하여 사용자와 상호 작용할 수 있습니다. 자세한 내용은 [이 SO 스레드] (http://stackoverflow.com/q/11767654/21567)를 참조하십시오. –

답변

2

콘솔 응용 프로그램은 일반적으로는 적극적으로 일을 만들거나 수동으로 메시지를 펌핑하여 협력하지 않는 한 Windows 메시지를받을 수 없습니다 따라서 메시지 펌프를 가지고하지 않습니다 도와주세요. 이것은 소스를 소유하지 않는 한 옵션이 아닙니다.이 경우 소스는 아닙니다.

관련 문제