【问题标题】:FindWindow return 0 in Windows 7FindWindow 在 Windows 7 中返回 0
【发布时间】:2014-01-08 02:00:57
【问题描述】:

我有一个 C# 程序。该程序创建一个 Adob​​e Reader 进程并打印一个PDF 文档。它在 Windows XP 中运行良好,但在 Windows 7 中无法运行。我检查了 AcroRd32.exe 路径在 Windows 7 中是否正确。FindWindow 方法在 Windows 7 中始终返回 0。

    [DllImport("user32.dll")]
    public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

    [DllImport("User32.dll")]
    public static extern IntPtr FindWindow(string ClassN, string WindN);

    [DllImport("user32.dll", EntryPoint = "SendMessageA")]
    private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);

    [DllImport("user32.dll", SetLastError = true)]
    static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

    [DllImport("shell32.dll ")]
    public static extern int ShellExecute(IntPtr hwnd, string lpszOp, string lpszFile, string lpszParams, string lpszDir, int FsShowCmd);

    [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
    public static extern uint WinExec(string lpCmdLine, uint uCmdShow);

    public bool isAcrobatExsists(string acrobatLoc)
    {
        IntPtr currentHandle = getWindowHandlerByClass("AcrobatSDIWindow");
        if (currentHandle != IntPtr.Zero)
        {
            return true;
        }
        return false;
    }

    private static IntPtr getWindowHandlerByClass(string className)
    {
        IntPtr currentHandle = FindWindow(className, null);
        return currentHandle;
    }

    private static IntPtr getWindowHandlerByName(string appName)
    {
        IntPtr currentHandle = FindWindow(null, appName);
        return currentHandle;
    }

【问题讨论】:

  • 我试过了。它仍然返回 0。

标签: c# pdf printing windows-7 findwindow


【解决方案1】:

Findwindow 很大程度上取决于您运行应用程序的方式。听起来您可能将其作为计划任务或 Windows 服务运行。它们在与用户桌面窗口所在的会话不同的会话中运行,因此它不会看到或无法与它们交互。

他们在 Windows Vista 中引入了此更改,因此执行此操作的应用程序在 XP 中可以正常工作,但在 Windows Vista 或更高版本中失败。

这里有一个来自 msdn 的链接:Application Compatibility: Session 0 isolation

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-14
    • 2013-06-25
    • 1970-01-01
    • 1970-01-01
    • 2014-04-14
    • 1970-01-01
    • 2012-01-31
    相关资源
    最近更新 更多