/// <include file='doc\Treenode.uex' path='docs/doc[@for="Treenode.ShowContextMenu"]/*' /> /// <devdoc> /// Shows the context menu for the Treenode. /// </devdoc> /// <internalonly/> private void ShowContextMenu(TreeNode treeNode) { if (treeNode.ContextMenu != null || treeNode.ContextMenuStrip != null) { ContextMenu contextMenu = treeNode.ContextMenu; ContextMenuStrip menu = treeNode.ContextMenuStrip; if (contextMenu != null) { NativeMethods.POINT pt = new NativeMethods.POINT(); UnsafeNativeMethods.GetCursorPos(pt); // VS7 #38994 // The solution to this problem was found in MSDN Article ID: Q135788. // Summary: the current window must be made the foreground window // before calling TrackPopupMenuEx, and a task switch must be // forced after the call. UnsafeNativeMethods.SetForegroundWindow(new HandleRef(this, this.Handle)); contextMenu.OnPopup( EventArgs.Empty ); SafeNativeMethods.TrackPopupMenuEx(new HandleRef(contextMenu, contextMenu.Handle), NativeMethods.TPM_VERTICAL, pt.x, pt.y, new HandleRef(this, this.Handle), null); // Force task switch (see above) UnsafeNativeMethods.PostMessage(new HandleRef(this, this.Handle), NativeMethods.WM_NULL, IntPtr.Zero, IntPtr.Zero); } // VsWhidbey : 432712. // Need to send TVM_SELECTITEM to highlight the node while the contextMenuStrip is being shown. else if (menu != null) { UnsafeNativeMethods.PostMessage(new HandleRef(this, Handle), NativeMethods.TVM_SELECTITEM, NativeMethods.TVGN_DROPHILITE, treeNode.Handle); menu.ShowInternal(this, PointToClient(MousePosition),/*keyboardActivated*/false); menu.Closing += new ToolStripDropDownClosingEventHandler(this.ContextMenuStripClosing); } } }
/// <summary> /// Предварительная фильтрация сообщения /// </summary> /// <param name="m">сообщение</param> /// <returns>true - прервать обработку, false - продолжать обработку</returns> public bool PreFilterMessage(ref Message m) { if (m.Msg == NativeMethods.WM_MOUSEWHEEL) { var point = new NativeMethods.POINT { x = ((short)((uint)m.LParam & 0xFFFF)), y = ((short)(((uint)m.LParam & 0xFFFF0000) >> 16)) }; m.HWnd = NativeMethods.WindowFromPoint(point); NativeMethods.SendMessage(m.HWnd, m.Msg, m.WParam, m.LParam); return true; } return false; }
public DCMapping(HandleRef hDC, Rectangle bounds) { if (hDC.Handle == IntPtr.Zero) { throw new ArgumentNullException("hDC"); } bool success; NativeMethods.POINT viewportOrg = new NativeMethods.POINT(); HandleRef hOriginalClippingRegion = NativeMethods.NullHandleRef; NativeMethods.RegionFlags originalRegionType = NativeMethods.RegionFlags.NULLREGION; this.translatedBounds = bounds; this.graphics = null; this.dc = DeviceContext.FromHdc(hDC.Handle); this.dc.SaveHdc(); // Retrieve the x-coordinates and y-coordinates of the viewport origin for the specified device context. success = SafeNativeMethods.GetViewportOrgEx(hDC, viewportOrg); Debug.Assert(success, "GetViewportOrgEx() failed."); // Create a new rectangular clipping region based off of the bounds specified, shifted over by the x & y specified in the viewport origin. HandleRef hClippingRegion = new HandleRef(null, SafeNativeMethods.CreateRectRgn(viewportOrg.x + bounds.Left, viewportOrg.y + bounds.Top, viewportOrg.x + bounds.Right, viewportOrg.y + bounds.Bottom)); Debug.Assert(hClippingRegion.Handle != IntPtr.Zero, "CreateRectRgn() failed."); try { // Create an empty region oriented at 0,0 so we can populate it with the original clipping region of the hDC passed in. hOriginalClippingRegion = new HandleRef(this, SafeNativeMethods.CreateRectRgn(0, 0, 0, 0)); Debug.Assert(hOriginalClippingRegion.Handle != IntPtr.Zero, "CreateRectRgn() failed."); // Get the clipping region from the hDC: result = {-1 = error, 0 = no region, 1 = success} per MSDN int result = SafeNativeMethods.GetClipRgn(hDC, hOriginalClippingRegion); Debug.Assert(result != -1, "GetClipRgn() failed."); // Shift the viewpoint origint by coordinates specified in "bounds". NativeMethods.POINT lastViewPort = new NativeMethods.POINT(); success = SafeNativeMethods.SetViewportOrgEx(hDC, viewportOrg.x + bounds.Left, viewportOrg.y + bounds.Top, lastViewPort); Debug.Assert(success, "SetViewportOrgEx() failed."); if (result != 0) { // Get the origninal clipping region so we can determine its type (we'll check later if we've restored the region back properly.) NativeMethods.RECT originalClipRect = new NativeMethods.RECT(); originalRegionType = (NativeMethods.RegionFlags)SafeNativeMethods.GetRgnBox(hOriginalClippingRegion, ref originalClipRect); Debug.Assert(originalRegionType != NativeMethods.RegionFlags.ERROR, "ERROR returned from SelectClipRgn while selecting the original clipping region.."); if (originalRegionType == NativeMethods.RegionFlags.SIMPLEREGION) { // Find the intersection of our clipping region and the current clipping region (our parent's) // Returns a NULLREGION, the two didn't intersect. // Returns a SIMPLEREGION, the two intersected // Resulting region (stuff that was in hOriginalClippingRegion AND hClippingRegion is placed in hClippingRegion NativeMethods.RegionFlags combineResult = (NativeMethods.RegionFlags)SafeNativeMethods.CombineRgn(hClippingRegion, hClippingRegion, hOriginalClippingRegion, NativeMethods.RGN_AND); Debug.Assert((combineResult == NativeMethods.RegionFlags.SIMPLEREGION) || (combineResult == NativeMethods.RegionFlags.NULLREGION), "SIMPLEREGION or NULLREGION expected."); } } else { // If there was no clipping region, then the result is a simple region. // We don't need to keep track of the original now, since it is empty. SafeNativeMethods.DeleteObject(hOriginalClippingRegion); hOriginalClippingRegion = new HandleRef(null, IntPtr.Zero); originalRegionType = NativeMethods.RegionFlags.SIMPLEREGION; } // Select the new clipping region; make sure it's a SIMPLEREGION or NULLREGION NativeMethods.RegionFlags selectResult = (NativeMethods.RegionFlags)SafeNativeMethods.SelectClipRgn(hDC, hClippingRegion); Debug.Assert((selectResult == NativeMethods.RegionFlags.SIMPLEREGION || selectResult == NativeMethods.RegionFlags.NULLREGION), "SIMPLEREGION or NULLLREGION expected."); } catch (Exception ex) { if (ClientUtils.IsSecurityOrCriticalException(ex)) { throw; } this.dc.RestoreHdc(); this.dc.Dispose(); } finally { // Delete the new clipping region, as the clipping region for the HDC is now set // to this rectangle. Hold on to hOriginalClippingRegion, as we'll need to restore // it when this object is disposed. success = SafeNativeMethods.DeleteObject(hClippingRegion); Debug.Assert(success, "DeleteObject(hClippingRegion) failed."); if (hOriginalClippingRegion.Handle != IntPtr.Zero) { success = SafeNativeMethods.DeleteObject(hOriginalClippingRegion); Debug.Assert(success, "DeleteObject(hOriginalClippingRegion) failed."); } } }
/// Translates a point from one control's coordinate system to the other /// same as: /// controlTo.PointToClient(controlFrom.PointToScreen(point)) /// but slightly more performant. public static Point TranslatePoint(Point point, Control fromControl, Control toControl) { NativeMethods.POINT pt = new NativeMethods.POINT(point.X, point.Y); UnsafeNativeMethods.MapWindowPoints(new HandleRef(fromControl, fromControl.Handle), new HandleRef(toControl, toControl.Handle), pt, 1); return new Point(pt.x, pt.y); }
internal Rectangle AccessibilityGetGridEntryBounds(GridEntry gridEntry) { int row = GetRowFromGridEntry(gridEntry); if (row == -1) { return new Rectangle(0, 0, 0, 0); } Rectangle rect = GetRectangle(row, ROWVALUE | ROWLABEL); // Translate rect to screen coordinates // NativeMethods.POINT pt = new NativeMethods.POINT(rect.X, rect.Y); UnsafeNativeMethods.ClientToScreen(new HandleRef(this, Handle), pt); return new Rectangle(pt.x, pt.y, rect.Width, rect.Height); }
public static extern int ClientToScreen(HandleRef hWnd, [In][Out] NativeMethods.POINT pt);
protected override void OnPaint(PaintEventArgs e) { var outerBounds = new Rectangle(0, 0, Width, Height); using (var target = new Bitmap(outerBounds.Width, outerBounds.Height, PixelFormat.Format32bppArgb)) { using (var targetGraphics = Graphics.FromImage(target)) { // The top and bottom borders extend over the sides of the window. // The left and right borders do no. This means that we need to // update the bounds to make it seem like the left and right // borders do extend outside of the window. if (Border == DropShadowBorder.Left || Border == DropShadowBorder.Right) { outerBounds = new Rectangle( outerBounds.Left, outerBounds.Top - _borderWidth, outerBounds.Width, outerBounds.Height + _borderWidth * 2 ); } if (Border == DropShadowBorder.Left || Border == DropShadowBorder.Top) { DrawImage( targetGraphics, _imageCache.CornerNW, new Point( outerBounds.Left, outerBounds.Top ) ); } if (Border == DropShadowBorder.Right || Border == DropShadowBorder.Top) { DrawImage( targetGraphics, _imageCache.CornerNE, new Point( outerBounds.Right - _cornerSize, outerBounds.Top ) ); } if (Border == DropShadowBorder.Bottom || Border == DropShadowBorder.Left) { DrawImage( targetGraphics, _imageCache.CornerSW, new Point( outerBounds.Left, outerBounds.Bottom - _cornerSize ) ); } if (Border == DropShadowBorder.Bottom || Border == DropShadowBorder.Right) { DrawImage( targetGraphics, _imageCache.CornerSE, new Point( outerBounds.Right - _cornerSize, outerBounds.Bottom - _cornerSize ) ); } if (Border == DropShadowBorder.Top) { DrawBorder( targetGraphics, _imageCache.BorderN, new Rectangle( outerBounds.Left + _cornerSize, outerBounds.Top, outerBounds.Width - _cornerSize * 2, _borderWidth ) ); } if (Border == DropShadowBorder.Bottom) { DrawBorder( targetGraphics, _imageCache.BorderS, new Rectangle( outerBounds.Left + _cornerSize, outerBounds.Bottom - _borderWidth, outerBounds.Width - _cornerSize * 2, _borderWidth ) ); } if (Border == DropShadowBorder.Left) { DrawBorder( targetGraphics, _imageCache.BorderW, new Rectangle( outerBounds.Left, outerBounds.Top + _cornerSize, _borderWidth, outerBounds.Height - _cornerSize * 2 ) ); } if (Border == DropShadowBorder.Right) { DrawBorder( targetGraphics, _imageCache.BorderE, new Rectangle( outerBounds.Right - _borderWidth, outerBounds.Top + _cornerSize, _borderWidth, outerBounds.Height - _cornerSize * 2 ) ); } } // Get device contexts var screenDc = NativeMethods.GetDC(IntPtr.Zero); var memDc = NativeMethods.CreateCompatibleDC(screenDc); var hBitmap = IntPtr.Zero; var hOldBitmap = IntPtr.Zero; try { // Get handle to the new bitmap and select it into the current device context hBitmap = target.GetHbitmap(Color.FromArgb(0)); hOldBitmap = NativeMethods.SelectObject(memDc, hBitmap); // Set parameters for layered window update var newSize = new NativeMethods.SIZE(target.Size); // Size window to match bitmap var sourceLocation = new NativeMethods.POINT(Point.Empty); var newLocation = new NativeMethods.POINT(Location); // Same as this window var blend = new NativeMethods.BLENDFUNCTION { BlendOp = NativeMethods.AC_SRC_OVER, // Only works with a 32bpp bitmap BlendFlags = 0, // Always 0 SourceConstantAlpha = 255, // Set to 255 for per-pixel alpha values AlphaFormat = NativeMethods.AC_SRC_ALPHA // Only works when the bitmap contains an alpha channel }; // Update the window NativeMethods.UpdateLayeredWindow( Handle, screenDc, ref newLocation, ref newSize, memDc, ref sourceLocation, 0, ref blend, NativeMethods.ULW_ALPHA ); } finally { // Release device context NativeMethods.ReleaseDC(IntPtr.Zero, screenDc); if (hBitmap != IntPtr.Zero) { NativeMethods.SelectObject(memDc, hOldBitmap); NativeMethods.DeleteObject(hBitmap); // Remove bitmap resources } NativeMethods.DeleteDC(memDc); } } }
internal void SetItemPosition(int index, int x, int y) { if (VirtualMode) return; if (index < 0 || index >= itemCount) throw new ArgumentOutOfRangeException("index", SR.GetString(SR.InvalidArgument, "index", (index).ToString(CultureInfo.CurrentCulture))); Debug.Assert(IsHandleCreated, "How did we add items without a handle?"); NativeMethods.POINT pt = new NativeMethods.POINT(); pt.x = x; pt.y = y; UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), NativeMethods.LVM_SETITEMPOSITION32, index, pt); }
/// <include file='doc\RichTextBox.uex' path='docs/doc[@for="RichTextBox.GetPositionFromCharIndex"]/*' /> /// <devdoc> /// Returns the location of the character at the given index. /// </devdoc> public override Point GetPositionFromCharIndex(int index) { if (richEditMajorVersion == 2) { return base.GetPositionFromCharIndex(index); } if (index < 0 || index > Text.Length) { return Point.Empty; } NativeMethods.POINT pt = new NativeMethods.POINT(); UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), NativeMethods.EM_POSFROMCHAR, pt, index); return new Point(pt.x, pt.y); }
Point CalcMousePosition(OverlayLayeredWindow window) { NativeMethods.POINT point = new NativeMethods.POINT(Control.MousePosition); NativeAPI.ScreenToClient(window.Handle, ref point); return(point.ToPoint()); }
/// <include file='doc\RichTextBox.uex' path='docs/doc[@for="RichTextBox.GetCharIndexFromPosition"]/*' /> /// <devdoc> /// Returns the index of the character nearest to the given point. /// </devdoc> public override int GetCharIndexFromPosition(Point pt) { NativeMethods.POINT wpt = new NativeMethods.POINT(pt.X, pt.Y); int index = (int)UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), NativeMethods.EM_CHARFROMPOS, 0, wpt); string t = this.Text; // EM_CHARFROMPOS will return an invalid number if the last character in the RichEdit // is a newline. // if (index >= t.Length) { index = Math.Max(t.Length - 1, 0); } return index; }
public static extern int MapWindowPoints(NativeMethods.HWND hWndFrom, NativeMethods.HWND hWndTo, [In, Out] ref NativeMethods.POINT pt, int cPoints);
private IntPtr LowLevelMouseProc(int nCode, IntPtr wParam, IntPtr lParam) { if (AllowOneClick) { if ((int)wParam == NativeMethods.WM_LBUTTONDOWN || (int)wParam == NativeMethods.WM_RBUTTONDOWN || (int)wParam == NativeMethods.WM_MBUTTONDOWN) { return(NativeMethods.CallNextHookEx(IntPtr.Zero, nCode, wParam, lParam)); } if ((int)wParam == NativeMethods.WM_LBUTTONUP || (int)wParam == NativeMethods.WM_RBUTTONUP || (int)wParam == NativeMethods.WM_MBUTTONUP) { AllowOneClick = false; return(NativeMethods.CallNextHookEx(IntPtr.Zero, nCode, wParam, lParam)); } } if (currentprocessid == 0) { currentprocessid = System.Diagnostics.Process.GetCurrentProcess().Id; } if (nCode >= NativeMethods.HC_ACTION) { var e = new InputEventArgs(); var pt = new NativeMethods.POINT(); NativeMethods.GetPhysicalCursorPos(ref pt); e.X = pt.x; e.Y = pt.y; e.AltKey = NativeMethods.HIBYTE(NativeMethods.GetKeyState(NativeMethods.VK_LMENU) | NativeMethods.GetKeyState(NativeMethods.VK_RMENU)) != 0; e.CtrlKey = NativeMethods.HIBYTE(NativeMethods.GetKeyState(NativeMethods.VK_LCONTROL) | NativeMethods.GetKeyState(NativeMethods.VK_RCONTROL)) != 0; e.ShiftKey = NativeMethods.HIBYTE(NativeMethods.GetKeyState(NativeMethods.VK_LSHIFT) | NativeMethods.GetKeyState(NativeMethods.VK_RSHIFT)) != 0; e.WinKey = NativeMethods.HIBYTE(NativeMethods.GetKeyState(NativeMethods.VK_LWIN) | NativeMethods.GetKeyState(NativeMethods.VK_RWIN)) != 0; switch ((int)wParam) { case NativeMethods.WM_LBUTTONUP: e.Type = InputEventType.MouseUp; e.Button = MouseButton.Left; if (!AllowOneClick) { RaiseOnMouseUp(e); } //OnInput(e); break; case NativeMethods.WM_RBUTTONUP: e.Type = InputEventType.MouseUp; e.Button = MouseButton.Right; if (!AllowOneClick) { RaiseOnMouseUp(e); } //OnInput(e); break; case NativeMethods.WM_MBUTTONUP: e.Type = InputEventType.MouseUp; e.Button = MouseButton.Middle; if (!AllowOneClick) { RaiseOnMouseUp(e); } //OnInput(e); break; case NativeMethods.WM_LBUTTONDOWN: e.Type = InputEventType.MouseDown; e.Button = MouseButton.Left; if (!AllowOneClick) { RaiseOnMouseDown(e); } //OnInput(e); break; case NativeMethods.WM_RBUTTONDOWN: e.Type = InputEventType.MouseDown; e.Button = MouseButton.Right; if (!AllowOneClick) { RaiseOnMouseDown(e); } //OnInput(e); break; case NativeMethods.WM_MBUTTONDOWN: e.Type = InputEventType.MouseDown; e.Button = MouseButton.Middle; if (!AllowOneClick) { RaiseOnMouseDown(e); } //OnInput(e); break; case NativeMethods.WM_MOUSEMOVE: e.Type = InputEventType.MouseMove; if (!AllowOneClick) { RaiseOnMouseMove(e); } //OnInput(e); break; } if (CallNext || (int)wParam == NativeMethods.WM_MOUSEMOVE || (int)wParam == NativeMethods.WM_MouseWheel) { // if((int)wParam != WM_MOUSEMOVE) Log.Debug("CallNextHookEx: " + CallNext); return(NativeMethods.CallNextHookEx(IntPtr.Zero, nCode, wParam, lParam)); } try { if (e.Element != null && e.Element.ProcessId == currentprocessid) { // if ((int)wParam != WM_MOUSEMOVE) Log.Debug("CallNextHookEx: " + CallNext); return(NativeMethods.CallNextHookEx(IntPtr.Zero, nCode, wParam, lParam)); } } catch (Exception ex) { Log.Error(ex, ""); return(NativeMethods.CallNextHookEx(IntPtr.Zero, nCode, wParam, lParam)); } // if ((int)wParam != WM_MOUSEMOVE) Log.Debug("Skip CallNextHookEx: " + CallNext); return((IntPtr)1); } else { return(NativeMethods.CallNextHookEx(IntPtr.Zero, nCode, wParam, lParam)); } }
public static extern int ScreenToClient(HandleRef hWnd, [In, Out] NativeMethods.POINT pt);
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; }
public void OnNewContact(IntPtr windowHandle, Multitouch.Contracts.IContact contact) { Window window = GetWindow(windowHandle); if (window != null) { window.Contacts.Add(new WindowContact(contact)); Body body; if (windowToBody.TryGetValue(window, out body)) { NativeMethods.POINT point = new NativeMethods.POINT((int)contact.X, (int)contact.Y); Vector2D contactPoint = point.ToVector2D(); if (body.Shape.CanGetIntersection) { Vector2D temp = body.Matrices.ToBody * contactPoint; IntersectionInfo intersectionInfo; if (body.Shape.TryGetIntersection(temp, out intersectionInfo)) { FixedHingeJoint joint = new FixedHingeJoint(body, contactPoint, new Lifespan()); engine.AddJoint(joint); contactJoints[contact.Id] = joint; } } } } }
private bool ShouldForwardChildMouseMessage(Control child, MouseEventArgs me, ref Point pt) { Size size = child.Size; // are we within two pixels of the edge? if (me.Y <= 1 || (size.Height - me.Y) <= 1) { // convert the coordinates to NativeMethods.POINT temp = new NativeMethods.POINT(); temp.x = me.X; temp.y = me.Y; UnsafeNativeMethods.MapWindowPoints(new HandleRef(child, child.Handle), new HandleRef(this, Handle), temp, 1); // forward the message pt.X = temp.x; pt.Y = temp.y; return true; } return false; }
/// <summary> /// Preforms basic syntax highlighting on the current script. /// </summary> /// <param name="full">If true the whole script will be highlighted, if false only the locally modified line will be.</param> public void Highlight(bool full) { if (_requireHighlighting == false) return; // Check we are not already highlighting if (_highlighting == true) return; int startIndex = 0; string text = scriptRichTextBox.Text; int finishIndex = text.Length; // If we are highlighting local changes then work out where to do it from. if (full == false) { startIndex = scriptRichTextBox.GetFirstCharIndexOfCurrentLine(); if (startIndex < 0) return; int line = scriptRichTextBox.GetLineFromCharIndex(startIndex); if (line >= scriptRichTextBox.Lines.Length) return; finishIndex = startIndex + scriptRichTextBox.Lines[line].Length; } // Store the scroll position for later. NativeMethods.POINT scrollPosition = new NativeMethods.POINT(); NativeMethods.SendMessage(new HandleRef(scriptRichTextBox, scriptRichTextBox.Handle), (int)NativeMethods.Win32Messages.EM_GETSCROLLPOS, 0, ref scrollPosition); // Store the original selection position and length. int selectionIndex = scriptRichTextBox.SelectionStart; int selectionLength = scriptRichTextBox.SelectionLength; int processStartIndex = 0; // Lock the script rich text box. NativeMethods.LockWindowUpdate((int)scriptRichTextBox.Handle); // Blank out the current selection. scriptRichTextBox.Select(startIndex, finishIndex - startIndex); scriptRichTextBox.SelectionColor = _normalColor; scriptRichTextBox.SelectionFont = _normalFont; // Check if the current text is inside a block comment, if // it is recolor the block. if (full == false) { string previousSub = (selectionIndex <= _previousText.Length - 2 && selectionIndex >= 2) ? _previousText.Substring(selectionIndex - 1, 2) : ""; int blockStartIndex = text.LastIndexOf("/*", selectionIndex); if (blockStartIndex > -1) { int blockStartEndIndex = text.IndexOf("*/", blockStartIndex); int blockEndIndex = text.IndexOf("*/", selectionIndex); if (blockStartEndIndex > 0 && blockEndIndex > 0 && blockStartEndIndex >= blockEndIndex) { scriptRichTextBox.Select(blockStartIndex, (blockEndIndex - blockStartIndex) + 2); scriptRichTextBox.SelectionColor = _commentColor; scriptRichTextBox.SelectionFont = _commentFont; // As we are highlighting a block comment we don't want // to highlight this selection normally. startIndex = finishIndex = -1; } } } // Go through the characters we are highlighting and highlight them. _highlighting = true; for (int charIndex = startIndex; charIndex < finishIndex; charIndex++) { // See if there is a single line comment at this position. if (charIndex < text.Length - 1 && text[charIndex] == '/' && text[charIndex + 1] == '/') { processStartIndex = charIndex; while (charIndex < finishIndex) { if (text[charIndex] == '\n') break; charIndex++; } scriptRichTextBox.Select(processStartIndex, charIndex - processStartIndex); scriptRichTextBox.SelectionColor = _commentColor; scriptRichTextBox.SelectionFont = _commentFont; } // See if there is a block comment start at this position. else if (full == true && charIndex < finishIndex - 1 && text[charIndex] == '/' && scriptRichTextBox.Text[charIndex + 1] == '*') { processStartIndex = charIndex; charIndex += 2; int depth = 1; while (charIndex < text.Length - 1) { if (text[charIndex] == '*' && text[charIndex + 1] == '/') { depth--; if (depth == 0) { charIndex += 2; break; } } else if (text[charIndex] == '/' && text[charIndex + 1] == '*') { depth++; } charIndex++; } scriptRichTextBox.Select(processStartIndex, charIndex - processStartIndex); scriptRichTextBox.SelectionColor = _commentColor; scriptRichTextBox.SelectionFont = _commentFont; } // See if there is a preprocessor line at this position. else if (text[charIndex] == '#') { processStartIndex = charIndex; while (charIndex < finishIndex) { if (text[charIndex] == '\n') break; charIndex++; } scriptRichTextBox.Select(processStartIndex, charIndex - processStartIndex); scriptRichTextBox.SelectionColor = _directiveColor; scriptRichTextBox.SelectionFont = _directiveFont; } // See if there is a string value next. else if (text[charIndex] == '\"') { processStartIndex = charIndex++; while (charIndex < finishIndex) { if (text[charIndex] == '\"' || text[charIndex] == '\n') { charIndex++; break; } charIndex++; } scriptRichTextBox.Select(processStartIndex, charIndex - processStartIndex); scriptRichTextBox.SelectionColor = _stringColor; scriptRichTextBox.SelectionFont = _stringFont; } // See if there is a numeric value next. else if (text[charIndex] >= '0' && text[charIndex] <= '9') { processStartIndex = charIndex; while (charIndex < finishIndex) { if ((text[charIndex] < '0' || text[charIndex] > '9') && text[charIndex] != '.') { scriptRichTextBox.Select(processStartIndex, charIndex - processStartIndex); scriptRichTextBox.SelectionColor = _numberColor; scriptRichTextBox.SelectionFont = _numberFont; charIndex--; break; } charIndex++; } } // See if there is a identifier next. else if ((text[charIndex] >= 'a' && text[charIndex] <= 'z') || (text[charIndex] >= 'A' && text[charIndex] <= 'Z') || text[charIndex] == '_') { processStartIndex = charIndex; while (charIndex < finishIndex) { if (!((text[charIndex] >= 'a' && text[charIndex] <= 'z') || (text[charIndex] >= 'A' && text[charIndex] <= 'Z') || (text[charIndex] >= '0' && text[charIndex] <= '9') || text[charIndex] == '_')) { charIndex--; break; } charIndex++; } if (processStartIndex + (charIndex - processStartIndex + 1) >= text.Length) continue; string keywordText = text.Substring(processStartIndex, charIndex - processStartIndex + 1).ToLower(); bool isKeyword = false; foreach (string keyword in _keywords) if (keywordText == keyword) { isKeyword = true; break; } if (isKeyword == true) { scriptRichTextBox.Select(processStartIndex, charIndex - processStartIndex + 1); scriptRichTextBox.SelectionColor = _keywordColor; scriptRichTextBox.SelectionFont = _keywordFont; } } } _highlighting = false; // Restore the original selection. scriptRichTextBox.SelectionStart = selectionIndex; scriptRichTextBox.SelectionLength = selectionLength; // Restore the scrool bar position NativeMethods.SendMessage(new HandleRef(scriptRichTextBox, scriptRichTextBox.Handle), (int)NativeMethods.Win32Messages.EM_SETSCROLLPOS, 0, ref scrollPosition); // Unlock the script rich text box. NativeMethods.LockWindowUpdate(0); // Save the previous text. _previousText = text; }
internal Point GetItemPosition(int index) { NativeMethods.POINT pt = new NativeMethods.POINT(); UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), NativeMethods.LVM_GETITEMPOSITION, index, pt); return new Point(pt.x, pt.y); }
private void PaintNative(Bitmap bitmap, byte opacity) { Debug.WriteLine("PaintNative"); IntPtr hdcDestination = NativeMethods.GetDC(IntPtr.Zero); IntPtr hdcSource = NativeMethods.CreateCompatibleDC(hdcDestination); IntPtr hdcBitmap = IntPtr.Zero; IntPtr previousBitmap = IntPtr.Zero; try { hdcBitmap = bitmap.GetHbitmap(Color.FromArgb(0)); previousBitmap = NativeMethods.SelectObject(hdcSource, hdcBitmap); NativeMethods.SIZE size = new NativeMethods.SIZE(bitmap.Width, bitmap.Height); NativeMethods.POINT source = new NativeMethods.POINT(0, 0); NativeMethods.POINT destination = new NativeMethods.POINT(Left, Top); NativeMethods.BLENDFUNCTION blend = new NativeMethods.BLENDFUNCTION(); blend.BlendOp = NativeMethods.AC_SRC_OVER; blend.BlendFlags = 0; blend.SourceConstantAlpha = opacity; blend.AlphaFormat = NativeMethods.AC_SRC_ALPHA; NativeMethods.UpdateLayeredWindow( Handle, hdcDestination, ref destination, ref size, hdcSource, ref source, 0, ref blend, 2); } catch (Exception) { return; } finally { NativeMethods.ReleaseDC(IntPtr.Zero, hdcDestination); if (hdcBitmap != IntPtr.Zero) { NativeMethods.SelectObject(hdcSource, previousBitmap); NativeMethods.DeleteObject(hdcBitmap); } NativeMethods.DeleteDC(hdcSource); } }
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; }
/// <include file='doc\PropertyGridView.uex' path='docs/doc[@for="PropertyGridView.PropertyGridViewAccessibleObject.HitTest"]/*' /> /// <devdoc> /// Get the accessible child at the given screen location. /// The accessible children of a PropertyGridView are accessible objects /// corresponding to the property grid entries. /// </devdoc> public override AccessibleObject HitTest(int x, int y) { // Convert to client coordinates // NativeMethods.POINT pt = new NativeMethods.POINT(x, y); UnsafeNativeMethods.ScreenToClient(new HandleRef(Owner, Owner.Handle), pt); // Find the grid entry at the given client coordinates // Point pos = ((PropertyGridView)Owner).FindPosition(pt.x, pt.y); if (pos != PropertyGridView.InvalidPosition) { GridEntry gridEntry = ((PropertyGridView)Owner).GetGridEntryFromRow(pos.Y); if (gridEntry != null) { // Return the accessible object for this grid entry // return gridEntry.AccessibilityObject; } } // No grid entry at this point // return null; }
private int HitTest(Point point) { NativeMethods.POINT pt = new NativeMethods.POINT(); pt.x = point.X; pt.y = point.Y; int hit = NativeMethods.SendMessage(Handle, NativeMethods.TB_HITTEST, 0, ref pt); if (hit > 0) { point = this.PointToScreen(point); Rectangle bounds = this.RectangleToScreen(new Rectangle(0, 0, Width, Height)); if (!bounds.Contains(point)) { return -1; } } return hit; }
/// <summary> /// Renders a page of the PDF document to the provided graphics instance. /// </summary> /// <param name="page">Number of the page to render.</param> /// <param name="graphics">Graphics instance to render the page on.</param> /// <param name="dpiX">Horizontal DPI.</param> /// <param name="dpiY">Vertical DPI.</param> /// <param name="bounds">Bounds to render the page in.</param> /// <param name="flags">Flags used to influence the rendering.</param> public void Render(int page, Graphics graphics, float dpiX, float dpiY, Rectangle bounds, PdfRenderFlags flags) { if (graphics == null) throw new ArgumentNullException("graphics"); if (_disposed) throw new ObjectDisposedException(GetType().Name); float graphicsDpiX = graphics.DpiX; float graphicsDpiY = graphics.DpiY; var dc = graphics.GetHdc(); try { if ((int)graphicsDpiX != (int)dpiX || (int)graphicsDpiY != (int)dpiY) { var transform = new NativeMethods.XFORM { eM11 = graphicsDpiX / dpiX, eM22 = graphicsDpiY / dpiY }; NativeMethods.SetGraphicsMode(dc, NativeMethods.GM_ADVANCED); NativeMethods.ModifyWorldTransform(dc, ref transform, NativeMethods.MWT_LEFTMULTIPLY); } var point = new NativeMethods.POINT(); NativeMethods.SetViewportOrgEx(dc, bounds.X, bounds.Y, out point); bool success = _file.RenderPDFPageToDC( page, dc, (int)dpiX, (int)dpiY, 0, 0, bounds.Width, bounds.Height, FlagsToFPDFFlags(flags) ); NativeMethods.SetViewportOrgEx(dc, point.X, point.Y, out point); if (!success) throw new Win32Exception(); } finally { graphics.ReleaseHdc(dc); } }