mirror of
https://github.com/peter-tanner/wmctrl-for-windows.git
synced 2024-11-30 11:10:16 +08:00
_adding some dev files
This commit is contained in:
parent
51ed315e54
commit
d9a06d63ea
17
_dev/ListWindows.cs
Normal file
17
_dev/ListWindows.cs
Normal 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
48
_dev/SwitchWindow.cs
Normal 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();
|
||||
}
|
Loading…
Reference in New Issue
Block a user