using System.Runtime.InteropServices;
سپس تعریف :
// Declare external functions.
[DllImport("user32.dll")]
private static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
private static extern int GetWindowText(IntPtr hWnd,
StringBuilder text, int count);
و نهایتا افزودن سه لیبل و یک تایمر (مثلا با نام tmrRefresh) به برنامه و فعال کردن رویداد Tick آن :
private void tmrRefresh_Tick(object sender, EventArgs e)
{
int chars = 256;
StringBuilder buff = new StringBuilder(chars);
// Obtain the handle of the active window.
IntPtr handle = GetForegroundWindow();
// Update the controls.
if (GetWindowText(handle, buff, chars) > 0)
{
lblCaption.Text = buff.ToString();
lblHandle.Text = handle.ToString();
if (handle == this.Handle)
{
lblCurrent.Text = "True";
}
else
{
lblCurrent.Text = "False";
}
}
}
منبع : Visual C# 2005 Recipes: A Problem-Solution Approach




 
			
			
 
					
					
					
						 پاسخ با نقل قول
  پاسخ با نقل قول 
			