public unsafe static BOOL IsAccelerator(HandleRef hAccel, int cAccelEntries, ref User32.MSG lpMsg, ushort *lpwCmd) { BOOL result = IsAccelerator(hAccel.Handle, cAccelEntries, ref lpMsg, lpwCmd); GC.KeepAlive(hAccel.Wrapper); return(result); }
BOOL IMsoComponentManager.FContinueIdle() { // If we have a message on queue, then don't continue idle processing. var msg = new User32.MSG(); return(User32.PeekMessageW(ref msg)); }
private void ForceSynchronousPaint() { if (!IsDisposed) { if (_numPaintsServiced == 0) { // protect against re-entrancy. try { var msg = new User32.MSG(); while (User32.PeekMessageW(ref msg, IntPtr.Zero, User32.WM.PAINT, User32.WM.PAINT, User32.PM.REMOVE).IsTrue()) { User32.UpdateWindow(msg.hwnd); // Infinite loop protection if (_numPaintsServiced++ > MaxPaintsToService) { Debug.Fail("somehow we've gotten ourself in a situation where we're pumping an unreasonable number of paint messages, investigate."); break; } } } finally { _numPaintsServiced = 0; } } } }
public void ThreadContext_EmptyProcessFiltersWorks() { // Test that no filters at all does not throw, and that returns false from translation Application.ThreadContext threadContext = new Application.ThreadContext(); var msg = new User32.MSG(); Assert.False(threadContext.PreTranslateMessage(ref msg)); }
public void ProcessEvent() { User32.MSG msg = default(User32.MSG); while (User32.PeekMessage(ref msg, WindowHandle, 0, 0, User32.PeekMessageFlags.Remove)) { User32.TranslateMessage(ref msg); User32.DispatchMessage(ref msg); } }
public void ShowDialog() { Show(); var msg = new User32.MSG(); while (Win32.User32.GetMessage(out msg, IntPtr.Zero, 0, 0)) { Win32.User32.TranslateMessage(ref msg); Win32.User32.DispatchMessage(ref msg); } }
public void ThreadContext_MultipleProcessFiltersProcesses() { // Test that multiple filters work Application.ThreadContext threadContext = new Application.ThreadContext(); User32.WindowMessage filterId2 = TestMessageId2; var mockContext2 = new Mock <IMessageFilter>(MockBehavior.Strict); mockContext2.Setup(c => c.PreFilterMessage(ref It.Ref <Message> .IsAny)) .Returns((MessageCallback)((ref Message m) => m.Msg == (int)filterId2)); threadContext.AddMessageFilter(mockContext2.Object); User32.WindowMessage filterId3 = TestMessageId3; var mockContext3 = new Mock <IMessageFilter>(MockBehavior.Strict); mockContext3.Setup(c => c.PreFilterMessage(ref It.Ref <Message> .IsAny)) .Returns((MessageCallback)((ref Message m) => m.Msg == (int)filterId3)); threadContext.AddMessageFilter(mockContext3.Object); var msg = new User32.MSG { message = TestMessageId1 }; Assert.False(threadContext.PreTranslateMessage(ref msg)); mockContext2.Verify(c => c.PreFilterMessage(ref It.Ref <Message> .IsAny), Times.Exactly(1)); mockContext3.Verify(c => c.PreFilterMessage(ref It.Ref <Message> .IsAny), Times.Exactly(1)); msg = new User32.MSG { message = TestMessageId2 }; Assert.True(threadContext.PreTranslateMessage(ref msg)); mockContext2.Verify(c => c.PreFilterMessage(ref It.Ref <Message> .IsAny), Times.Exactly(2)); mockContext3.Verify(c => c.PreFilterMessage(ref It.Ref <Message> .IsAny), Times.Exactly(1)); msg = new User32.MSG { message = TestMessageId3 }; Assert.True(threadContext.PreTranslateMessage(ref msg)); mockContext2.Verify(c => c.PreFilterMessage(ref It.Ref <Message> .IsAny), Times.Exactly(3)); mockContext3.Verify(c => c.PreFilterMessage(ref It.Ref <Message> .IsAny), Times.Exactly(2)); }
public void Update() { try { bool asd = keys_AltTab; //event message loop ... User32.MSG _eventMessage = new User32.MSG(); while (User32.PeekMessage(ref _eventMessage, IntPtr.Zero, 0, 0, User32.PM_REMOVE)) { User32.TranslateMessage(ref _eventMessage); User32.DispatchMessage(ref _eventMessage); } //set current curosr pos ... User32.GetCursorPos(out _cursorPos); //get current window with focus ... CurrentWindowHandle = User32.GetForegroundWindow(); if (CurrentWindowHandle == IntPtr.Zero) { return; } if (keys_AltTab) { _altTabWindowHandle = CurrentWindowHandle; } Process process = GetProcessByHandle(CurrentWindowHandle); if (process == null) { return; } ProcessModule pModule = process.MainModule; if (pModule == null) { return; } //set current exe ... CurrentExecutable = new Executable(pModule.FileName); }catch { } }
public void ToolTip_WmShow_Invokes_AnnounceText_WithExpectedText_ForTabControlTabs() { Mock <TabControl> mockTabControl = new() { CallBase = true, Object = { ShowToolTips = true } }; Mock <Control.ControlAccessibleObject> mockAccessibleObject = new(MockBehavior.Strict, mockTabControl.Object); mockAccessibleObject .Setup(a => a.InternalRaiseAutomationNotification( It.IsAny <AutomationNotificationKind>(), It.IsAny <AutomationNotificationProcessing>(), It.IsAny <string>())) .Returns(true); mockTabControl.Protected().Setup <AccessibleObject>("CreateAccessibilityInstance").Returns(mockAccessibleObject.Object); // We need a Form because tooltips don't work on controls without a valid parent. using Form form = new(); using ToolTip toolTip = new(); using TabControl tabControl = mockTabControl.Object; using TabPage tabPage = new() { ToolTipText = "TabPage" }; toolTip.SetToolTip(tabControl, "TabControl"); tabControl.Controls.Add(tabPage); form.Controls.Add(tabControl); form.Show(); Assert.NotEqual(IntPtr.Zero, tabControl.InternalHandle); Assert.True(toolTip.GetHandleCreated()); // Enforce AccessibilityObject creation. Assert.Equal(mockAccessibleObject.Object, tabControl.AccessibilityObject); // Post MOUSEMOVE to the tooltip queue and then just remove it from the queue without handling. // This will update the point returned by GetMessagePos which is used by TTM.POPUP to determine the tool to display. Assert.True(User32.PostMessageW(toolTip, User32.WM.MOUSEMOVE, lParam: PARAM.FromPoint(tabPage.GetToolNativeScreenRectangle().Location)).IsTrue()); User32.MSG msg = default; Assert.True(User32.PeekMessageW(ref msg, toolTip, User32.WM.MOUSEMOVE, User32.WM.MOUSEMOVE, User32.PM.REMOVE).IsTrue()); // Show the tooltip. User32.SendMessageW(toolTip, (User32.WM)ComCtl32.TTM.POPUP); mockAccessibleObject.Verify(a => a.InternalRaiseAutomationNotification( AutomationNotificationKind.ActionCompleted, AutomationNotificationProcessing.All, $" {tabPage.ToolTipText}"), Times.Once); }
public void ThreadContext_CorrectProcessFiltersProcesses() { // Test that a filter with the correct ID returns true Application.ThreadContext threadContext = new Application.ThreadContext(); User32.WindowMessage filterId = TestMessageId2; var mockContext = new Mock <IMessageFilter>(MockBehavior.Strict); mockContext.Setup(c => c.PreFilterMessage(ref It.Ref <Message> .IsAny)) .Returns((MessageCallback)((ref Message m) => m.Msg == (int)filterId)); threadContext.AddMessageFilter(mockContext.Object); var msg = new User32.MSG { message = filterId }; Assert.True(threadContext.PreTranslateMessage(ref msg)); mockContext.Verify(c => c.PreFilterMessage(ref It.Ref <Message> .IsAny), Times.Exactly(1)); }
public void ThreadContext_WrongProcessFiltersPassesThrough() { // Test that a filter for the wrong ID returns false, but does get called Application.ThreadContext threadContext = new Application.ThreadContext(); User32.WindowMessage filterId = TestMessageId2; var mockContext = new Mock <IMessageFilter>(MockBehavior.Strict); mockContext.Setup(c => c.PreFilterMessage(ref It.Ref <Message> .IsAny)) .Returns((MessageCallback)((ref Message m) => m.Msg == (int)filterId)); threadContext.AddMessageFilter(mockContext.Object); var msg = new User32.MSG { message = TestMessageId1 }; Assert.False(threadContext.PreTranslateMessage(ref msg)); mockContext.Verify(c => c.PreFilterMessage(ref It.Ref <Message> .IsAny), Times.Exactly(1)); }
/// <summary> /// Run an event loop until a <see cref="User32.WindowMessage.WM_QUIT"/> message is caught /// </summary> public static void Run() { var msg = new User32.MSG(); var handle = GCHandle.Alloc(msg); while (true) { if (!User32.PeekMessage((IntPtr)handle, IntPtr.Zero, User32.WindowMessage.WM_NULL, User32.WindowMessage.WM_NULL, User32.PeekMessageRemoveFlags.PM_REMOVE)) { continue; } if (msg.message == User32.WindowMessage.WM_QUIT) { break; } User32.TranslateMessage(ref msg); User32.DispatchMessage(ref msg); } handle.Free(); }
BOOL IMsoComponentManager.FPushMessageLoop( UIntPtr dwComponentID, msoloop uReason, void *pvLoopData) { // Hold onto old state to allow restore before we exit... msocstate currentLoopState = _currentState; BOOL continueLoop = BOOL.TRUE; if (!OleComponents.TryGetValue(dwComponentID, out ComponentHashtableEntry entry)) { return(BOOL.FALSE); } IMsoComponent prevActive = _activeComponent; try { User32.MSG msg = new User32.MSG(); IMsoComponent requestingComponent = entry.component; _activeComponent = requestingComponent; Debug.WriteLineIf( CompModSwitches.MSOComponentManager.TraceInfo, $"ComponentManager : Pushing message loop {uReason}"); Debug.Indent(); while (continueLoop.IsTrue()) { // Determine the component to route the message to IMsoComponent component = _trackingComponent ?? _activeComponent ?? requestingComponent; bool useAnsi = false; BOOL peeked = User32.PeekMessageW(ref msg); if (peeked.IsTrue()) { useAnsi = msg.hwnd != IntPtr.Zero && User32.IsWindowUnicode(msg.hwnd).IsFalse(); if (useAnsi) { peeked = User32.PeekMessageA(ref msg); } } if (peeked.IsTrue()) { continueLoop = component.FContinueMessageLoop(uReason, pvLoopData, &msg); // If the component wants us to process the message, do it. if (continueLoop.IsTrue()) { if (useAnsi) { User32.GetMessageA(ref msg); Debug.Assert(User32.IsWindowUnicode(msg.hwnd).IsFalse()); } else { User32.GetMessageW(ref msg); Debug.Assert(msg.hwnd == IntPtr.Zero || User32.IsWindowUnicode(msg.hwnd).IsTrue()); } if (msg.message == User32.WM.QUIT) { Debug.WriteLineIf( CompModSwitches.MSOComponentManager.TraceInfo, "ComponentManager : Normal message loop termination"); ThreadContext.FromCurrent().DisposeThreadWindows(); if (uReason != msoloop.Main) { User32.PostQuitMessage((int)msg.wParam); } continueLoop = BOOL.FALSE; break; } // Now translate and dispatch the message. // // Reading through the rather sparse documentation, // it seems we should only call FPreTranslateMessage // on the active component. if (component.FPreTranslateMessage(&msg).IsFalse()) { User32.TranslateMessage(ref msg); if (useAnsi) { User32.DispatchMessageA(ref msg); } else { User32.DispatchMessageW(ref msg); } } } } else { // If this is a DoEvents loop, then get out. There's nothing left for us to do. if (uReason == msoloop.DoEvents || uReason == msoloop.DoEventsModal) { break; } // Nothing is on the message queue. Perform idle processing and then do a WaitMessage. bool continueIdle = false; if (OleComponents != null) { IEnumerator enumerator = OleComponents.Values.GetEnumerator(); while (enumerator.MoveNext()) { ComponentHashtableEntry idleEntry = (ComponentHashtableEntry)enumerator.Current; continueIdle |= idleEntry.component.FDoIdle(msoidlef.All).IsTrue(); } } // Give the component one more chance to terminate the message loop. continueLoop = component.FContinueMessageLoop(uReason, pvLoopData, null); if (continueLoop.IsTrue()) { if (continueIdle) { // If someone has asked for idle time, give it to them. However, // don't cycle immediately; wait up to 100ms. Why? Because we don't // want someone to attach to idle, forget to detach, and then cause // CPU to end up in race condition. For Windows Forms this generally isn't an issue because // our component always returns false from its idle request User32.MsgWaitForMultipleObjectsEx(0, IntPtr.Zero, 100, User32.QS.ALLINPUT, User32.MWMO.INPUTAVAILABLE); } else { // We should call GetMessage here, but we cannot because // the component manager requires that we notify the // active component before we pull the message off the // queue. This is a bit of a problem, because WaitMessage // waits for a NEW message to appear on the queue. If a // message appeared between processing and now WaitMessage // would wait for the next message. We minimize this here // by calling PeekMessage. if (User32.PeekMessageW(ref msg, IntPtr.Zero, 0, 0, User32.PM.NOREMOVE).IsFalse()) { User32.WaitMessage(); } } } } } Debug.Unindent(); Debug.WriteLineIf(CompModSwitches.MSOComponentManager.TraceInfo, $"ComponentManager : message loop {uReason} complete."); } finally { _currentState = currentLoopState; _activeComponent = prevActive; } return(continueLoop.IsFalse() ? BOOL.TRUE : BOOL.FALSE); }
public bool DoBeginDrag(object[] components, SelectionRules rules, int initialX, int initialY) { // if we're in a sizing operation, or the mouse isn't down, don't do this! if ((rules & SelectionRules.AllSizeable) != SelectionRules.None || Control.MouseButtons == MouseButtons.None) { return(true); } Control c = client.GetDesignerControl(); localDrag = true; localDragInside = false; dragComps = components; dragBase = new Point(initialX, initialY); localDragOffset = Point.Empty; c.PointToClient(new Point(initialX, initialY)); DragDropEffects allowedEffects = DragDropEffects.Copy | DragDropEffects.None | DragDropEffects.Move; // check to see if any of the components are inherhited. if so, don't allow them to be moved. // We replace DragDropEffects.Move with a local bit called AllowLocalMoveOnly which means it // can be moved around on the current dropsource/target, but not to another target. Since only // we understand this bit, other drop targets will not allow the move to occur // for (int i = 0; i < components.Length; i++) { InheritanceAttribute attr = (InheritanceAttribute)TypeDescriptor.GetAttributes(components[i])[typeof(InheritanceAttribute)]; if (!attr.Equals(InheritanceAttribute.NotInherited) && !attr.Equals(InheritanceAttribute.InheritedReadOnly)) { allowedEffects &= ~DragDropEffects.Move; allowedEffects |= (DragDropEffects)AllowLocalMoveOnly; } } DataObject data = new ComponentDataObjectWrapper(new ComponentDataObject(client, serviceProvider, components, initialX, initialY)); // We make sure we're painted before we start the drag. Then, we disable window painting to // ensure that the drag can proceed without leaving artifacts lying around. We should be caling LockWindowUpdate, // but that causes a horrible flashing because GDI+ uses direct draw. // User32.MSG msg = default; while (User32.PeekMessageW(ref msg, IntPtr.Zero, User32.WM.PAINT, User32.WM.PAINT, User32.PM.REMOVE).IsTrue()) { User32.TranslateMessage(ref msg); User32.DispatchMessageW(ref msg); } // don't do any new painting... bool oldFreezePainting = freezePainting; // asurt 90345 -- this causes some subtle bugs, so i'm turning it off to see if we really need it, and if we do // if we can find a better way. // //freezePainting = true; AddCurrentDrag(data, client.Component); // Walk through all the children recursively and disable drag-drop // for each of them. This way, we will not accidentally try to drop // ourselves into our own children. // ArrayList allowDropChanged = new ArrayList(); foreach (object comp in components) { Control ctl = comp as Control; if (ctl != null && ctl.HasChildren) { DisableDragDropChildren(ctl.Controls, allowDropChanged); } } DragDropEffects effect = DragDropEffects.None; IDesignerHost host = GetService(typeof(IDesignerHost)) as IDesignerHost; DesignerTransaction trans = null; if (host != null) { trans = host.CreateTransaction(string.Format(SR.DragDropDragComponents, components.Length)); } try { effect = c.DoDragDrop(data, allowedEffects); if (trans != null) { trans.Commit(); } } finally { RemoveCurrentDrag(data); // Reset the AllowDrop for the components being dragged. // foreach (Control ctl in allowDropChanged) { ctl.AllowDrop = true; } freezePainting = oldFreezePainting; if (trans != null) { ((IDisposable)trans).Dispose(); } } bool isMove = (effect & DragDropEffects.Move) != 0 || ((int)effect & AllowLocalMoveOnly) != 0; // since the EndDrag will clear this bool isLocalMove = isMove && localDragInside; ISelectionUIService selectionUISvc = (ISelectionUIService)GetService(typeof(ISelectionUIService)); Debug.Assert(selectionUISvc != null, "Unable to get selection ui service when adding child control"); if (selectionUISvc != null) { // We must check to ensure that UI service is still in drag mode. It is // possible that the user hit escape, which will cancel drag mode. // if (selectionUISvc.Dragging) { // cancel the drag if we aren't doing a local move selectionUISvc.EndDrag(!isLocalMove); } } if (!localDragOffset.IsEmpty && effect != DragDropEffects.None) { DrawDragFrames(dragComps, localDragOffset, localDragEffect, Point.Empty, DragDropEffects.None, false); } localDragOffset = Point.Empty; dragComps = null; localDrag = localDragInside = false; dragBase = Point.Empty; /*if (!isLocalMove && isMove){ * IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost)); * IUndoService undoService = (IUndoService)GetService(typeof(IUndoService)); * IActionUnit unit = null; * * if (host != null) { * DesignerTransaction trans = host.CreateTransaction("Drag/drop"); * try{ * // delete the components * try{ * for (int i = 0; i < components.Length; i++){ * if (components[i] is IComponent){ * if (undoService != null){ * unit = new CreateControlActionUnit(host, (IComponent)components[i], true); * } * host.DestroyComponent((IComponent)components[i]); * if (undoService != null){ * undoService.AddAction(unit, false); * } * } * } * }catch(CheckoutException ex){ * if (ex != CheckoutException.Canceled){ * throw ex; * } * } * } * finally{ * trans.Commit(); * } * } * }*/ return(false); }
public static extern bool GetMessage( out User32.MSG lpMsg, IntPtr hWnd, uint wMsgFilterMin, uint wMsgFilterMax);
public unsafe static extern BOOL IsAccelerator(IntPtr hAccel, int cAccelEntries, ref User32.MSG lpMsg, ushort *lpwCmd);