středa 19. srpna 2015

Active Window Title Watch

class Program
    {
        static void Main(string[] args)
        {
            while(true)
            {
                Console.WriteLine(GetActiveWindowTitle());
                Thread.Sleep(1000);
            }
        }

        [DllImport("user32.dll")]
        static extern IntPtr GetForegroundWindow();

        [DllImport("user32.dll")]
        static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);

        private static string GetActiveWindowTitle()
        {
            const int nChars = 256;
            StringBuilder Buff = new StringBuilder(nChars);
            IntPtr handle = GetForegroundWindow();

            if (GetWindowText(handle, Buff, nChars) > 0)
            {
                return Buff.ToString();
            }
            return null;
        }
    }

Zdroj:
http://stackoverflow.com/questions/115868/how-do-i-get-the-title-of-the-current-active-window-using-c
http://www.csharphelp.com/2006/08/get-current-window-handle-and-caption-with-windows-api-in-c/

Žádné komentáře:

Okomentovat