Search code examples
wpfvisual-studio-2010focusinteropvisual-foxpro

Foxpro hosted Wpf window return focus to foxpro when Tab is pressed


I have a Visual FoxPro 9 application from which I call a wpf window using COM interop. When TAB is pressed for the first time the focus goes back to the FoxPro window. If I come back to the wpf window this happens again until the third time I do it, and then the focus works normally. This occurs using the mouse or Alt+Tab to go back to the wpf window. It happens whether there is a focused element (textbox, datepicker,...) or not. I have tried to capture the PreviewKeyDown event of the window, but it seems that it happens before it can capture it. I have tested the wpf window in a wpf application and it works ok.

The C Sharp class is like:

[ClassInterface(ClassInterfaceType.AutoDispatch)]
[ProgId("SBN.WPF.Com")]
[ComVisible(true)]
public class WpfFoxPro
{

and the FoxPro calls are like:

oDll = Createobjectex("SBN.WPF.Com", "", "")
oDll.VOpenWPFWindow()

I'm using Visual Studio 2010 and .Net 4.0 and I'm running out of ideas. Does any one know something about this?


Solution

  • Might sound stupid, but could you disable the VFP windows whilst the WPF one is active? It's not a solution, but based on 10 years of working with VFP, sometimes you just have to stop bashing your head against the brick wall and go for the kludge. ;)