views:

573

answers:

2

I've written a IE Toolbar in C# and everything is working fine except that when I open a child Windows Form from my toolbar, the tab key doesn't work on the child form to allow me to move from field to field.

The interesting part is that when I open my child form using form.showDialog() instead of form.show() the tabs work like normal.

The toolbar I've created is based on this article and this article

I've implemented TranslateAcceleratorIO as mentioned in several articles, but still no luck.

Here are my implmentations of TranslateAcceleratorIO() and HasFocusIO() (implemented in my toolband class)

        [DllImport("user32.dll")]
        public static extern int TranslateMessage(ref MSG lpMsg);

        [DllImport("user32", EntryPoint = "DispatchMessage")]
        static extern bool DispatchMessage(ref MSG msg);

        public int HasFocusIO()
        {                            
            return this.ContainsFocus ? 0 : 1; //S_OK : S_FALSE;
        }

        public int TranslateAcceleratorIO(ref MSG msg)
        {                
            if (msg.message == 0x100)//WM_KEYDOWN
                if (msg.wParam == (uint)Keys.Tab || msg.wParam ==(uint)Keys.F6)
                {
                    if (SelectNextControl(
                            ActiveControl,
                            ModifierKeys == Keys.Shift ? false : true,
                            true,
                            true,
                            false)
                        )
                    {
                        return 0;//S_OK
                    }
                }
                else
                {                        
                    TranslateMessage(ref msg);
                    DispatchMessage(ref msg);
                    return 0;//S_OK
                }
            return 1;//S_FALSE
        }

I've also tried having TranslateAccelerator like this with no luck:

   public int TranslateAcceleratorIO(ref MSG msg)
    {

        TranslateMessage(ref msg);
        DispatchMessage(ref msg);
        return 0;//S_OK
    }

Has anybody else run into this issue?

+1  A: 

Are you also implementing HasFocusIO? I believe your main toolbar class must also implement HasFocusIO and return true.

These types of problems with IE toolbars were the bane of my existence for a while. I think what I eventually ended up doing was creating separate UI threads and making my dialogs modal in those threads, which eliminated a bunch of weird issues. But I think implementing HasFocusIO and TranslateAcceleratorIO should work for this particular one.

Gerald
A: 

Where are you implementing these? It's hard to tell from what you have there, are you implementing them in your Form or are you implementing them in your deskband class?

You need to implement them in your DeskBand implementation, and HasFocusIO needs to return true whenever one of your windows has focus (not just when the toolbar has focus). Then the messages for Tab, Delete, arrow keys, etc should be dispatched to the TranslateAcceleratorIO, also in your deskband, and from there you'll have to pass them along to your form.

The IE plugin framework is incredibly hacky that way.

Gerald
The methods I posted are implemented in my deskband. I hooked up the debugger and I noticed my HasFocusIO() is never getting called, so there must be an issue with how I'm hooking into IE.
Millhouse