2012-12-07 2 views
2

Outlook 약속을 보내는 wpf 응용 프로그램을 만들고 있습니다. 이 응용 프로그램에서 약속의받는 사람을 선택하려면 Outlook 선택 이름 대화 상자를 열고 있습니다. 다음은 내 코드입니다 :wlookup 응용 프로그램과 Outlook에서 열 때 초점을 맞출 Outlook 선택 이름 대화 상자를 얻는 방법

Outlook.SelectNamesDialog selectNameDialog = 
      outlookApp.Session.GetSelectNamesDialog(); 
     selectNameDialog.SetDefaultDisplayMode(
      Outlook.OlDefaultSelectNamesDisplayMode.olDefaultMeeting); 

     foreach (var recipient in recipientsList) 
     { 
      if (string.IsNullOrEmpty(recipient)) 
       continue; 
      Outlook.Recipient confRoom = 
       selectNameDialog.Recipients.Add(recipient); 
      // Explicitly specify Recipient.Type. 
      confRoom.Type = (int)Outlook.OlMeetingRecipientType.olRequired; 
     } 

     selectNameDialog.Recipients.ResolveAll(); 

     selectNameDialog.Display(); 

내 문제는 내가 선택 이름 대화 상자를 열 때 Outlook이 실행되지 않는 경우 잘 작동한다는 것입니다. 그러나 Outlook이 실행 중이고 내 애플리케이션에서 클릭하여이 대화 상자를 열면 내 애플리케이션의 뒤쪽과 Outlook 창의 상단에 열립니다. Outlook이 실행중인 경우에도 내 응용 프로그램 위에 표시해야합니다. 이 대화 상자를 앞에두면 도움이 될 것입니다. 미리 감사드립니다.

답변

1

Outlook 프로세스를 가져 와서 창을 앞으로 가져올 수 있습니다. .NET 훅이 없기 때문에 네이티브 Win32 DLL을 사용해야합니다. 물론

[Flags()] 
    private enum SetWindowPosFlags : uint 
    { 
     SynchronousWindowPosition = 0x4000, 
     DeferErase = 0x2000, 
     DrawFrame = 0x0020, 
     FrameChanged = 0x0020, 
     HideWindow = 0x0080, 
     DoNotActivate = 0x0010, 
     DoNotCopyBits = 0x0100, 
     IgnoreMove = 0x0002, 
     DoNotChangeOwnerZOrder = 0x0200, 
     DoNotRedraw = 0x0008, 
     DoNotReposition = 0x0200, 
     DoNotSendChangingEvent = 0x0400, 
     IgnoreResize = 0x0001, 
     IgnoreZOrder = 0x0004, 
     ShowWindow = 0x0040, 
    } 

    [DllImport("user32.dll")] 
    [return: MarshalAs(UnmanagedType.Bool)] 
    static extern bool SetForegroundWindow(IntPtr hWnd); 

    [DllImport("user32.dll", SetLastError = true)] 
    static extern bool BringWindowToTop(IntPtr hWnd); 

    static readonly IntPtr HWND_TOP = new IntPtr(0); 
    static readonly IntPtr HWND_TOPMOST = new IntPtr(-1); 

    [DllImport("user32.dll")] 
    [return: MarshalAs(UnmanagedType.Bool)] 
    static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, SetWindowPosFlags uFlags); 

    [DllImport("user32.dll")] 
    static extern IntPtr SetFocus(IntPtr hWnd); 

    int bring_window_to_front_mode = 1; // Various option here, try them out 
    Boolean TopMost = false; 

     System.Diagnostics.Process[] prcs = System.Diagnostics.Process.GetProcessesByName("XBMCLauncher"); 
     foreach (var proc in prcs) 
     { 
      Log.LogLine("Main Window Handle {0}", p.MainWindowHandle.ToInt32()); 
      switch (bring_window_to_front_mode) 
      { 
       case 1: 
        if (TopMost) 
        { 
         Log.LogLine("SetWindowPos TopMost {0}", p.MainWindowHandle.ToInt32()); 
         SetWindowPos(p.MainWindowHandle, HWND_TOPMOST, 50, 50, 500, 500, SetWindowPosFlags.IgnoreMove | SetWindowPosFlags.IgnoreResize); 
        } 
        else 
        { 
         Log.LogLine("SetWindowPos {0}", p.MainWindowHandle.ToInt32()); 
         SetWindowPos(p.MainWindowHandle, HWND_TOP, 50, 50, 500, 500, SetWindowPosFlags.IgnoreMove | SetWindowPosFlags.IgnoreResize); 
        } 
        break; 
       case 2: 
        Log.LogLine("BringWindowToTop {0}", p.MainWindowHandle.ToInt32()); 
        BringWindowToTop(p.MainWindowHandle); 
        break; 
       case 3: 
        Log.LogLine("SetForegroundWindow {0}", p.MainWindowHandle.ToInt32()); 
        SetForegroundWindow(p.MainWindowHandle); 
        break; 
       case 4: 
        Log.LogLine("SetFocus {0}", p.MainWindowHandle.ToInt32()); 
        SetFocus(p.MainWindowHandle); 
        break; 
      } 
     } 

/캐치를 시도 ...

관련 문제