Activating CustomTask Panes

N

Nick Lucas

When I make a custom task pane visible from a command bar button or from a
ribbon button it is displayed but the user then has to click on the task pane
to give it focus and activate it. I have added a SendKeys.Send ("{F6}") which
will give the task pane focus but only if the Inbox - Microsoft Outlook pane
currently has focus i.e. this doesn't work if you click on the To-Do Bar
first. I've tried API calls but without any success. From my 26 years of
experience with end users I know that they will not find this acceptable and
it's not a great user experience. Does anyone have a working work-around or
could the VSTO team add a custom task pane activate() of focus() method ?
 
K

Ken Slovak - [MVP - Outlook]

VSTO has nothing to do with it, CTP's are part of the Office library and any
new methods for CTP's would have to be added by the Office team.

There is no direct way to do what you want but you can try working around
the problem by handling the VisibleStateChange() event of the CTP and
checking to see if Visible is true. In that case you can call a public
method in the task pane form to set focus to a control on the form or to the
form itself. You could also use the constructor method of the form to do
something like that. In Win32 API terms you could also get the hWnd of the
CTP and use the SetFocus() API in that event or the form constructor.

See if any of that helps.
 
N

Nick Lucas

I've tried the suggestions and neither method works. When I tried the API
calls I checked that the SetActiveWindow() correctly returned the parent
window hwnd value. The parent being "Inbox - Microsoft Outlook". But the CTP
still doesn't get the focus. I have the code in ctp_VisibleChanged, I believe
VisibleStateChanged was in the previous VSTO SE, I'm using VS2008 and VSTO
3.0. Using a FindWindow() and SetActiveWIndow() with Windows Forms 2.0 as a
test for the APIs works fine and I can switch to whatever window I desire so
I know the API calls are fine, but something is not happening when I try it
with the CTP.

With the focus method in the ctp_VisibleChanged() I tried:

MyUserControl myControl=(MyUserControl)ctp.Control;
myControl.ShowMe()

Where ShowMe() in the user control code contained this.Focus(), I also tried
it with a control on the user control. Running in debug shows that it hits
the code but still no joy, just to make sure that it was running the ShowMe()
code I changed the text property of one of my textboxes within the user
control to "CHANGED !" and it did indeed change it.
 
K

Ken Slovak - [MVP - Outlook]

I can get an hWnd for the CTP as a child window of an Explorer or Inspector,
so there should be some way of setting focus to it. I haven't played with it
to see what works but I'd see if SetFocus() works, you didn't say if you
tried that.

If that doesn't work then I'd be looking at SetWindowPos() or even
SetWindowLong().

That's about all I can think of.
 
N

Nick Lucas

Many thanks for your suggestions Ken, these APIs "do what they say on the
tin" within Windows Forms but still no joy in the CTP. I did try the
SetFocus() as well. I too get the hWnd ok but I don't understand why the API
call doesn't work.
 
N

Nick Lucas

I just added a GetWindowText() to ensure the hWnd was correct and
unfortunately it is correct. The stringbuilder returns the correct caption
from the CTP.
 
K

Ken Slovak - [MVP - Outlook]

Then I'm out of ideas.

Using those API's certainly works in my usual C# projects as well as all the
VB6 projects I've done, but I hadn't tried to set the focus into a CTP.
About all I can think of is to open a support incident with MS, but you're
likely to be told that there's nothing to be done I'd guess.
 
N

Nick Lucas

Once again many thanks for your help, I've raised it as a bug. I hope you'll
agree that this doesn't make for a great User Experience !
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top