2010-06-13 16 views
6

Durante la ejecución de mi programa, yo quiero ocultar/minimizar la aplicación de reconocimiento de voz de Microsoft:¿Cómo ocultar/mostrar un proceso usando C#?

alt text http://img143.imageshack.us/img143/9380/minimize.png

y al final quiero mostrar/maximizar el uso de C#!

Este proceso no lo he iniciado, así que no puedo dar el control del proceso startInfo.

He tratado de utilizar métodos user32.dll como:

  1. ShowWindow
  2. AnimatedWindows
  3. AnimatedWindows
  4. SetForegroundWindow
  5. SetWindowPos

Con todos ellos Tengo el mismo problema.

puedo ocultar las ventanas (aunque tengo que llamar a uno de los métodos dos veces con opción SW_HIDE), pero cuando llamo el método con una bandera SW_SHOW, simplemente no se muestra ..

Cómo ¿Puedo maximizar/mostrar después de ocultar el proceso?

¡Gracias de antemano!

Aquí es algunas piezas del código, ahora se implementa a utilizar SetWindowPlacement:

{ 
    [DllImport("user32.dll")] 
    [return: MarshalAs(UnmanagedType.Bool)] 
    public static extern bool GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl); 
    [DllImport("user32.dll", SetLastError = true)] 
    [return: MarshalAs(UnmanagedType.Bool)] 
    static extern bool SetWindowPlacement(IntPtr hWnd, 
     [In] ref WINDOWPLACEMENT lpwndpl); 
    [DllImport("user32.dll")] 
    public static extern Boolean ShowWindowAsync(IntPtr hWnd, Int32 nCmdShow); 
    [DllImport("user32.dll")] 
    public static extern Boolean SetForegroundWindow(IntPtr hWnd);   
    [DllImport("user32.dll")] 
    public static extern Boolean ShowWindow(IntPtr hWnd, Int32 nCmdShow); 
    [DllImport("user32.dll")] 
    public static extern Boolean AnimateWindow(IntPtr hWnd, uint dwTime, uint dwFlags); 
    [DllImport("dwmapi.dll")] 
    public static extern int DwmSetWindowAttribute(IntPtr hwnd, uint dwAttribute, IntPtr pvAttribute, IntPtr lol); 
//Definitions For Different Window Placement Constants 
const UInt32 SW_HIDE = 0; 
const UInt32 SW_SHOWNORMAL = 1; 
const UInt32 SW_NORMAL = 1; 
const UInt32 SW_SHOWMINIMIZED = 2; 
const UInt32 SW_SHOWMAXIMIZED = 3; 
const UInt32 SW_MAXIMIZE = 3; 
const UInt32 SW_SHOWNOACTIVATE = 4; 
const UInt32 SW_SHOW = 5; 
const UInt32 SW_MINIMIZE = 6; 
const UInt32 SW_SHOWMINNOACTIVE = 7; 
const UInt32 SW_SHOWNA = 8; 
const UInt32 SW_RESTORE = 9; 

public sealed class AnimateWindowFlags 
{ 
    public const int AW_HOR_POSITIVE = 0x00000001; 
    public const int AW_HOR_NEGATIVE = 0x00000002; 
    public const int AW_VER_POSITIVE = 0x00000004; 
    public const int AW_VER_NEGATIVE = 0x00000008; 
    public const int AW_CENTER = 0x00000010; 
    public const int AW_HIDE = 0x00010000; 
    public const int AW_ACTIVATE = 0x00020000; 
    public const int AW_SLIDE = 0x00040000; 
    public const int AW_BLEND = 0x00080000; 
} 

public struct WINDOWPLACEMENT 
{ 
    public int length; 
    public int flags; 
    public int showCmd; 
    public System.Drawing.Point ptMinPosition; 
    public System.Drawing.Point ptMaxPosition; 
    public System.Drawing.Rectangle rcNormalPosition; 
} 


      //this works 

      param = new WINDOWPLACEMENT(); 
      param.length = Marshal.SizeOf(typeof(WINDOWPLACEMENT)); 
      param.showCmd = (int)SW_HIDE; 
      lol = SetWindowPlacement(theprocess.MainWindowHandle, ref param); 


      // this doesn't work 

      WINDOWPLACEMENT param = new WINDOWPLACEMENT(); 
      param.length = Marshal.SizeOf(typeof(WINDOWPLACEMENT)); 
      param.showCmd = SW_SHOW; 
      lol = GetWindowPlacement(theprocess.MainWindowHandle, ref param); 

NOTA: ¿El API SAPI tiene un comando para minimizar este minimizar y maximizar esta ventana?

Respuesta

1

¡Toda la serie de funciones SetForegroundWindow/ShowWindow solo funciona cuando las estrellas se alinean! :) Por lo general, se trata de llamar a las funciones en el orden correcto. Lo sentimos, no pueden ayudar específicamente pero esto podría proporcionar algunas ideas

http://markribau.org/blog/2005/12/29/why-dont-focus-and-setforegroundwindow-work/

+0

que se olvidó de mension que uno. ¡Yo también usé eso! –

+0

actualizado para ser. – hawk

1

es la procoess todavía runing si lo envía el mensaje SW_HIDE? La aplicación ciertamente no está usando el estilo estándar de GUI, por lo que puede reaccionar al mensaje cerrándose.

Si ese es el caso, puede probar otros trucos, como mover la ventana a alguna ubicación invisible (por ejemplo, -1000, -1000), que también debería ser posible utilizando el método SetWindowPlacement que ya importó.

+0

Sí, todavía está en ejecución. –

2

Como dijo Tomas, debería intentar usar los mensajes SW_HIDE y SW_SHOW.

a hacer eso si se conoce el reconocimiento de voz winwow nombre y luego usar algo como esto:

HWND hc = FindWindow("processname","Windowtitle"); 
ShowWindow(hc,SW_HIDE); 
+0

¿cómo puedo descubrir el título de la ventana? –

+0

La manera simple es cargar Windows 'TaskMonitor y verlo allí. Eche un vistazo a esto dos: http://msdn.microsoft.com/en-us/library/ms633499%28VS.85%29.aspx http://www.recursosvisualbasic.com.ar/htm /listado-api/88-hwnd-class-name-parent.htm –

Cuestiones relacionadas