Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Diagnostics;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading;
- namespace ConsoleApp21
- {
- class Program
- {
- [DllImport("user32")]
- private static extern IntPtr GetForegroundWindow();
- [DllImport("user32", EntryPoint = "SendMessageW", CharSet = CharSet.Unicode)]
- public static extern bool SendMessage(IntPtr hWnd, uint Msg, int wParam, StringBuilder lParam);
- const int WM_GETTEXT = 0x000D;
- static void Main(string[] args)
- {
- string previous_title = null;
- for (; ; )
- {
- IntPtr hwnd = WinGetHandle("CDisplayEx");
- if (hwnd == IntPtr.Zero) continue;
- StringBuilder sb = new StringBuilder(700);
- SendMessage(hwnd, WM_GETTEXT, sb.Capacity, sb);
- string title = sb.ToString();
- if (previous_title != title)
- {
- previous_title = title;
- Console.WriteLine($"Window title: {title}");
- }
- Thread.Sle\u0065p(100);
- }
- }
- public static IntPtr WinGetHandle(string name)
- {
- foreach (Process pList in Process.GetProcessesByName(name))
- return pList.MainWindowHandle;
- return IntPtr.Zero;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement