Advertisement
Guest User

Untitled

a guest
Aug 9th, 2021
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.03 KB | None | 0 0
  1. using System;
  2. using System.Diagnostics;
  3. using System.Runtime.InteropServices;
  4. using System.Text;
  5. using System.Threading;
  6.  
  7. namespace ConsoleApp21
  8. {
  9.  
  10.     class Program
  11.     {
  12.  
  13.  
  14.  
  15.         static void Main(string[] args)
  16.         {
  17.             Timer timer1 = new Timer("CDisplayEx", e) { Interval = 1000, Enabled = true };
  18.             timer1.Tick += new System.EventHandler(timer1_Tick);
  19.  
  20.         }
  21.  
  22.         private void timer1_Tick(object sender, EventArgs e)
  23.         {
  24.             StringBuilder sbBufferText = new StringBuilder(255);
  25.             GetWindowText(GetForegroundWindow(), sbBufferText, sbBufferText.Capacity);
  26.             Console.WriteLine("Foreground Window text = {0}", sbBufferText.ToString());
  27.         }
  28.  
  29.         [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
  30.         public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
  31.  
  32.         [DllImport("User32.dll", SetLastError = true)]
  33.         public static extern IntPtr GetForegroundWindow();
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement