none
Returning focus to a Outlook .NET MailItem's WordEditor RRS feed

  • Question

  • Hello all,

    I am using a Custom Task Pane inside of an Inspector for a MailItem (compose/reply window) to display a form for the user to interact with before sending an e-mail.  One of the things they can do is click a button inside the pane to add some content to the e-mail body.  This all works fine, but once they click the button the focus is set inside the task pane, and I would like the focus to be set back to the MailItem's word editor (the body of the e-mail) where the text was just inserted so they can seamlessly resume typing without having to click their mouse back into it.  I have tried using the Inspector's .Activate() method, the WordEditor's .Activate() method, to no avail.  I'm sure there would be some hacky method using WinAPI's to force focus of the window, but does anyone know of a way to do this just using the object model?  If not, could someone point me in the right direction to how to do the hacky method?  The problem is there could potentially be many inspectors open (multiple compose/reply windows) and I would want to make sure it was focusing the correct instance of the Inspector.

    Thank you very much!

    Wednesday, May 1, 2013 5:54 PM

Answers

  • You can use the Win32 API's to do that, but the object models won't do it for you.
     
    Outlook Inspectors and Explorers can be cast to IOleWindow objects, then you can call IOleWindow.GetWindow() to get the window's hWnd. Use that with a pinvoke to SetFocus() or SetWindowLong().
     
    See http://msdn.microsoft.com/en-us/library/windows/desktop/ms680102(v=vs.85).aspx for more information on the IOleWindow interface.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "B Atkinson" <=?utf-8?B?QiBBdGtpbnNvbg==?=> wrote in message news:e7ce082c-31c7-4bed-9d44-82d0f0873755...

    Hello all,

    I am using a Custom Task Pane inside of an Inspector for a MailItem (compose/reply window) to display a form for the user to interact with before sending an e-mail.  One of the things they can do is click a button inside the pane to add some content to the e-mail body.  This all works fine, but once they click the button the focus is set inside the task pane, and I would like the focus to be set back to the MailItem's word editor (the body of the e-mail) where the text was just inserted so they can seamlessly resume typing without having to click their mouse back into it.  I have tried using the Inspector's .Activate() method, the WordEditor's ..Activate() method, to no avail.  I'm sure there would be some hacky method using WinAPI's to force focus of the window, but does anyone know of a way to do this just using the object model?  If not, could someone point me in the right direction to how to do the hacky method?  The problem is there could potentially be many inspectors open (multiple compose/reply windows) and I would want to make sure it was focusing the correct instance of the Inspector.

    Thank you very much!


    Ken Slovak MVP - Outlook
    Wednesday, May 1, 2013 6:20 PM
    Moderator
  • Actually, calling the SetActiveWIndow() function is probably the best call to make.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Ken Slovak MVP" <=?utf-8?B?S2VuIFNsb3ZhayBNVlA=?=> wrote in message news:547b3dd5-d5e6-45ab-a051-7f75f5229cf2...
    You can use the Win32 API's to do that, but the object models won't do it for you.
     
    Outlook Inspectors and Explorers can be cast to IOleWindow objects, then you can call IOleWindow.GetWindow() to get the window's hWnd. Use that with a pinvoke to SetFocus() or SetWindowLong().
     
    See http://msdn.microsoft.com/en-us/library/windows/desktop/ms680102(v=vs.85).aspx for more information on the IOleWindow interface.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "B Atkinson" <=?utf-8?B?QiBBdGtpbnNvbg==?=> wrote in message news:e7ce082c-31c7-4bed-9d44-82d0f0873755...

    Hello all,

    I am using a Custom Task Pane inside of an Inspector for a MailItem (compose/reply window) to display a form for the user to interact with before sending an e-mail.  One of the things they can do is click a button inside the pane to add some content to the e-mail body.  This all works fine, but once they click the button the focus is set inside the task pane, and I would like the focus to be set back to the MailItem's word editor (the body of the e-mail) where the text was just inserted so they can seamlessly resume typing without having to click their mouse back into it.  I have tried using the Inspector's .Activate() method, the WordEditor's ..Activate() method, to no avail.  I'm sure there would be some hacky method using WinAPI's to force focus of the window, but does anyone know of a way to do this just using the object model?  If not, could someone point me in the right direction to how to do the hacky method?  The problem is there could potentially be many inspectors open (multiple compose/reply windows) and I would want to make sure it was focusing the correct instance of the Inspector.

    Thank you very much!


    Ken Slovak MVP - Outlook

    Ken Slovak MVP - Outlook
    Wednesday, May 1, 2013 6:38 PM
    Moderator
  • It looks like the NNTP bridge to the forums isn't working correctly, here's what I had posted:

    You can use the Win32 API's to do that, but the object models won't do it for you.
     
    Outlook Inspectors and Explorers can be cast to IOleWindow objects, then you can call IOleWindow.GetWindow() to get the window's hWnd. Use that with a pinvoke to SetFocus() or SetWindowLong(). Actually, calling the SetActiveWIndow() function is probably the best call to make.
     
    See http://msdn.microsoft.com/en-us/library/windows/desktop/ms680102(v=vs.85).aspx for more information on the IOleWindow interface.

    Ken Slovak MVP - Outlook

    Wednesday, May 1, 2013 8:23 PM
    Moderator

All replies

  • You can use the Win32 API's to do that, but the object models won't do it for you.
     
    Outlook Inspectors and Explorers can be cast to IOleWindow objects, then you can call IOleWindow.GetWindow() to get the window's hWnd. Use that with a pinvoke to SetFocus() or SetWindowLong().
     
    See http://msdn.microsoft.com/en-us/library/windows/desktop/ms680102(v=vs.85).aspx for more information on the IOleWindow interface.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "B Atkinson" <=?utf-8?B?QiBBdGtpbnNvbg==?=> wrote in message news:e7ce082c-31c7-4bed-9d44-82d0f0873755...

    Hello all,

    I am using a Custom Task Pane inside of an Inspector for a MailItem (compose/reply window) to display a form for the user to interact with before sending an e-mail.  One of the things they can do is click a button inside the pane to add some content to the e-mail body.  This all works fine, but once they click the button the focus is set inside the task pane, and I would like the focus to be set back to the MailItem's word editor (the body of the e-mail) where the text was just inserted so they can seamlessly resume typing without having to click their mouse back into it.  I have tried using the Inspector's .Activate() method, the WordEditor's ..Activate() method, to no avail.  I'm sure there would be some hacky method using WinAPI's to force focus of the window, but does anyone know of a way to do this just using the object model?  If not, could someone point me in the right direction to how to do the hacky method?  The problem is there could potentially be many inspectors open (multiple compose/reply windows) and I would want to make sure it was focusing the correct instance of the Inspector.

    Thank you very much!


    Ken Slovak MVP - Outlook
    Wednesday, May 1, 2013 6:20 PM
    Moderator
  • Actually, calling the SetActiveWIndow() function is probably the best call to make.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Ken Slovak MVP" <=?utf-8?B?S2VuIFNsb3ZhayBNVlA=?=> wrote in message news:547b3dd5-d5e6-45ab-a051-7f75f5229cf2...
    You can use the Win32 API's to do that, but the object models won't do it for you.
     
    Outlook Inspectors and Explorers can be cast to IOleWindow objects, then you can call IOleWindow.GetWindow() to get the window's hWnd. Use that with a pinvoke to SetFocus() or SetWindowLong().
     
    See http://msdn.microsoft.com/en-us/library/windows/desktop/ms680102(v=vs.85).aspx for more information on the IOleWindow interface.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "B Atkinson" <=?utf-8?B?QiBBdGtpbnNvbg==?=> wrote in message news:e7ce082c-31c7-4bed-9d44-82d0f0873755...

    Hello all,

    I am using a Custom Task Pane inside of an Inspector for a MailItem (compose/reply window) to display a form for the user to interact with before sending an e-mail.  One of the things they can do is click a button inside the pane to add some content to the e-mail body.  This all works fine, but once they click the button the focus is set inside the task pane, and I would like the focus to be set back to the MailItem's word editor (the body of the e-mail) where the text was just inserted so they can seamlessly resume typing without having to click their mouse back into it.  I have tried using the Inspector's .Activate() method, the WordEditor's ..Activate() method, to no avail.  I'm sure there would be some hacky method using WinAPI's to force focus of the window, but does anyone know of a way to do this just using the object model?  If not, could someone point me in the right direction to how to do the hacky method?  The problem is there could potentially be many inspectors open (multiple compose/reply windows) and I would want to make sure it was focusing the correct instance of the Inspector.

    Thank you very much!


    Ken Slovak MVP - Outlook

    Ken Slovak MVP - Outlook
    Wednesday, May 1, 2013 6:38 PM
    Moderator
  • It looks like the NNTP bridge to the forums isn't working correctly, here's what I had posted:

    You can use the Win32 API's to do that, but the object models won't do it for you.
     
    Outlook Inspectors and Explorers can be cast to IOleWindow objects, then you can call IOleWindow.GetWindow() to get the window's hWnd. Use that with a pinvoke to SetFocus() or SetWindowLong(). Actually, calling the SetActiveWIndow() function is probably the best call to make.
     
    See http://msdn.microsoft.com/en-us/library/windows/desktop/ms680102(v=vs.85).aspx for more information on the IOleWindow interface.

    Ken Slovak MVP - Outlook

    Wednesday, May 1, 2013 8:23 PM
    Moderator