사용자가 하드 드라이브에서 Office 문서를 열면 exe (winform 응용 프로그램)를 열어야합니다. 모달 창을 사용하여 문서에 대한 세부 정보를 캡처합니다.하드 드라이브에서 Office 문서를 여는 동안 모달로 exe (Windows 응용 프로그램) 열기
나는 Office 문서 파일이 열려 있는지 여부를 모니터링하기 위해 클라이언트 컴퓨터에서 실행되는 콘솔 앱을 개발했습니다. 당신은 내가 예상대로 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 자동화를 사용하여 창을 다시 사용할 수 없도록 설정할 수도 있습니다. 귀하의 앱을 모달로 만듭니다. 다시 활성화하는 것을 잊지 마십시오. –