protected internal override bool ProcessMnemonic(char charCode) {
            bool processed = false;

            if (CanSelect) {
                try {
                    NativeMethods.tagCONTROLINFO ctlInfo = new NativeMethods.tagCONTROLINFO();
                    int hr = this.axOleControl.GetControlInfo(ctlInfo);
                    if (NativeMethods.Succeeded(hr)) {
                        //
                        // Sadly, we don't have a message so we must fake one ourselves.
                        // The message we are faking is a WM_SYSKEYDOWN with the right
                        // alt key setting.
                        NativeMethods.MSG msg = new NativeMethods.MSG();
                        msg.hwnd = IntPtr.Zero;
                        msg.message = NativeMethods.WM_SYSKEYDOWN;
                        msg.wParam = (IntPtr) Char.ToUpper(charCode, CultureInfo.CurrentCulture);
                        msg.lParam = (IntPtr) 0x20180001;
                        msg.time = SafeNativeMethods.GetTickCount();
                        NativeMethods.POINT p = new NativeMethods.POINT();
                        UnsafeNativeMethods.GetCursorPos(p);
                        msg.pt_x = p.x;
                        msg.pt_y = p.y;
                        if (SafeNativeMethods.IsAccelerator(new HandleRef(ctlInfo, ctlInfo.hAccel), ctlInfo.cAccel, ref msg, null)) {
                            this.axOleControl.OnMnemonic(ref msg);
                            FocusInternal();
                            processed = true;
                        }
                    }
                }
                catch (Exception ex) {
                    if (ClientUtils.IsCriticalException(ex)) {
                        throw;
                    }
                    Debug.Fail("error in processMnemonic");
                }
            }
            return processed;
        }
Exemplo n.º 2
0
 protected internal override bool ProcessMnemonic(char charCode) {
     Debug.WriteLineIf(ControlKeyboardRouting.TraceVerbose, "In AxHost.ProcessMnemonic: " + (int)charCode);
     if (CanSelect) {
         try {
             NativeMethods.tagCONTROLINFO ctlInfo = new NativeMethods.tagCONTROLINFO();
             int hr = GetOleControl().GetControlInfo(ctlInfo);
             if (NativeMethods.Failed(hr)) {
                 return false;
             }
             NativeMethods.MSG msg = new NativeMethods.MSG();
             // Sadly, we don't have a message so we must fake one ourselves...
             // A bit of ugliness here (a bit?  more like a bucket...)
             // The message we are faking is a WM_SYSKEYDOWN w/ the right alt key setting...
             msg.hwnd = (ContainingControl == null) ? IntPtr.Zero : ContainingControl.Handle;
             msg.message = NativeMethods.WM_SYSKEYDOWN;
             msg.wParam = (IntPtr) Char.ToUpper(charCode, CultureInfo.CurrentCulture);
             msg.lParam = (IntPtr) 0x20180001;
             msg.time = SafeNativeMethods.GetTickCount();
             NativeMethods.POINT p = new NativeMethods.POINT();
             UnsafeNativeMethods.GetCursorPos(p);
             msg.pt_x = p.x;
             msg.pt_y = p.y;
             if (SafeNativeMethods.IsAccelerator(new HandleRef(ctlInfo, ctlInfo.hAccel), ctlInfo.cAccel, ref msg, null)) {
                 GetOleControl().OnMnemonic(ref msg);
                 Debug.WriteLineIf(ControlKeyboardRouting.TraceVerbose, "\t Processed mnemonic " + msg);
                 Focus();
                 return true;
             }
         }
         catch (Exception t) {
             Debug.Fail("error in processMnemonic");
             Debug.Fail(t.ToString());
             return false;
         }
     }
     return false;
 }