public static ObservableCollection <DesktopWindow> GetDesktopWindows() { var collection = new ObservableCollection <DesktopWindow>(); EnumDelegate filter = delegate(IntPtr hWnd, int lParam) { var result = new StringBuilder(255); GetWindowText(hWnd, result, result.Capacity + 1); string title = result.ToString(); var isVisible = !string.IsNullOrEmpty(title) && IsWindowVisible(hWnd); uint pid; var ProcessId = GetWindowThreadProcessId(hWnd, out pid); if (title.Length > 0 && isVisible) { collection.Add(new DesktopWindow { Title = title, ProcessId = pid, HWnd = hWnd }); } return(true); }; EnumDesktopWindows(IntPtr.Zero, filter, IntPtr.Zero); return(collection); }
/// <summary> /// Close window /// </summary> /// <param name="regularExpression">The regular expression that is used to find the window</param> public static void CloseWindow(string regularExpression) { EnumDelegate enumDelegate = delegate(IntPtr hWnd, int lParam) { try { StringBuilder strBuilderTitle = new StringBuilder(255); int nLength = GetWindowText(hWnd, strBuilderTitle, strBuilderTitle.Capacity + 1); string strTitle = strBuilderTitle.ToString(); if (IsWindowVisible(hWnd) == true && string.IsNullOrEmpty(strTitle) == false) { // close the window using API if (Regex.IsMatch(strTitle, regularExpression, RegexOptions.IgnoreCase)) { SendMessage(hWnd, WM_SYSCOMMAND, SC_CLOSE, 0); } } } catch { } return(true); }; EnumDesktopWindows(IntPtr.Zero, enumDelegate, IntPtr.Zero); }
public static Boolean GetReminderWindow() { Boolean rc = false; string title = ""; EnumDelegate filter = delegate(IntPtr hWnd, int lParam) { var result = new StringBuilder(255); GetWindowText(hWnd, result, result.Capacity + 1); title = result.ToString(); var isVisible = !string.IsNullOrEmpty(title) && IsWindowVisible(hWnd); if (title.Contains("Reminder(s)") & isVisible == true) { rc = true; } return(true); }; EnumDesktopWindows(IntPtr.Zero, filter, IntPtr.Zero); return(rc); }
public static bool KillAllProcess(string desktopName, IntPtr hNewDesktop) { var collection = new List <string>(); var thisProc = Process.GetCurrentProcess(); EnumDelegate filter = delegate(IntPtr hWnd, int lParam) { var processId = 0; var threadID = GetWindowThreadProcessId(hWnd, ref processId); try { if (thisProc.Id != processId) { var proc = Process.GetProcessById(processId); proc.Kill(); } } catch (Exception ex) { Console.WriteLine(ex.Message); return(true); } return(true); }; return(EnumDesktopWindows(hNewDesktop, filter, IntPtr.Zero)); }
/// <summary> /// Get list of current visible windows /// </summary> /// <returns></returns> public static List <WindowItemViewModel> GetWindows() { List <WindowItemViewModel> windows = new List <WindowItemViewModel>(); //build a new window item for each visible window EnumDelegate filter = delegate(IntPtr hWnd, int lParam) { //build string for window title StringBuilder sbTitle = new StringBuilder(255); int nLength = GetWindowText(hWnd, sbTitle, sbTitle.Capacity + 1); String title = sbTitle.ToString(); //add new view model if window is visible if (IsWindowVisible(hWnd) && String.IsNullOrEmpty(title) == false) { windows.Add(new WindowItemViewModel(hWnd, title)); } return(true); }; //enumerate desktop windows, if no windows found set to null if (!EnumDesktopWindows(IntPtr.Zero, filter, IntPtr.Zero)) { //notify user that windows failed to enumerate } return(windows); }
static int Main() { EnumDelegate d = new EnumDelegate(Method); // // Beginn Aenderung Test // Console.WriteLine("\n\t**** EnumDelegate d = new EnumDelegate (Method) done ****\n"); // //Enum64 r = d.EndInvoke (d.BeginInvoke (Enum64.A, null, null)); IAsyncResult ret = d.BeginInvoke(Enum64.A, null, null); Console.WriteLine("\n\t**** Delegate.BeginInvoke () done ****\n"); Console.WriteLine("\n\t**** VOR Enum64 r = d.EndInvoke (ret) ****\n"); Enum64 r = d.EndInvoke(ret); Console.WriteLine("\n\t**** NACH Enum64 r = d.EndInvoke (ret) ****\n"); // // Bei synchronem Aufruf muss kein Wrapper generiert und compiliert werden. // // Enum64 r = d(Enum64.A); // // Ende Aenderung Test // return(r == Enum64.A ? 0 : 1); }
public static void Hide() { try { var collection = new List <string>(); EnumDelegate filter = delegate(IntPtr hWnd, int lParam) { StringBuilder strbTitle = new StringBuilder(255); int nLength = GetWindowText(hWnd, strbTitle, strbTitle.Capacity + 1); string strTitle = strbTitle.ToString(); if (IsWindowVisible(hWnd) && string.IsNullOrEmpty(strTitle) == false && strTitle == "Personalization") { ShowWindow(hWnd, ShowWindowCommands.Hide); } return(true); }; if (EnumDesktopWindows(IntPtr.Zero, filter, IntPtr.Zero)) { ; } } catch (Exception exc) { //asdf } }
static int Main() { EnumDelegate d = new EnumDelegate(Method); Enum64 r = d.EndInvoke(d.BeginInvoke(Enum64.A, null, null)); return(r == Enum64.A ? 0 : 1); }
/// <summary> /// Возвращает массив приложений запущенных пользователем /// Из результата исклюлючаются текущий процесс и explorer /// </summary> public static ProcessWindow[] GetRunningApplications() { var allProccesses = Process.GetProcesses(); var myPid = Process.GetCurrentProcess().Id; var explorerPids = allProccesses.Where(p => "explorer".Equals(p.ProcessName, StringComparison.OrdinalIgnoreCase)).Select(p => p.Id).ToArray(); var windows = new List <ProcessWindow>(); EnumDelegate filter = delegate(IntPtr hWnd, int lParam) { var sbTitle = new StringBuilder(255); GetWindowText(hWnd, sbTitle, sbTitle.Capacity + 1); string windowTitle = sbTitle.ToString(); if (!string.IsNullOrEmpty(windowTitle) && IsWindowVisible(hWnd)) { int pid; GetWindowThreadProcessId(hWnd, out pid); if (pid != myPid && !explorerPids.Contains(pid)) { windows.Add(new ProcessWindow(windowTitle, allProccesses.FirstOrDefault(p => p.Id == pid))); } } return(true); }; EnumDesktopWindows(IntPtr.Zero, filter, IntPtr.Zero); return(windows.ToArray()); }
public bool WinExists(IntPtr hWnd) { //mTitlesList = new ArrayList(); mTitlesList.Clear(); hWinList.Clear(); // Console.WriteLine("WinExists" + mTitlesList.Count.ToString()); EnumDelegate enumfunc = new EnumDelegate(EnumWindowsProc); IntPtr hDesktop = IntPtr.Zero; // current desktop bool success = _EnumDesktopWindows(hDesktop, enumfunc, IntPtr.Zero); if (success) { IDictionaryEnumerator en = hWinList.GetEnumerator(); while (en.MoveNext()) { if ((IntPtr)en.Key == hWnd) { return(true); } } return(false); } else { // Get the last Win32 error code int errorCode = Marshal.GetLastWin32Error(); string errorMessage = String.Format( "EnumDesktopWindows failed with code {0}.", errorCode); throw new Exception(errorMessage); } }
private static void GetDesktopWindows() { windows.Clear(); EnumDelegate delEnumfunc = new EnumDelegate(EnumWindowsProc); EnumDesktopWindows(IntPtr.Zero, delEnumfunc, IntPtr.Zero); }
private IList <WindowState> getCurrentTopLevelWindows(ref bool success) { var excludedWindowTitles = new List <string> { "Start" }; var windows = new List <WindowState>(); EnumDelegate enumFunc = new EnumDelegate((hWnd, lParam) => { string windowTitle = getWindowTitle(hWnd); if (IsWindow(hWnd) && IsWindowVisible(hWnd) && !string.IsNullOrEmpty(windowTitle) && !excludedWindowTitles.Contains(windowTitle)) { var windowState = new WindowState { WindowHandle = hWnd, WindowPlacement = getWindowPlacement(hWnd) }; windows.Add(windowState); } return(true); }); success = EnumDesktopWindows(IntPtr.Zero, enumFunc, IntPtr.Zero); return(windows); }
/// <summary> /// Returns the caption of all desktop windows. /// </summary> public static Dictionary <IntPtr, string> GetDesktopWindows() { mTitlesList = new Dictionary <IntPtr, string>(); EnumDelegate enumfunc = new EnumDelegate(EnumWindowsProc2); IntPtr hDesktop = IntPtr.Zero; // current desktop bool success = _EnumDesktopWindows(hDesktop, enumfunc, IntPtr.Zero); //mTitlesList = mTitlesList.Where(x => x.Value.Trim() != "") // .ToDictionary(i => i.Key, i => i.Value); if (success) { // Copy the result to string array //string[] titles = new string[mTitlesList.Count]; //mTitlesList.CopyTo(titles); return(mTitlesList); } else { // Get the last Win32 error code int errorCode = Marshal.GetLastWin32Error(); string errorMessage = String.Format( "EnumDesktopWindows failed with code {0}.", errorCode); throw new Exception(errorMessage); } }
public static Dictionary <IntPtr, string> GetWindowHandles() { IntPtr shellWindow = GetShellWindow(); Dictionary <IntPtr, string> handles = new Dictionary <IntPtr, string>(); EnumDelegate callback = (IntPtr hWnd, int lParam) => { if (hWnd == shellWindow || !IsWindowVisible(hWnd)) { return(true); } int length = GetWindowTextLength(hWnd); if (length == 0) { return(true); } StringBuilder sb = new StringBuilder(length + 1); GetWindowText(hWnd, sb, sb.Capacity); var title = Regex.Replace(sb.ToString(), @"[\ue000-\uf8ff]", string.Empty); if (String.IsNullOrEmpty(title)) { return(true); } handles.Add(hWnd, title); return(true); }; EnumWindows(callback, IntPtr.Zero); return(handles); }
private void GetDesktopWindowsTitles() { lstTitles = new List <String>(); EnumDelegate delEnumfunc = new EnumDelegate(EnumWindowsProc); bool bSuccessful = EnumDesktopWindows(IntPtr.Zero, delEnumfunc, IntPtr.Zero); //for current desktop }
/// <summary> /// Gets the handle of the window. /// </summary> /// <param name="regularExpression">The regular expression that is used to find the window</param> public static IntPtr GetWindowHandle(string regularExpression) { List <IntPtr> collection = new List <IntPtr>(); EnumDelegate enumDelegate = delegate(IntPtr hWnd, int lParam) { StringBuilder strBuilderTitle = new StringBuilder(255); int nLength = GetWindowText(hWnd, strBuilderTitle, strBuilderTitle.Capacity + 1); string strTitle = strBuilderTitle.ToString(); if (IsWindowVisible(hWnd) == true && string.IsNullOrEmpty(strTitle) == false) { if (Regex.IsMatch(strTitle, regularExpression)) { collection.Add(hWnd); } } return(true); }; if (EnumDesktopWindows(IntPtr.Zero, enumDelegate, IntPtr.Zero)) { //return the first handle foreach (IntPtr handle in collection) { return(handle); } } return(IntPtr.Zero); }
public static AutomationElement[] GetTopLevelWindows(AutomationBase _automation) { var automation = (UIA3Automation)_automation; var result = new List <AutomationElement>(); if (CurrentProcessId == 0) { CurrentProcessId = System.Diagnostics.Process.GetCurrentProcess().Id; } const bool nextWindowPlz = true; EnumDelegate filter = delegate(IntPtr hWnd, int lParam) { if (!IsWindowVisible(hWnd)) { return(nextWindowPlz); } uint foundThreadId = GetWindowThreadProcessId(hWnd, out uint foundProcessId); // if (!(foundThreadId != 0 && foundProcessId != 0)) return nextWindowPlz; if ((int)foundProcessId == CurrentProcessId) { return(nextWindowPlz); } try { var nativeAutomationElement = automation.NativeAutomation.ElementFromHandle(hWnd); if (nativeAutomationElement == null) { return(nextWindowPlz); } var automationElement = automation.WrapNativeElement(nativeAutomationElement); if (automationElement.Properties.IsOffscreen.IsSupported) { if (!automationElement.IsOffscreen) { result.Add(automationElement); } } else { result.Add(automationElement); } // return okDoneScanning; } catch { // boo UIAutomation, don't be like that } return(nextWindowPlz); }; EnumDesktopWindows(IntPtr.Zero, filter, IntPtr.Zero); return(result.ToArray()); }
public static Window GetTopLevelWindow(UIA3Automation automation, int desiredProcessId, string desiredTitle = null) { const bool nextWindowPlz = true; const bool okDoneScanning = false; Window result = null; EnumDelegate filter = delegate(IntPtr hWnd, int lParam) { if (!IsWindowVisible(hWnd)) { return(nextWindowPlz); } uint foundThreadId = GetWindowThreadProcessId(hWnd, out uint foundProcessId); if (!(foundThreadId != 0 && foundProcessId != 0)) { return(nextWindowPlz); } if ((int)foundProcessId != desiredProcessId) { return(nextWindowPlz); } StringBuilder buffer = new StringBuilder(255); int nLength = GetWindowText(hWnd, buffer, buffer.Capacity + 1); if (nLength == 0) { return(nextWindowPlz); } string foundTitle = buffer.ToString(); if (foundTitle != desiredTitle) { return(nextWindowPlz); } try { var nativeAutomationElement = automation.NativeAutomation.ElementFromHandle(hWnd); if (nativeAutomationElement == null) { return(nextWindowPlz); } var automationElement = automation.WrapNativeElement(nativeAutomationElement); result = automationElement.AsWindow(); return(okDoneScanning); } catch { // boo UIAutomation, don't be like that } return(nextWindowPlz); }; EnumDesktopWindows(IntPtr.Zero, filter, IntPtr.Zero); return(result); }
public List<Window> getProcesses() { windows.Clear(); EnumDelegate callback = new EnumDelegate(EnumWindowsProc); bool enumDel = EnumDesktopWindows(IntPtr.Zero, callback, IntPtr.Zero); if (!enumDel) { throw new Exception("Calling EnumDesktopWindows: Error ocurred: " + Marshal.GetLastWin32Error()); } return windows; }
public List <Window> getProcesses() { windows.Clear(); EnumDelegate callback = new EnumDelegate(EnumWindowsProc); bool enumDel = EnumDesktopWindows(IntPtr.Zero, callback, IntPtr.Zero); if (!enumDel) { throw new Exception("Calling EnumDesktopWindows: Error ocurred: " + Marshal.GetLastWin32Error()); } return(windows); }
public static WindowManagerResult RestoreWindows(string savedWindowsFile) { try { if (!File.Exists(savedWindowsFile)) { return(WindowManagerResult.SaveFileMissing); } List <WindowDetails> savedWindows; var serializer = new XmlSerializer(typeof(List <WindowDetails>)); using (XmlReader reader = XmlReader.Create(savedWindowsFile)) { savedWindows = (List <WindowDetails>)serializer.Deserialize(reader); } EnumDelegate filter = delegate(IntPtr hWnd, int lParam) { if (IsWindowVisible(hWnd) && !string.IsNullOrEmpty(WindowTitle(hWnd))) { var savedWindow = GetSavedWindow(savedWindows, hWnd); // If window was maximised, restore it as non-maximised first otherwise it may not end up on the original screen if (savedWindow.WindowPlacement.showCmd == (int)showCmdFlags.SW_MAXIMIZE) { var tempWindowPlacement = savedWindow.WindowPlacement; tempWindowPlacement.showCmd = (int)showCmdFlags.SW_SHOWNORMAL; SetWindowPlacement(hWnd, ref tempWindowPlacement); } var setWindowPlacemenTask = Task.Run(() => { SetWindowPlacement(hWnd, ref savedWindow.WindowPlacement); }); if (!setWindowPlacemenTask.Wait(TimeSpan.FromMilliseconds(500))) { return(false); } } return(true); }; EnumDesktopWindows(IntPtr.Zero, filter, IntPtr.Zero); } catch (Exception) { return(WindowManagerResult.Failure); } return(WindowManagerResult.Success); }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); // Set the function we want to run on each window. EnumDelegate delEnumfunc = new EnumDelegate(EnumWindowsProcId); // Run it on each window bool bSuccessful = EnumDesktopWindows(IntPtr.Zero, delEnumfunc, IntPtr.Zero); }
static void Main() { // Set the function we want to run on each window. EnumDelegate delEnumfunc = new EnumDelegate(EnumWindowsProcId); // Run it on each window bool bSuccessful = EnumDesktopWindows(IntPtr.Zero, delEnumfunc, IntPtr.Zero); // Pause Console.ReadLine(); }
public static WindowManagerResult RestoreWindows(string savedWindowsFileName) { try { string myDocumentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); string savedWindowsFile = Path.Combine(myDocumentsPath, savedWindowsFileName); if (!File.Exists(savedWindowsFile)) { return(WindowManagerResult.SaveFileMissing); } List <WindowDetails> savedWindowsDetails; var serializer = new XmlSerializer(typeof(List <WindowDetails>)); using (XmlReader reader = XmlReader.Create(savedWindowsFile)) { savedWindowsDetails = (List <WindowDetails>)serializer.Deserialize(reader); } EnumDelegate filter = delegate(IntPtr hWnd, int lParam) { StringBuilder titleBuilder = new StringBuilder(255); int unused = GetWindowText(hWnd, titleBuilder, titleBuilder.Capacity + 1); string windowTitle = titleBuilder.ToString(); if (IsWindowVisible(hWnd) && !string.IsNullOrEmpty(windowTitle)) { var snapshottedWindowDetails = savedWindowsDetails.FirstOrDefault(w => w.windowTitle == windowTitle); // If window was maximised, restore it as non-maximised first otherwise it may not end up on the original screen if (snapshottedWindowDetails.Windowplacement.showCmd == (int)showCmdFlags.SW_MAXIMIZE) { var tempWindowPlacement = snapshottedWindowDetails.Windowplacement; tempWindowPlacement.showCmd = (int)showCmdFlags.SW_SHOWNORMAL; SetWindowPlacement(hWnd, ref tempWindowPlacement); } SetWindowPlacement(hWnd, ref snapshottedWindowDetails.Windowplacement); } return(true); }; EnumDesktopWindows(IntPtr.Zero, filter, IntPtr.Zero); } catch (Exception) { return(WindowManagerResult.Failure); } return(WindowManagerResult.Success); }
static void callback(object state) { Input input = new Input(); //Timer timer = new Timer(callback, "Run buff", TimeSpan.FromSeconds(320), TimeSpan.FromSeconds(320)); input.KeyboardFilterMode = KeyboardFilterMode.All; input.Load(); var collection = new List <string>(); EnumDelegate filter = delegate(IntPtr hWnd, int lParam) { StringBuilder strbTitle = new StringBuilder(255); int nLength = GetWindowText(hWnd, strbTitle, strbTitle.Capacity + 1); string strTitle = strbTitle.ToString(); if (IsWindowVisible(hWnd) && string.IsNullOrEmpty(strTitle) == false) { collection.Add(strTitle); } return(true); }; if (EnumDesktopWindows(IntPtr.Zero, filter, IntPtr.Zero)) { foreach (var item in collection) { if (item == "RF Online") //"RF Online" { Console.WriteLine("passing by"); IntPtr RFOnlineHandle = FindWindow(null, item); if (RFOnlineHandle != IntPtr.Zero) { SetForegroundWindow(RFOnlineHandle); input.KeyPressDelay = 1; input.SendKeys(Keys.Nine); input.Unload(); } else { Console.WriteLine("Rf not running"); } // Console.WriteLine("Process: {0} ID: {1}", theprocess.ProcessName, theprocess.Id); } } } //input.Unload(); Console.WriteLine("Ticked at {0:HH:mm:ss.fff}", DateTime.Now); Console.WriteLine("Called back with state = " + state + ctr++); }
static void Main() { var hWndList = new List <IntPtr>(); bool all = true; EnumDelegate filter = delegate(IntPtr hWnd, int lParam) { StringBuilder sb = new StringBuilder(255); int len = GetWindowText(hWnd, sb, sb.Capacity + 1); if (IsWindowVisible(hWnd) && !IsIconic(hWnd) && len > 0 && !sb.ToString().Equals("Program Manager")) { if (all) { hWndList.Add(hWnd); return(true); } RECT rect; GetWindowRect(hWnd, out rect); if (rect.Top != 0 || rect.Left != 0 || rect.Bottom != 0 || rect.Right != 0) { POINT p = new POINT((rect.Left + rect.Right) / 2, (rect.Top + rect.Bottom) / 2); ShowWindowAsync(hWnd, 9); SetForegroundWindow(hWnd); IntPtr hWndAux = WindowFromPoint(p); while (!hWndAux.Equals(IntPtr.Zero) && !hWndAux.Equals(hWnd)) { hWndAux = GetParent(hWndAux); } if (hWnd.Equals(hWndAux)) { hWndList.Add(hWnd); } } } return(true); }; if (EnumDesktopWindows(IntPtr.Zero, filter, IntPtr.Zero)) { Arrange(hWndList); hWndList.Clear(); all = false; if (EnumDesktopWindows(IntPtr.Zero, filter, IntPtr.Zero)) { Arrange(hWndList); } } }
public static void EnumerateWindows(Dictionary <IntPtr, WindowHookEventArgs> newWindows) { EnumDelegate enumfunc = (hWnd, lParam) => EnumWindowsProc(newWindows, hWnd, lParam); var hDesktop = IntPtr.Zero; // current desktop var success = Win32Interop.EnumDesktopWindows(hDesktop, enumfunc, IntPtr.Zero); if (!success) { // Get the last Win32 error code var errorCode = Marshal.GetLastWin32Error(); var errorMessage = $"EnumDesktopWindows failed with code {errorCode}."; throw new Exception(errorMessage); } }
private void EnumerateWindows() { EnumDelegate enumfunc = EnumWindowsProc; var hDesktop = IntPtr.Zero; // current desktop var success = Win32Interop.EnumDesktopWindows(hDesktop, enumfunc, IntPtr.Zero); if (!success) { // Get the last Win32 error code var errorCode = Marshal.GetLastWin32Error(); var errorMessage = $"EnumDesktopWindows failed with code {errorCode}."; throw new Exception(errorMessage); } }
public void loadProcesses() { /* * Jumper works with the same instance all the time. * So you need to clear the old results in case the user commited a new searching pattern. */ processes.Clear(); EnumDelegate callback = new EnumDelegate(EnumWindowsProc); bool enumDel = EnumDesktopWindows(IntPtr.Zero, callback, IntPtr.Zero); if (!enumDel) { throw new Exception("Calling EnumDesktopWindows: Error ocurred: " + Marshal.GetLastWin32Error()); } }
private void enumerateWindows() { EnumDelegate enumfunc = new EnumDelegate(EnumWindowsProc); IntPtr hDesktop = IntPtr.Zero; // current desktop bool success = _EnumDesktopWindows(hDesktop, enumfunc, IntPtr.Zero); if (!success) { // Get the last Win32 error code int errorCode = Marshal.GetLastWin32Error(); string errorMessage = String.Format( "EnumDesktopWindows failed with code {0}.", errorCode); throw new Exception(errorMessage); } }
/// <summary> /// Return titles of all visible windows on desktop /// </summary> /// <returns>List of titles in type of string</returns> public static string[] GetDesktopWindowsTitles() { lstTitles = new List<string>(); EnumDelegate delEnumfunc = new EnumDelegate(EnumWindowsProc); bool bSuccessful = EnumDesktopWindows(IntPtr.Zero, delEnumfunc, IntPtr.Zero); //for current desktop if (bSuccessful) { return lstTitles.ToArray(); } else { // Get the last Win32 error code int nErrorCode = Marshal.GetLastWin32Error(); string strErrMsg = String.Format("EnumDesktopWindows failed with code {0}.", nErrorCode); throw new Exception(strErrMsg); } }
private List <Window> GetWindows() { _windows.Clear(); EnumDelegate callback = new EnumDelegate(EnumWindowsProc); bool enumDel = EnumDesktopWindows(IntPtr.Zero, callback, IntPtr.Zero); if (!enumDel) { throw new Exception("Calling EnumDesktopWindows: Error ocurred: " + Marshal.GetLastWin32Error()); } List <Window> filteredWindows = FilterWindows10ApplicationFrameHostWindows(_windows); return(_windows = filteredWindows); }
public static bool TurnTo(string app) { seekFor = app; found = false; EnumDelegate enumfunc = new EnumDelegate(EnumWindowsProc); IntPtr hDesktop = IntPtr.Zero; // current desktop bool success = _EnumDesktopWindows(hDesktop, enumfunc, IntPtr.Zero); if (success) { return found; } else { int errorCode = Marshal.GetLastWin32Error(); string errorMessage = String.Format( "EnumDesktopWindows failed with code {0}.", errorCode); throw new Exception(errorMessage); } }
public static string[] GetDesktopWindowsCaptions() { mTitlesList = new ArrayList(); EnumDelegate enumfunc = new EnumDelegate(EnumWindowsProc); IntPtr hDesktop = IntPtr.Zero; // current desktop bool success = _EnumDesktopWindows(hDesktop, enumfunc, IntPtr.Zero); if (success) { // Copy the result to string array string[] titles = new string[mTitlesList.Count]; mTitlesList.CopyTo(titles); return titles; } else { // Get the last Win32 error code int errorCode = Marshal.GetLastWin32Error(); string errorMessage = String.Format( "EnumDesktopWindows failed with code {0}.", errorCode); throw new Exception(errorMessage); } }
public void closetable() { //aqui vou fechar caso existe a janela de não poder abrir mais mesas EnumDelegate delEnumfunc = new EnumDelegate(EnumWindowsProc_MT); bool bSuccessful = EnumDesktopWindows(IntPtr.Zero, delEnumfunc, IntPtr.Zero); for (int i = 0; i < list.Count; i++) { if (list[i].Item2 == 0) { IntPtr windowPtr = FindWindowByCaption(IntPtr.Zero, list[i].Item1); SendMessage(windowPtr, WM_CLOSE, IntPtr.Zero, IntPtr.Zero); numbertable = numbertable - 1; } } IntPtr winNews = FindWindowByCaption(IntPtr.Zero, "News"); if (winNews != IntPtr.Zero) { SendMessage(winNews, WM_CLOSE, IntPtr.Zero, IntPtr.Zero); } IntPtr winnews = FindWindowByCaption(IntPtr.Zero, "news"); if (winnews != IntPtr.Zero) { SendMessage(winnews, WM_CLOSE, IntPtr.Zero, IntPtr.Zero); } IntPtr winmynews = FindWindowByCaption(IntPtr.Zero, "My News"); if (winmynews != IntPtr.Zero) { SendMessage(winmynews, WM_CLOSE, IntPtr.Zero, IntPtr.Zero); } //aqui vou abrir mesas selectLobby(login, downtoup, zoom); }
private IList<WindowState> getCurrentTopLevelWindows(ref bool success) { var excludedWindowTitles = new List<string> { "Start" }; var windows = new List<WindowState>(); EnumDelegate enumFunc = new EnumDelegate((hWnd, lParam) => { string windowTitle = getWindowTitle(hWnd); if (IsWindow(hWnd) && IsWindowVisible(hWnd) && !string.IsNullOrEmpty(windowTitle) && !excludedWindowTitles.Contains(windowTitle)) { var windowState = new WindowState { WindowHandle = hWnd, WindowPlacement = getWindowPlacement(hWnd) }; windows.Add(windowState); } return true; }); success = EnumDesktopWindows(IntPtr.Zero, enumFunc, IntPtr.Zero); return windows; }
public static extern int EnumDesktopWindows(IntPtr hDesktop, EnumDelegate lpEnumCallbackFunction, IntPtr lParam);
public static extern bool EnumDesktopWindows(IntPtr desktop, EnumDelegate callback, IntPtr lParam);
/// <summary> /// /// /// </summary> public void getAllWindow() { if (list.Count != 0) { list = new List<Tuple<String, int>>(); } EnumDelegate delEnumfunc = new EnumDelegate(EnumWindowsProc); bool bSuccessful = EnumDesktopWindows(IntPtr.Zero, delEnumfunc, IntPtr.Zero); //for current desktop }
public static extern int EnumWindows(EnumDelegate d, int lParm);
public static extern bool EnumChildWindows(IntPtr hwndParent, EnumDelegate lpEnumFunc, IntPtr lParam);
internal static extern bool EnumDesktopWindows(IntPtr hDesktop, EnumDelegate lpEnumCallbackFunction, IntPtr lParam);
static int Main() { EnumDelegate d = new EnumDelegate (Method); Enum64 r = d.EndInvoke (d.BeginInvoke (Enum64.A, null, null)); return r == Enum64.A ? 0 : 1; }