public static IntPtr SearchWindow(String title, bool flgA = false) { WindowSearchData sd = new WindowSearchData { Title = title, flgActivate = flgA }; callBackPtr = new MyEnumWindowsProc(Report); EnumWindows(callBackPtr, ref sd); return(sd.hwnd); }
public static IntPtr SearchWindowByClassName(IntPtr hwnd, String className, bool flgA = false) { WindowSearchData sd = new WindowSearchData { ClassName = className, flgActivate = flgA }; callBackPtr = new MyEnumWindowsProc(Report); EnumChildWindows(hwnd, callBackPtr, ref sd); //EnumWindows(callBackPtr, ref sd); return(sd.hwnd); }
public static IntPtr FindWindowByTitle(string title, EnumTitleSearchType searchType) { WindowSearchData search = new WindowSearchData(searchType, title); IntPtr p = (IntPtr)search.ID; if (_windowSearchResults == null) { _windowSearchResults = new Dictionary <int, WindowSearchData>(); } _windowSearchResults.Add(search.ID, search); EnumWindows(enumerateWindowsProcess, p); _windowSearchResults.Remove(search.ID); return(search.WindowFound); }
public static IntPtr SearchForWindow(string wndclass, string title) { WindowSearchData sd = new WindowSearchData { Wndclass = wndclass, Title = title }; int tryCount = 0; while (sd.HWnd == IntPtr.Zero && tryCount < 5) { Thread.Sleep(100); EnumWindows(EnumProc, ref sd); tryCount++; } return(sd.HWnd); }
public static bool EnumProc(IntPtr hWnd, ref WindowSearchData data) { // Check classname and title // This is different from FindWindow() in that the code below allows partial matches StringBuilder sb = new StringBuilder(1024); GetWindowText(hWnd, sb, sb.Capacity); if (sb.ToString().StartsWith(data.Title)) { data.HWnd = hWnd; return(false); // Found the wnd, halt enumeration } return(true); }
public static bool Report(IntPtr hwnd, ref WindowSearchData searchData) { int size = 10240; if (searchData.ClassName != null) { String winClass = GetWinClass(hwnd); Debug.WriteLine(String.Format("{0:X}", hwnd.ToInt32()) + " ClassName=[" + winClass + "]"); if (winClass.IndexOf(searchData.ClassName) >= 0) { searchData.hwnd = hwnd; Debug.WriteLine("Window handle is " + hwnd + " class=" + winClass.ToString()); if (searchData.flgActivate) { SetForegroundWindow(hwnd); Thread.Sleep(500); } return(false); } } else { StringBuilder winTitle = new StringBuilder(size); GetWindowText(hwnd, winTitle, size); String title = winTitle.ToString(); //Debug.WriteLine("Report:" + title); if (title.IndexOf(searchData.Title) >= 0) { searchData.hwnd = hwnd; Debug.WriteLine("Window handle is " + hwnd + " title=" + winTitle.ToString()); if (searchData.flgActivate) { SetForegroundWindow(hwnd); Thread.Sleep(500); } return(false); } } return(true); }
public static extern bool EnumChildWindows(IntPtr parentHandle, MyEnumWindowsProc callback, ref WindowSearchData data);
public static extern bool EnumWindows(MyEnumWindowsProc lpEnumFunc, ref WindowSearchData data);
private static extern bool EnumWindows(EnumWindowsProc lpEnumFunc, ref WindowSearchData data);