ユーザがハードドライブからオフィス文書を開くと、exe(winフォームアプリケーション)を開く必要があります。モーダルウィンドウを使用してドキュメントの詳細をキャプチャします。ハードドライブからオフィス文書を開くときにモーダルとしてexe(Windowsアプリ)を開く
私は、オフィス文書ファイルが開いているかどうかを監視するために、クライアントマシンで実行されるコンソールアプリケーションを開発しました。あなたは、私が予想通りexe.Itの作業を開くためにProcess.Start
を使用していますOnUIAEvent
イベントハンドラで見た場合、以下のコード
static void Main(string[] args)
{
var UIAEventHandler = new AutomationEventHandler(OnUIAEvent);
Automation.AddAutomationEventHandler(WindowPattern.WindowOpenedEvent,
AutomationElement.RootElement,
TreeScope.Children, UIAEventHandler);
Console.ReadLine();
Automation.RemoveAllEventHandlers();
}
public static void OnUIAEvent(object src, AutomationEventArgs args)
{
AutomationElement element;
try
{
element = src as AutomationElement;
}
catch
{
return;
}
string name = "";
if (element == null)
name = "null";
else
{
name = element.GetCurrentPropertyValue(
AutomationElement.NameProperty) as string;
}
if (name.Length == 0) name = "<NoName>";
string guid = Guid.NewGuid().ToString("N");
string str = string.Format("{0} : {1}", name, args.EventId.Id);
if ((element.Current.ClassName.Equals("XLMAIN", StringComparison.InvariantCultureIgnoreCase) == true && name.Contains(".xlsx")) || (element.Current.ClassName.Equals("OpusApp", StringComparison.InvariantCultureIgnoreCase) == true && name.Contains(".docx")))
{
Process.Start(@"E:\experiment\TestingWindowsService\UserInfomation\bin\Debug\UserInfomation.exe", element.Current.Name);
//Automation.AddAutomationEventHandler(
// WindowPattern.WindowClosedEvent,
// element, TreeScope.Element, (s, e) => UIAEventHandler1(s, e, guid, name));
Console.WriteLine(guid + " : " + name);
// Environment.Exit(1234);
}
}
を見つけてください。しかし、私は、EXEが開いているドキュメントのモーダルとして開く必要があります。以下のコードは、EXEのフォームロードです。
private void Form1_Load(object sender, EventArgs e)
{
this.TopMost = true;
this.CenterToScreen();
}
開いている文書に対してモーダルとして開くようにWindowsアプリケーションを開くことはできますか?
UIオートメーションを使用すると、ウィンドウを無効にすることもできます。ユーザーがウィンドウを再び有効にすることはできません。あなたのアプリをモーダルにします。それを再度有効にすることを忘れないでください。 –