การอ่านค่า Title จากโปรแกรมอื่นๆ ในโปรแกรม console C# .NET
การอ่านค่า Title จากโปรแกรมที่เรียกใช้งานอยู่ ในโปรแกรม console C# สำหรับการเขียนบอท หรือโปรแกรมอื่นๆ เพื่อเช็คว่า โปรแกรมเป้าหมายแสดงผล หรือมีกระบวนการการทำงานที่ถูกต้องหรือไม่ ซึ่งในส่วนนี้จะเช็คได้แค่ชื่อ Title ของโปรแกรมนั้นๆ เท่านั้น
using System.Text; using System.Runtime.InteropServices;
[DllImport("user32.dll")] static extern IntPtr GetForegroundWindow(); [DllImport("user32.dll")] static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);
private void GetActiveWindow() { const int nChars = 256; IntPtr handle; StringBuilder Buff = new StringBuilder(nChars); handle = GetForegroundWindow(); if (GetWindowText(handle, Buff, nChars) > 0) { Console.WriteLine(Buff.ToString()); } }