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
- {
- static void Main(string[] args)
- {
- Timer timer1 = new Timer("CDisplayEx", e) { Interval = 1000, Enabled = true };
- timer1.Tick += new System.EventHandler(timer1_Tick);
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- StringBuilder sbBufferText = new StringBuilder(255);
- GetWindowText(GetForegroundWindow(), sbBufferText, sbBufferText.Capacity);
- Console.WriteLine("Foreground Window text = {0}", sbBufferText.ToString());
- }
- [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
- public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
- [DllImport("User32.dll", SetLastError = true)]
- public static extern IntPtr GetForegroundWindow();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement