public void showTabTitles() { //Grab all the Chrome processes Process[] chromeProcesses = Process.GetProcessesByName("chrome"); //Chrome process not found if ((chromeProcesses.Length == 0)) { items.Add("Chrome isn\'t open?"); return; } //Clear our array of tab titles tabTitles = new List <string>(); //Kick off our search for chrome tab titles EnumWindowsCallback callBackFn = new EnumWindowsCallback(Enumerator); EnumWindows(callBackFn, 0); //Add to our listbox items.AddRange(tabTitles.ToArray()); if (searchTry == 0 && !ActivateSelectedWindow()) { btnShowTabTitles_Click(null, null); } searchTry++; }
/// <summary> /// 프로세스 ID로 윈도우 핸들을 얻는다. /// </summary> /// <param name="processId"></param> /// <returns></returns> public int GetWindowHandle(uint processId) { /* * 핸들을 각 창에 차례로 전달하여 응용 프로그램 정의 콜백 함수에 전달하여 화면의 모든 최상위 창을 열거합니다. * EnumWindows 는 마지막 최상위 창이 열거되거나 콜백 함수가 FALSE를 반환 할 때까지 계속 됩니다. */ /* * EnumWindows 사용방법 참고 * https://crynut84.tistory.com/49 */ int rethWnd = 0; EnumWindowsCallback callback = (hwnd, lParam) => { uint pid = GetProcessId(hwnd); if (pid == processId) { rethWnd = hwnd; // return false가 나올때 까지 해당 콜백이 계속 실행된다. return(false); } return(true); }; EnumWindows(callback, 0); return(rethWnd); }
public static IEnumerable <ApplicationWindow> GetApplicationWindows() { List <ApplicationWindow> windows = new List <ApplicationWindow>(); EnumWindowsCallback callback = new EnumWindowsCallback( (hWnd, lParam) => { if (!IsWindowVisible(hWnd) || string.IsNullOrEmpty(GetText(hWnd))) { return(true); } if ((long)GetParent(hWnd) == 0) { bool hasOwner = (long)GetWindow(hWnd, GW_OWNER) != 0; uint exStyle = (uint)GetWindowLongPtr(hWnd, GWL_EXSTYLE); if ((exStyle & WS_EX_TOOLWINDOW) == 0 && !hasOwner) { ApplicationWindow window = new ApplicationWindow(hWnd); windows.Add(window); } } return(true); } ); EnumWindows(callback, IntPtr.Zero); return(windows); }
/// <summary> /// 遍历所有子窗口 /// </summary> /// <param name="windowHandleParent">父窗口</param> /// <param name="callback">查找到窗口时的回调函数</param> /// <returns></returns> public static bool EnumChildWindows(IntPtr windowHandleParent, EnumWindowsCallback callback) { if (callback == null) { throw new ArgumentNullException(); } return(NativeMethods.EnumChildWindows(windowHandleParent, (windowHandle, lParam) => callback(windowHandle), IntPtr.Zero)); }
/// <summary> /// This function is based on jasonfah/chrome-tab-titles on GitHub /// https://github.com/jasonfah/chrome-tab-titles/blob/master/c%23/ChromeTabTitles/Form1.cs /// </summary> private void showTabTitles() { //Clear our array of tab titles youtubeWindows.Clear(); // Kick off our search for chrome tab titles EnumWindowsCallback callBackFn = new EnumWindowsCallback(Enumerator); EnumWindows(callBackFn, 0); }
public static List <IntPtr> GetChildWindows(IntPtr parent) { var windows = new List <IntPtr>(); EnumWindowsCallback @delegate = (window, p) => { windows.Add(window); return(true); }; EnumChildWindows(parent, @delegate, IntPtr.Zero); return(windows); }
public static BOOL EnumWindows(EnumWindowsCallback lpEnumFunc) { // We pass a static delegate to the native function and supply the callback as // reference data, so that the CLR doesn't need to generate a native code block for // each callback delegate instance (for storing the closure pointer). var gcHandle = GCHandle.Alloc(lpEnumFunc); try { return(EnumWindows(s_enumWindowsNativeCallback, GCHandle.ToIntPtr(gcHandle))); } finally { gcHandle.Free(); } }
public static WindowRectangle CheckWindow(int height, int width) { // Have to declare a delegate so that a thunk is created, so that win32 may call us back. EnumWindowsCallback callBackFn = new EnumWindowsCallback(ReportWindow); heightWindow = height; widthWindow = width; EnumWindows(callBackFn, 0); WindowRectangle w = new WindowRectangle(); w.Left = rectangleOfWindow.Left; w.Right = rectangleOfWindow.Right; w.Top = rectangleOfWindow.Top; w.Bottom = rectangleOfWindow.Bottom; return(w); }
public static IntPtr FindWindowByPartialTitle(string title) { IntPtr hWndResult = IntPtr.Zero; EnumWindowsCallback enumFunc = (IntPtr hWnd, IntPtr param) => { if (GetWindowText(hWnd).Contains(title)) { hWndResult = hWnd; } }; var lpEnumFunc = Marshal.GetFunctionPointerForDelegate(enumFunc); Win32.EnumWindows(lpEnumFunc, 0); return(hWndResult); }
public void showTabTitles() { //Grab all the Chrome processes Process[] chromeProcesses = Process.GetProcessesByName("chrome"); //Chrome process not found if ((chromeProcesses.Length == 0)) { //lstTabTitles.Items.Add("Chrome isn\'t open?"); //btnShowTabTitles.Enabled = false; return; } //Clear our array of tab titles tabTitles = new List <string>(); //Kick off our search for chrome tab titles selectedProcess = new List <IntPtr>(); EnumWindowsCallback callBackFn = new EnumWindowsCallback(Enumerator); EnumWindows(callBackFn, 0); //Add to our listbox //lstTabTitles.Items.AddRange(tabTitles.ToArray()); /* * foreach(var it in tabTitles) * { * if ( it.ToLower().Contains("tcs")) * { * bringToFront(it); * break; * } * } */ }
internal static extern int EnumWindows( EnumWindowsCallback lpEnumFunc, int lParam );
public static extern int EnumWindows(EnumWindowsCallback x, int y);
public static extern int EnumWindows(EnumWindowsCallback callback, int lparam);
public static extern bool EnumWindows(EnumWindowsCallback lpfn, int lParam);
private static extern bool EnumChildWindows( IntPtr parentWindow, EnumWindowsCallback callback, IntPtr param);
public static extern int EnumWindows(EnumWindowsCallback callPtr, int lPar);
static extern bool EnumWindows(EnumWindowsCallback callback, ref SearchData searchData);
private static extern int EnumWindows(EnumWindowsCallback callback, int lparam);
public static extern bool EnumChildWindows(IntPtr hWnd, EnumWindowsCallback callback, int param);
static extern bool EnumChildWindows(IntPtr parentHandle, EnumWindowsCallback callback, IntPtr lParam);
public static extern bool EnumWindows(EnumWindowsCallback callback, int param);
public extern static int EnumChildWindows(IntPtr hWndParent, EnumWindowsCallback lpEnumFunc, int lParam);
public static extern bool EnumWindows(EnumWindowsCallback callback, IntPtr lParam);
private static extern int EnumWindows(EnumWindowsCallback callback, /*ref*/ IntPtr param);
static extern int EnumWindows(EnumWindowsCallback hWnd, IntPtr lParam);
public static extern int EnumChildWindows(IntPtr hwnd, EnumWindowsCallback proc, IntPtr lParam);
public static extern int EnumChildWindows(IntPtr hWnd, EnumWindowsCallback lpEnumFunc, int lParam);
public extern static int EnumWindows(EnumWindowsCallback lpEnumFunc, int lParam);
public static extern int EnumThreadWindows(IntPtr hWndParent, EnumWindowsCallback callback, int lParam);
private static extern bool EnumChildWindows(IntPtr hWndParent, EnumWindowsCallback callback, /*ref*/ IntPtr param);
internal static extern bool EnumThreadWindows(int tId, EnumWindowsCallback callback, IntPtr callbackParam);
public static extern int _EnumWindows(EnumWindowsCallback lpEnumFunc, int lParam);
internal static extern int EnumWindows(EnumWindowsCallback callPtr, int lParam);
private static extern bool EnumWindows(EnumWindowsCallback lpEnumFunc, IntPtr lParam);
internal static extern int EnumWindows(EnumWindowsCallback lpEnumFunc, int lParam);
public static extern int EnumWindows(EnumWindowsCallback callback, int extraData);