c# get foreground window
C#
#region Retrieve list of windows
[DllImport("user32")]
private static extern int GetWindowLongA(IntPtr hWnd, int index);
[DllImport("USER32.DLL")]
private static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
[DllImport("USER32.DLL")]
private static extern bool EnumWindows(EnumWindowsProc enumFunc, int lParam);
[DllImport("user32.dll")]
private static extern IntPtr GetForegroundWindow();
private const int GWL_STYLE = -16;
private const ulong WS_VISIBLE = 0x10000000L;
private const ulong WS_BORDER = 0x00800000L;
private const ulong TARGETWINDOW = WS_BORDER | WS_VISIBLE;
internal class Window
{
public string Title;
public IntPtr Handle;
public override string ToString()
{
return Title;
}
}
private List<Window> windows;
private void GetWindows()
{
windows = new List<Window>();
EnumWindows(Callback, 0);
}
private bool Callback(IntPtr hwnd, int lParam)
{
if (this.Handle != hwnd && (GetWindowLongA(hwnd, GWL_STYLE) & TARGETWINDOW) == TARGETWINDOW)
{
StringBuilder sb = new StringBuilder(100);
GetWindowText(hwnd, sb, sb.Capacity);
Window t = new Window();
t.Handle = hwnd;
t.Title = sb.ToString();
windows.Add(t);
}
return true; //continue enumeration
}
#endregion
Also in C#:
- Title
- C# get all files in directory
- Category
- C#
- Title
- how to get array of children transform
- Category
- C#
- Title
- how to insert into a list c#
- Category
- C#
- Title
- unity switch to scene and transfer data
- Category
- C#
- Title
- unity load scene
- Category
- C#
- Title
- orderby make sunday last day c#
- Category
- C#
- Title
- unity how to change rotation
- Category
- C#
- Title
- asp.net core task iactionresult
- Category
- C#
- Title
- how to name GameObject in c#
- Category
- C#
- Title
- exit game unity
- Category
- C#
- Title
- C# linq mselect
- Category
- C#
- Title
- generate a dropdown list from array data using razor .net mvc
- Category
- C#
- Title
- c# keyvaluepair
- Category
- C#
- Title
- how to move towards an object unity
- Category
- C#
- Title
- unity docs player input
- Category
- C#
- Title
- no overload for 'useItemOnSceneLoad' matches delegate 'UnityAction<Scene, LoadSceneMode>'
- Category
- C#
- Title
- IEnumerator
- Category
- C#
- Title
- c# read all text from a file
- Category
- C#
- Title
- c# convert double to int
- Category
- C#
- Title
- find negative version of integer in c#
- Category
- C#
- Title
- how to update a project to cross target .net core
- Category
- C#
- Title
- c# dictionaries
- Category
- C#
- Title
- unity check if gameobject is active
- Category
- C#
- Title
- how to check if a value is inside an array c#
- Category
- C#
- Title
- how to mock abstract httpcontext using moq .net core
- Category
- C#
- Title
- c# switct case
- Category
- C#
- Title
- uncaught syntaxerror invalid or unexpected token unity webgl
- Category
- C#
- Title
- c# round number up
- Category
- C#
- Title
- system.io.directorynotfoundexception c#
- Category
- C#
- Title
- check for collision unity c#
- Category
- C#
- Title
- how to cjeck if a string has a word c#
- Category
- C#
- Title
- c# dictionary add
- Category
- C#
- Title
- asking for user input integer c#
- Category
- C#
- Title
- c# remove last value from list
- Category
- C#
- Title
- how to make % posibility to spawn an object C# in unity
- Category
- C#
- Title
- c# if statement
- Category
- C#
- Title
- asp.net core mvc not triggering client side validation
- Category
- C#
- Title
- query associative table ef6
- Category
- C#
- Title
- how to parse a string to an integer c#
- Category
- C#
- Title
- open udp socket c#
- Category
- C#
- Title
- vb.net drag window without titlebar
- Category
- C#
- Title
- loop over enum values
- Category
- C#
- Title
- c# bool list count true
- Category
- C#
- Title
- unity 2d enemy field of view
- Category
- C#
- Title
- Failed to retrieve Firebase Instance Id
- Category
- C#
- Title
- transform object according to its parent unity
- Category
- C#
- Title
- 2D follow ia unity 2D with agrorange
- Category
- C#
- Title
- delegate function c#
- Category
- C#
- Title
- c# how to open file explorer
- Category
- C#
- Title
- create asp.net which send email and sms using own api
- Category
- C#
- Title
- C# .net core convert string to enum
- Category
- C#
- Title
- date time heutiges datum
- Category
- C#
- Title
- replace double backslash with single backslash c#
- Category
- C#
- Title
- c# display image
- Category
- C#
- Title
- c# adding to a list
- Category
- C#
- Title
- convert from xls to xlsx C#
- Category
- C#
- Title
- c# implement ienumerable t
- Category
- C#
- Title
- for each property in object c#
- Category
- C#
- Title
- c# request run as administrator
- Category
- C#
- Title
- unity find object by name
- Category
- C#
- Title
- flip boolean c#
- Category
- C#
- Title
- delay in unity
- Category
- C#
- Title
- C# random.Next error
- Category
- C#
- Title
- how to hide and show object in unity script
- Category
- C#
- Title
- create new object from generic c#
- Category
- C#
- Title
- Could not load file or assembly 'Ubiety.Dns.Core, Version=2.2.1.0
- Category
- C#
- Title
- c# datetime dd/mm/yyy hh:mm:ss
- Category
- C#
- Title
- how to reference a child object unity
- Category
- C#
- Title
- how to route back to url using Request.Headers["Referer"].ToString() in asp.net core
- Category
- C#
- Title
- c# listview
- Category
- C#
- Title
- how to declare a string c#
- Category
- C#
- Title
- c# create new object
- Category
- C#
- Title
- c# shorten an definition
- Category
- C#
- Title
- print content of array c#
- Category
- C#
- Title
- 2d character controller unity
- Category
- C#
- Title
- unity string format time
- Category
- C#
- Title
- unity how to check object position
- Category
- C#
- Title
- c# append array
- Category
- C#
- Title
- c# reverse a string
- Category
- C#
- Title
- how to use variables in c#
- Category
- C#
- Title
- c# store generic type without arguments
- Category
- C#
- Title
- c# how to refreshyour bindingsource
- Category
- C#
- Title
- how to cast list to observablecollection c#
- Category
- C#
- Title
- how to add an embedded resource in visual studio code
- Category
- C#
- Title
- convert array to list Unity C#
- Category
- C#
- Title
- c# clone stream
- Category
- C#
- Title
- c# making a folder
- Category
- C#
- Title
- html hidden text
- Category
- C#
- Title
- How to get number of months between 2 dates c#
- Category
- C#
- Title
- c# download string url
- Category
- C#
- Title
- unity 2d detect click on sprite
- Category
- C#
- Title
- how to reduce garbage collection c#
- Category
- C#
- Title
- using in c#
- Category
- C#
- Title
- how to change player cursor c# script unity
- Category
- C#
- Title
- button color uwp c#
- Category
- C#
- Title
- compile in one single exe c#
- Category
- C#
- Title
- unity c# run a command then wait
- Category
- C#
- Title
- what function is called just before the a script is ended c#
- Category
- C#
- Title
- wpf textblock line break code behind
- Category
- C#
- Title
- xamarin hide back button
- Category
- C#