【发布时间】:2017-07-25 07:33:06
【问题描述】:
我有 winapi c# 将网页保存为 pdf。应用程序在网页上使用 control + P 并按 Enter。我的默认打印机是“nuance pdf”,我想将文件另存为 pdf。我的代码如下所示:
static class Program
{
[DllImport("user32.dll")]
public static extern int SetForegroundWindow(IntPtr hWnd);
[DllImport("User32.dll")]
public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, string lParam);
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[STAThread]
static void Main()
{
Boolean Check = true;
string text = "MyFileName";
while (Check)
{
Process[] processes = Process.GetProcessesByName("iexplore");
foreach (Process proc in processes)
{
SetForegroundWindow(proc.MainWindowHandle);
SendKeys.SendWait("^(p)");
SendKeys.SendWait("{ENTER}");
var handle = FindWindow(null, "Save As");
Console.WriteLine("handle {0}", handle);
//SendMessage(handle, 0x000C, IntPtr.Zero, text);
SendKeys.SendWait("{ENTER}");
}
Check = false;
}
}
}
此代码将文件名保存为“https___www.google.pdf”。我想更改文件名(突出显示)。
我该怎么做?任何指针? 感谢您的帮助。
【问题讨论】:
-
这听起来像是
System.Windows.Automation的工作。 -
谢谢雷蒙德。你有例子吗?
-
你不能只发送
Alt+n键到对话框选择文件名框然后发送新文件名吗? -
在这个站点上有很多使用自动化命名空间的例子。 Here's one 使用它来单击按钮。 Here's one 使用
ValuePattern更改编辑控件中的文本。 -
Stack Overflow 不能替代网络搜索和基础研究。当有人建议您使用 UI 自动化时,请先进行基础研究,然后再询问示例。一个称职的程序员的一个基本要求是勤奋和专注于进行此类研究。