我想從我的應用程式中打開 MS Word 檔案。我使用 ShellExecute 函式來完成這項作業。它確實打開了我指定的 word 檔案,但它恢復了我之前打開并最小化的檔案,這不是我想要的。ShellExecute 也回傳 42 ,我不知道是什么意思。我是否錯誤地使用了 ShellExecute?
using System;
using System.Windows.Forms;
namespace Test_Doc
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
[System.Runtime.InteropServices.DllImport("Shell32.dll")]
public static extern int ShellExecute(IntPtr hwnd, string lpOperation, string lpFile, string lpParameters, string lpDirecotry, int nShowCmd);
private const int SW_HIDE = 0;
private const int SW_SHOWNORMAL = 1;
private const int SW_SHOWMINIMIZED = 2;
private const int SW_SHOWMAXIMIZED = 3;
private const int SW_SHOWNOACTIVATE = 4;
private const int SW_RESTORE = 9;
private const int SW_SHOWDEFAULT = 10;
private void button1_Click(object sender, EventArgs e)
{
string filePath = System.Reflection.Assembly.GetEntryAssembly().Location;
string fileName = System.IO.Path.Combine(filePath, "2.docx");
int i = ShellExecute(this.Handle, "Edit", fileName, null, null, SW_SHOWNORMAL);
MessageBox.Show(i.ToString());
}
}
}
uj5u.com熱心網友回復:
ShellExecute不允許您控制應用程式。但是,您可以從 C# 應用程式自動化 Word,之后您可以在其中管理應用程式。例如,有關詳細資訊,請參閱如何使用 Visual C# 自動化 Microsoft Word 以創建新檔案。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/517210.html
上一篇:.NET6TimeZoneInfo.TryConvertWindowsIdToIanaId()確實回傳false
