public static void ShowContextMenu(ContextMenuStrip contextMenu, DTE dte) { try { var serviceProvider = new ServiceProvider(dte as IServiceProvider); IVsUIShellOpenDocument sod = (IVsUIShellOpenDocument)serviceProvider.GetService(typeof(SVsUIShellOpenDocument)); IVsUIHierarchy targetHier; uint[] targetId = new uint[1]; IVsWindowFrame targetFrame; int isOpen; Guid viewId = new Guid(LogicalViewID.Primary); sod.IsDocumentOpen(null, 0, dte.ActiveWindow.Document.FullName, ref viewId, 0, out targetHier, targetId, out targetFrame, out isOpen); IVsTextView textView = VsShellUtilities.GetTextView(targetFrame); TextSelection selection = (TextSelection)dte.ActiveWindow.Document.Selection; Microsoft.VisualStudio.OLE.Interop.POINT[] interopPoint = new Microsoft.VisualStudio.OLE.Interop.POINT[1]; textView.GetPointOfLineColumn(selection.ActivePoint.Line, selection.ActivePoint.LineCharOffset, interopPoint); POINT p = new POINT(interopPoint[0].x, interopPoint[0].y); ClientToScreen(textView.GetWindowHandle(), p); contextMenu.Show(new Point(p.x, p.y)); } catch (Exception) { contextMenu.Show(); } }
//should I only make automationElement and actionListener once? public static UIItem GetControl(Point point) { POINT point1 = new POINT(point.X, point.Y); IntPtr myIntPtr = WindowFromPoint(point1); AutomationElement automationElement = AutomationElement.FromHandle(myIntPtr); automationElement = GetChildControl(point, automationElement) ?? automationElement; TreeWalker walker = TreeWalker.ControlViewWalker; AutomationElement parentElement = walker.GetParent(automationElement); if (parentElement != null && parentElement.Current.LocalizedControlType == "button") automationElement = parentElement; int delNum; while(((string.IsNullOrEmpty(automationElement.Current.Name) && string.IsNullOrEmpty(automationElement.Current.AutomationId)) || int.TryParse(automationElement.Current.AutomationId, out delNum))) { automationElement = walker.GetParent(automationElement); } ActionListener actionListener = new NullActionListener(); return new UIItem(automationElement, actionListener); }
public SnapperWindow(int x, int y, int width, int height) : base("Snap N Share", 10, 10, 640, 480) { // Show a form so we can capture the desired group IP and port number ServerForm groupForm = new ServerForm(); //IPAddress randomAddress = NewTOAPIA.Net.Utility.GetRandomMulticastAddress(); //groupForm.groupAddressField.Text = randomAddress.ToString(); groupForm.ShowDialog(); // Get the address and port from the form fUseGray = groupForm.checkBox1.Checked; string groupIP = groupForm.groupAddressField.Text; int groupPort = int.Parse(groupForm.groupPortField.Text); IPEndPoint ipep = new IPEndPoint(IPAddress.Parse(groupIP), groupPort); // Set our title to the address specified so the user // can easily identify their session. Title = "SnapNShare - " + ipep.ToString(); fSnapper = new ScreenSnapper(); fClientOrigin = new POINT(); int pwidth = ClientRectangle.Width; int pheight = ClientRectangle.Height; fScreenImage = new GDIDIBSection(width, height, BitCount.Bits24); fGrayImage = new PixelArray<Lumb>(width, height,fScreenImage.Orientation, new Lumb()); BackgroundColor = RGBColor.White; this.Opacity = 0.5; // Create the MultiSession object so we can send stuff out to a group //fSession = new MultiSession(Guid.NewGuid().ToString(), ipep); fSession = new MultiSession(ipep, Guid.NewGuid().ToString(), "William", true, true, null); // Add the channel for graphics commands PayloadChannel payloadChannel = fSession.CreateChannel(PayloadType.dynamicPresentation); fCommandDispatcher = new GraphPortChunkEncoder(payloadChannel); fUserIOChannel = fSession.CreateChannel(PayloadType.xApplication2); //fUserIOEncoder = new UserIOChannelEncoder(fUserIOChannel); //fUserIODecoder = new UserIOChannelDecoder(fUserIOChannel); //fUserIODecoder.MouseActivityEvent += new MouseActivityEventHandler(fUserIODecoder_MouseActivityEvent); //fUserIODecoder.KeyboardActivityEvent += new KeyboardActivityEventHandler(fUserIODecoder_KeyboardActivityEvent); // Start the thread that will take snapshots of the screen fGlobalTimer = new PrecisionTimer(); fFrameRate = 2; // Frames per second fSnapperRunning = true; snapperThread = new Thread(RunSnaps); snapperThread.Start(); }
public SnapperWindow(int x, int y, int width, int height) : base("Pixel Share", 10, 10, 640, 480) { // Show a form so we can capture the desired group IP and port number ServerForm groupForm = new ServerForm(); //IPAddress randomAddress = NewTOAPIA.Net.Utility.GetRandomMulticastAddress(); //groupForm.groupAddressField.Text = randomAddress.ToString(); groupForm.ShowDialog(); // Get the address and port from the form fUseGray = groupForm.checkBox1.Checked; string groupIP = groupForm.groupAddressField.Text; int groupPort = int.Parse(groupForm.groupPortField.Text); IPEndPoint ipep = new IPEndPoint(IPAddress.Parse(groupIP), groupPort); // Set our title to the address specified so the user // can easily identify their session. Title = "SnapNShare - " + ipep.ToString(); fSnapper = new ScreenSnapper(); fClientOrigin = new POINT(); int pwidth = ClientRectangle.Width; int pheight = ClientRectangle.Height; fScreenImage = new GDIDIBSection(width, height, BitCount.Bits24); fGrayImage = new PixelArray<Lumb>(width, height,fScreenImage.Orientation, new Lumb()); BackgroundColor = RGBColor.White; this.Opacity = 0.5; // Add the channel for graphics commands CommChannel graphicsChannel = new CommChannel(ipep, true, false); fCommandDispatcher = new GraphPortChunkEncoder(graphicsChannel); // Start the thread that will take snapshots of the screen fGlobalTimer = new PrecisionTimer(); fFrameRate = 2; // Frames per second fSnapperRunning = true; snapperThread = new Thread(RunSnaps); snapperThread.Start(); }
static extern IntPtr SendMessage(IntPtr hWnd, int wMsg, out POINT wParam, IntPtr lParam);
protected override void WndProc(ref Message m) { switch (m.Msg) { case WM_MOUSEWHEEL: if (m_SmoothScroll) break; int delta = ((int)m.WParam >> 16) / 120; IntPtr msg = delta < 0 ? (IntPtr)SB_LINEDOWN : (IntPtr)SB_LINEUP; if (delta < 0) delta = -delta; for (int i = 0; i < delta; ++i) SendMessage(m.HWnd, WM_VSCROLL, msg, IntPtr.Zero); m.Result = IntPtr.Zero; return; case WM_PAINT: if (VerticalScrollPosChanged != null) { // Handling the VScroll event wasn't enough: When the user scrolls the scrollbar by grabbing the thumb of the // scrollbar then if you hold the thumb in one position for 1-2 seconds then the text is automatically scrolled // to a whole line vertically without sending any events. We have to know about every single Y scroll pos change // in order to correctly redraw the line number control. POINT scroll_pos = new POINT(); SendMessage(Handle, EM_GETSCROLLPOS, IntPtr.Zero, ref scroll_pos); if (scroll_pos.Y != m_PrevScrollPos.Y) { m_PrevScrollPos = scroll_pos; VerticalScrollPosChanged(this); } } if (PostPaint == null) break; // HACK: couldn't get it work otherwise... Invalidate(); base.WndProc(ref m); using (Graphics g = CreateGraphics()) PostPaint(this, g); return; } base.WndProc(ref m); }
static extern bool ScreenToClient(IntPtr hWnd, ref POINT lpPoint);
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, POINT lParam);
internal extern static bool Win32MoveToEx(IntPtr hdc, int x, int y, ref POINT lpPoint);
private extern static bool Win32ClientToScreen(IntPtr hWnd, ref POINT pt);
internal override void DrawReversibleRectangle(IntPtr handle, Rectangle rect, int line_width) { IntPtr hdc; IntPtr pen; IntPtr oldpen; POINT pt; pt = new POINT(); pt.x = 0; pt.y = 0; Win32ClientToScreen(handle, ref pt); // If we want the standard hatch pattern we would // need to create a brush // Grab a pen pen = Win32CreatePen(PenStyle.PS_SOLID, line_width, IntPtr.Zero); hdc = Win32GetDC(IntPtr.Zero); Win32SetROP2(hdc, ROP2DrawMode.R2_NOT); oldpen = Win32SelectObject(hdc, pen); Control c = Control.FromHandle (handle); if (c != null) { RECT window_rect; Win32GetWindowRect (c.Handle, out window_rect); Region r = new Region (new Rectangle(window_rect.left, window_rect.top, window_rect.right - window_rect.left, window_rect.bottom - window_rect.top)); Win32ExtSelectClipRgn(hdc, r.GetHrgn (Graphics.FromHdc (hdc)), (int) ClipCombineMode.RGN_AND); } Win32MoveToEx(hdc, pt.x + rect.Left, pt.y + rect.Top, IntPtr.Zero); if ((rect.Width > 0) && (rect.Height > 0)) { Win32LineTo(hdc, pt.x + rect.Right, pt.y + rect.Top); Win32LineTo(hdc, pt.x + rect.Right, pt.y + rect.Bottom); Win32LineTo(hdc, pt.x + rect.Left, pt.y + rect.Bottom); Win32LineTo(hdc, pt.x + rect.Left, pt.y + rect.Top); } else { if (rect.Width > 0) { Win32LineTo(hdc, pt.x + rect.Right, pt.y + rect.Top); } else { Win32LineTo(hdc, pt.x + rect.Left, pt.y + rect.Bottom); } } Win32SelectObject(hdc, oldpen); Win32DeleteObject(pen); if (c != null) Win32ExtSelectClipRgn(hdc, IntPtr.Zero, (int) ClipCombineMode.RGN_COPY); Win32ReleaseDC(IntPtr.Zero, hdc); }
private static extern bool GetCursorPos(out POINT lpPoint);
//IntPtr fUserIODecoder_KeyboardActivityEvent(object sender, KeyboardActivityArgs ke) //{ // if (!fAllowRemoteControl) // return IntPtr.Zero; // Console.WriteLine("Received Key Event: {0} {1} {2}", InputSimulator.KeyEvents, ke.AcitivityType, ke.VirtualKeyCode); // InputSimulator.SimulateKeyboardActivity(ke.VirtualKeyCode, ke.AcitivityType); // return IntPtr.Zero; //} //void fUserIODecoder_MouseActivityEvent(object sender, MouseActivityArgs me) //{ // if (fAllowRemoteControl) // { // // What we've received are window relative coordinates. // // First we need to convert them to screen relative coordinates // POINT aPoint = new POINT(me.X, me.Y); // User32.ClientToScreen(Handle, ref aPoint); // // Now for input simulation, we need to turn the screen // // point into a normalized range of 0 to 65535 // // Normalize the point // Screen myScreen = Screen.FromHandle(Handle); // Rectangle screenRect = myScreen.Bounds; // float xFrac = (float)aPoint.X / screenRect.Width; // float yFrac = (float)aPoint.Y / screenRect.Height; // int normalizedX = (int)(xFrac * 65535); // int normalizedY = (int)(yFrac * 65535); // // And finally, send the input // InputSimulator.SimulateMouseActivity(normalizedX, normalizedY, me.Delta, me.ButtonActivity); // } //} #endregion void SnapClientArea() { Rectangle cRect = ClientRectangle; // If we have resized since last picture, then // resize the capture buffer before taking // the next snapshot. if (fNeedsResize) { fScreenImage = new GDIDIBSection(cRect.Width, cRect.Height, BitCount.Bits24); fGrayImage = new PixelArray<Lumb>(cRect.Width, cRect.Height, fScreenImage.Orientation, new Lumb()); fNeedsResize = false; } // To take a snapshot, we need to convert the client area's upper left corner // to screen space, as the device context we're using is for the whole screen. // So, we get the origin, and make the User32 call to convert that to screen space. fClientOrigin = new POINT(0, 0); User32.ClientToScreen(Handle, ref fClientOrigin); // Now we actually take the snapshot. // We pass in the client area, based in screen coordinates // and the PixelBuffer object to capture into. fSnapper.SnapAPicture(new Rectangle(fClientOrigin.X, fClientOrigin.Y, fScreenImage.Width, fScreenImage.Height), fScreenImage); }
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, POINT point);
public static extern bool GetCursorPos(out POINT lpPoint);
public static extern bool UpdateLayeredWindow(IntPtr hwnd, IntPtr hdcDst, ref POINT pptDst, ref SIZE psize, IntPtr hdcSrc, ref POINT pptSrc, uint crKey, [In] ref BLENDFUNCTION pblend, uint dwFlags);
internal override void DrawReversibleLine(Point start, Point end, Color backColor) { IntPtr hdc; IntPtr pen; IntPtr oldpen; POINT pt; COLORREF clrRef = new COLORREF(); pt = new POINT(); pt.x = 0; pt.y = 0; Win32ClientToScreen(IntPtr.Zero, ref pt); // If we want the standard hatch pattern we would // need to create a brush clrRef.R = backColor.R; clrRef.G = backColor.G; clrRef.B = backColor.B; // Grab a pen pen = Win32CreatePen(PenStyle.PS_SOLID, 1, ref clrRef); hdc = Win32GetDC(IntPtr.Zero); Win32SetROP2(hdc, ROP2DrawMode.R2_NOT); oldpen = Win32SelectObject(hdc, pen); Win32MoveToEx(hdc, pt.x + start.X, pt.y + start.Y, IntPtr.Zero); Win32LineTo(hdc, pt.x + end.X, pt.y + end.Y); Win32SelectObject(hdc, oldpen); Win32DeleteObject(pen); Win32ReleaseDC(IntPtr.Zero, hdc); }
static extern IntPtr WindowFromPoint(POINT Point);
private extern static bool Win32ScreenToClient(IntPtr hWnd, ref POINT pt);
private extern static int RtlMoveMemory(ref POINT Destination, ref RECT Source, int Length);
private extern static bool Win32GetCursorPos(out POINT lpPoint);
public static extern int GetCursorPos(ref POINT lpPoint);
public void SetIMEWindowLocation(int x, int y) { if (disableIME || hIMEWnd == IntPtr.Zero) return; POINT p = new POINT(); p.x = x; p.y = y; COMPOSITIONFORM lParam = new COMPOSITIONFORM(); lParam.dwStyle = CFS_POINT; lParam.ptCurrentPos = p; lParam.rcArea = new RECT(); try { SendMessage(hIMEWnd, WM_IME_CONTROL, new IntPtr(IMC_SETCOMPOSITIONWINDOW), lParam); } catch (AccessViolationException ex) { Handle(ex); } }
public static extern IntPtr AccessibleObjectFromPoint(POINT pt, [Out, MarshalAs(UnmanagedType.Interface)] out IAccessible accObj, [Out] out object ChildID);
public static extern IntPtr GetCursorPos(out POINT point);
/// <summary> /// 指定の座標にアイコンがないか /// </summary> /// <param name="hwnd"></param> /// <param name="x"></param> /// <param name="y"></param> /// <returns>アイコンがない場合はtrue</returns> private bool IsHitTestNoIcon(IntPtr hwnd, int x, int y) { int pID = 0; IntPtr hProcess = IntPtr.Zero; IntPtr p = IntPtr.Zero; try { POINT pt = new POINT(); pt.x = x; pt.y = y; ScreenToClient(hwnd, ref pt); GetWindowThreadProcessId(hwnd, ref pID); hProcess = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE, false, pID); if (hProcess != IntPtr.Zero) { LVHITTESTINFO lhi = new LVHITTESTINFO(); int dw = 0; lhi.pt = pt; p = VirtualAllocEx(hProcess, IntPtr.Zero, Marshal.SizeOf(lhi), MEM_COMMIT, PAGE_READWRITE); WriteProcessMemory(hProcess, p, ref lhi, Marshal.SizeOf(lhi), ref dw); SendMessage(hwnd, LVM_SUBITEMHITTEST, IntPtr.Zero, p); ReadProcessMemory(hProcess, p, ref lhi, Marshal.SizeOf(lhi), ref dw); return lhi.iItem < 0; } } finally { if (p != IntPtr.Zero) VirtualFreeEx(hProcess, p, 0, MEM_RELEASE); if (hProcess != IntPtr.Zero) CloseHandle(hProcess); } return false; }
public static extern IntPtr WindowFromPoint(POINT point);
static extern IntPtr SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, ref POINT lParam);
internal override void ClientToScreen(IntPtr handle, ref int x, ref int y) { POINT pnt = new POINT(); pnt.x = x; pnt.y = y; Win32ClientToScreen(handle, ref pnt); x = pnt.x; y = pnt.y; }
public static extern bool SetViewportOrgEx(IntPtr hdc, int X, int Y, out POINT lpPoint);
public static extern IntPtr WindowFromPoint(POINT Point);