7

在执行我的程序时,我想隐藏/最小化 Microsoft 语音识别应用程序:

替代文字 http://img143.imageshack.us/img143/9380/minimize.png

最后我想使用 c# 显示/最大化!

这个过程不是由我启动的,所以我无法控制进程 startInfo。

我尝试使用 user32.dll 方法,例如:

  1. 展示窗口
  2. 动画窗口
  3. 动画窗口
  4. 设置前景窗口
  5. 设置窗口位置

对于所有这些,我都有同样的问题。

我可以隐藏窗口(尽管我必须使用 SW_HIDE 选项调用其中一种方法两次),但是当我使用 SW_SHOW 标志调用该方法时,它根本不显示..

隐藏进程后如何最大化/显示?

提前致谢!

下面是一些代码,现在实现为使用 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);

注意:SAPI API 是否有一个命令来最小化这个最小化和最大化这个窗口?

4

3 回答 3

2

正如 Tomas 所说,您应该尝试使用 SW_HIDE 和 SW_SHOW 消息。

您可以通过知道语音识别 winwow 名称然后使用以下内容来做到这一点:

HWND hc = FindWindow("processname","Windowtitle"); 
ShowWindow(hc,SW_HIDE);
于 2010-06-14T16:15:28.643 回答
1

整个 SetForegroundWindow/ShowWindow 函数集只有在星星对齐时才起作用!:) 通常是以正确的顺序调用函数的问题。抱歉不能具体帮助,但这可能会提供一些想法

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

于 2010-06-13T12:23:33.577 回答
1

如果您向其发送消息,进程是否仍在运行SW_HIDE?该应用程序当然没有使用标准的 GUI 样式,因此它可能会通过关闭自身来对消息做出反应。

如果是这种情况,您可以尝试其他技巧,例如将窗口移动到某个不可见的位置(例如-1000、-1000),使用SetWindowPlacement您已经导入的方法也应该可以。

于 2010-06-13T12:43:38.560 回答