_adding some dev files

This commit is contained in:
elmanuelito 2016-01-13 21:32:17 +01:00
parent 51ed315e54
commit d9a06d63ea
2 changed files with 65 additions and 0 deletions

17
_dev/ListWindows.cs Normal file
View File

@ -0,0 +1,17 @@
using System.IO;
using System;
using System.Diagnostics;
class Program
{
static void Main()
{
Process[] processlist = Process.GetProcesses();
foreach (Process process in processlist)
{
if (!String.IsNullOrEmpty(process.MainWindowTitle))
{
Console.WriteLine("Process: {0} ID: {1} Window title: {2}", process.ProcessName, process.Id, process.MainWindowTitle);
}
}
}
}

48
_dev/SwitchWindow.cs Normal file
View File

@ -0,0 +1,48 @@
//declarations
using system.IO;
using System.Runtime.InteropServices;
using System.Diagnostics;
//more
//namespace here
//class here
//initialize method
class Program
{
static void Main()
{
//related .dll import
[DllImport("user32.dll")]
public static extern void SwitchToThisWindow(IntPtr hWnd);
String ProcWindow = "main";
//function which calls switchWindow() is here but not important
Process[] procs = Process.GetProcessesByName(ProcWindow);
foreach (Process proc in procs)
{
//switch to process by name
SwitchToThisWindow(proc.MainWindowHandle);
Console.WriteLine("Process: {0} ID: {1} Window title: {2}", proc.ProcessName, proc.Id, proc.MainWindowTitle);
}
}
}
}
// --------------------------------------------------------------------------------
// ---
// --------------------------------------------------------------------------------
http://stackoverflow.com/questions/2315561/correct-way-in-net-to-switch-the-focus-to-another-application
// --------------------------------------------------------------------------------
// ---
// --------------------------------------------------------------------------------
AutomationElement element = AutomationElement.FromHandle(process.MainWindowHandle);
if (element != null)
{
element.SetFocus();
}