protected override void WndProc(ref Message m) { switch (m.Msg) { // // Things we explicitly ignore and pass to the ActiveX's windproc // case NativeMethods.WM_ERASEBKGND: case NativeMethods.WM_REFLECT + NativeMethods.WM_NOTIFYFORMAT: case NativeMethods.WM_SETCURSOR: case NativeMethods.WM_SYSCOLORCHANGE: case NativeMethods.WM_LBUTTONDBLCLK: case NativeMethods.WM_LBUTTONUP: case NativeMethods.WM_MBUTTONDBLCLK: case NativeMethods.WM_MBUTTONUP: case NativeMethods.WM_RBUTTONDBLCLK: case NativeMethods.WM_RBUTTONUP: case NativeMethods.WM_CONTEXTMENU: // // Some of the MSComCtl controls respond to this message to do some // custom painting. So, we should just pass this message through. case NativeMethods.WM_DRAWITEM: DefWndProc(ref m); break; case NativeMethods.WM_COMMAND: if (!ReflectMessageInternal(m.LParam, ref m)) DefWndProc(ref m); break; case NativeMethods.WM_HELP: // We want to both fire the event, and let the ActiveX have the message... base.WndProc(ref m); DefWndProc(ref m); break; case NativeMethods.WM_LBUTTONDOWN: case NativeMethods.WM_MBUTTONDOWN: case NativeMethods.WM_RBUTTONDOWN: case NativeMethods.WM_MOUSEACTIVATE: if (!DesignMode) { if (containingControl != null && containingControl.ActiveControl != this) { FocusInternal(); } } DefWndProc(ref m); break; case NativeMethods.WM_KILLFOCUS: hwndFocus = (IntPtr)m.WParam; try { base.WndProc(ref m); } finally { hwndFocus = IntPtr.Zero; } break; case NativeMethods.WM_DESTROY: // // If we are currently in a state of InPlaceActive or above, // we should first reparent the ActiveX control to our parking // window before we transition to a state below InPlaceActive. // Otherwise we face all sorts of problems when we try to // transition back to a state >= InPlaceActive. // if (this.ActiveXState >= WebBrowserHelper.AXState.InPlaceActive) { IntPtr hwndInPlaceObject; if (NativeMethods.Succeeded(this.AXInPlaceObject.GetWindow(out hwndInPlaceObject))) { Application.ParkHandle(new HandleRef(this.AXInPlaceObject, hwndInPlaceObject)); } } if (RecreatingHandle) { axReloadingState = axState; } // // If the ActiveX control was holding on to our handle we need // to get it to throw it away. This, we do by transitioning it // down below InPlaceActivate (because it is when transitioning // up to InPlaceActivate that the ActiveX control grabs our handle). TransitionDownTo(WebBrowserHelper.AXState.Running); if (this.axWindow != null) { this.axWindow.ReleaseHandle(); } OnHandleDestroyed(EventArgs.Empty); break; default: if (m.Msg == WebBrowserHelper.REGMSG_MSG) { m.Result = (IntPtr)WebBrowserHelper.REGMSG_RETVAL; } else { base.WndProc(ref m); } break; } }
protected override void OnHandleCreated(EventArgs e) { // // ASURT 43741 This is needed to prevent some controls (for e.g. Office Web Components) from // failing to InPlaceActivate() when they call RegisterDragDrop() but do not call // OleInitialize(). The EE calls CoInitializeEx() on the thread, but I believe // that is not good enough for DragDrop. // if (Application.OleRequired() != System.Threading.ApartmentState.STA) { throw new ThreadStateException(SR.GetString(SR.ThreadMustBeSTA)); } base.OnHandleCreated(e); // make sure we restore whatever running state whad prior to the handle recreate. // if (axReloadingState != WebBrowserHelper.AXState.Passive && axReloadingState != axState) { if (axState < axReloadingState) { TransitionUpTo(axReloadingState); } else { TransitionDownTo(axReloadingState); } axReloadingState = WebBrowserHelper.AXState.Passive; } }