public static void SuppressSIP() { var hWnd = PInvoke.FindWindow("SIPWndClass", null); if (hWnd == IntPtr.Zero) { return; } var flags = (PInvoke.WindowStyles)PInvoke.GetWindowLong(hWnd, -16 /*GWL_STYLE*/); if ((flags & PInvoke.WindowStyles.WS_VISIBLE) == 0) { return; // not visible } var hWndButton = PInvoke.FindWindow("MS_SIPBUTTON", "MS_SIPBUTTON"); if (hWndButton == IntPtr.Zero) { return; // no button! } PInvoke.SipShowIM(PInvoke.SIPF.SIPF_OFF); //Click(hWndButton, null); flags = (PInvoke.WindowStyles)PInvoke.GetWindowLong(hWnd, -16 /*GWL_STYLE*/); if ((flags & PInvoke.WindowStyles.WS_VISIBLE) != 0) { Console.WriteLine("oops"); } }
private static WinComponent FromHandle(IntPtr hwndCur) { var chArWindowClass = new StringBuilder(257); PInvoke.GetClassName(hwndCur, chArWindowClass, 256); var strWndClass = chArWindowClass.ToString(); var length = PInvoke.GetWindowTextLength(hwndCur); var sb = new StringBuilder(length + 1); PInvoke.GetWindowText(hwndCur, sb, sb.Capacity); PInvoke.RECT rct; PInvoke.GetWindowRect(hwndCur, out rct); var style = PInvoke.GetWindowLong(hwndCur, PInvoke.GWL_STYLE); var res = new WinComponent(strWndClass, sb.ToString(), hwndCur, rct.Left, rct.Top, style); return(res); }
public static void ScrollIntoView(IntPtr hWnd) { PInvoke.RECT rc, rpc; IntPtr hwndParent = PInvoke.GetParent(hWnd); if (hwndParent == IntPtr.Zero) { // no parent, cannot be scrolled return; } // is the parent window vertically or horizontally scrollable? var style = (PInvoke.WindowStyles)PInvoke.GetWindowLong(hwndParent, -16 /*GWL_STYLE*/); var vscroll = (style & PInvoke.WindowStyles.WS_VSCROLL) != 0; var hscroll = (style & PInvoke.WindowStyles.WS_HSCROLL) != 0; ComputeRectRelativeToParent(hWnd, hwndParent, out rpc, out rc); while (hscroll && rc.Left < rpc.Left) { Scroll(hwndParent, 0, 1); // move right ComputeRectRelativeToParent(hWnd, hwndParent, out rpc, out rc); } while (vscroll && rc.Top < rpc.Top) { Scroll(hwndParent, 1, 0); // move up ComputeRectRelativeToParent(hWnd, hwndParent, out rpc, out rc); } while (hscroll && rc.Right > rpc.Right) { Scroll(hwndParent, 0, -1); // move leftP ComputeRectRelativeToParent(hWnd, hwndParent, out rpc, out rc); } while (vscroll && rc.Bottom > rpc.Bottom) { Scroll(hwndParent, -1, 0); // move down ComputeRectRelativeToParent(hWnd, hwndParent, out rpc, out rc); } }
private static void RecurseFindWindow(IntPtr hWndParent, List <WinComponent> childs) { if (hWndParent == IntPtr.Zero) { return; } var pointers = new List <IntPtr>(); IntPtr hwndCur = PInvoke.GetWindow(hWndParent, (uint)PInvoke.GetWindowFlags.GW_HWNDFIRST); do { pointers.Add(hwndCur); var chArWindowClass = new StringBuilder(257); PInvoke.GetClassName(hwndCur, chArWindowClass, 256); var strWndClass = chArWindowClass.ToString(); var length = PInvoke.GetWindowTextLength(hwndCur); var sb = new StringBuilder(length + 1); PInvoke.GetWindowText(hwndCur, sb, sb.Capacity); PInvoke.RECT rct; PInvoke.GetWindowRect(hwndCur, out rct); var style = PInvoke.GetWindowLong(hwndCur, PInvoke.GWL_STYLE); childs.Add(new WinComponent(strWndClass, sb.ToString(), hwndCur, rct.Left, rct.Top, style)); hwndCur = PInvoke.GetWindow(hwndCur, (uint)PInvoke.GetWindowFlags.GW_HWNDNEXT); } while (hwndCur != IntPtr.Zero); foreach (var pointer in pointers) { RecurseFindWindow(PInvoke.GetWindow(pointer, (uint)PInvoke.GetWindowFlags.GW_CHILD), childs); } }