C# 传话
我想要一个Word应用程序,请参见下面的代码:C# 传话,c#,ms-word,C#,Ms Word,我想要一个Word应用程序,请参见下面的代码: string caption = wordApp.Caption; IntPtr handler = FindWindow(null, caption); SetForegroundWindow(handler); wordApp.Visible = true; 我得到的错误是: Error CS0103: The name 'FindWindow' does not exist in the current context Error CS
string caption = wordApp.Caption;
IntPtr handler = FindWindow(null, caption);
SetForegroundWindow(handler);
wordApp.Visible = true;
我得到的错误是:
Error CS0103: The name 'FindWindow' does not exist in the current context
Error CS0103: The name 'SetForegroundWindow' does not exist in the current context
我想我错过了一个参考,即使编译器没有这么说。我说得对吗?这可能对解决您的问题有很大帮助:
包含它的库位于User32.lib下。这可能对您的问题有很大帮助:
包含它的库位于User32.lib下。在使用函数之前,您需要声明函数,我假设您要调用Windows API:FindWindow和setforegroundindow
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
static extern bool SetForegroundWindow(IntPtr hWnd);
您可以在MSDN文档中找到更多示例。您需要在使用函数之前声明它们,我假设您要调用Windows API:FindWindow和SetForeGroundWindow
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
static extern bool SetForegroundWindow(IntPtr hWnd);
您可以在MSDN文档中找到更多示例。因为您使用的是C#,所以请使用Process.getProcessByName(),类似以下内容:
Process[] processes = Process.GetProcessesByName("WINWORD");
SetForegroundWindow(processes[0].Handle);
要使用SetForegroundWindow(),必须具备以下条件:
[DllImport("user32.dll")]
static extern bool SetForegroundWindow(IntPtr hWnd);
因为您使用的是C#,所以请使用Process.getProcessByName(),类似于:
Process[] processes = Process.GetProcessesByName("WINWORD");
SetForegroundWindow(processes[0].Handle);
要使用SetForegroundWindow(),必须具备以下条件:
[DllImport("user32.dll")]
static extern bool SetForegroundWindow(IntPtr hWnd);
单词被激活了但没有被带到前面单词被激活了但没有被带到前面