Active Window

  • Thread starter Thread starter Josh
  • Start date Start date
J

Josh

Hi,

Anyone know how to read the text from the title bar of currently active
window in Windows. I want to record what application I used at what time.

I hope there is a quick c# answer.

Thanks in advance
 
One way to do this might be to pinvoke the GetForegroundWindow,
GetWindowTextLength, and GetWindowText functions. I believe all of these
functions are present at the link below.
http://www.pinvoke.net/
 
Hello,
I am trying to do the same thing but have no experience with pinvoke. Can
you provide a code snippet to help get me started?
Thanks!
 
private void GetActiveWindow()
{
try
{

const int nChars = 256;
int handle = 0;
StringBuilder Buff = new StringBuilder(nChars);

handle = GetForegroundWindow();

if ( GetWindowText(handle, Buff, nChars) > 0 )
{
textBox1.Text = Buff.ToString();
}

comboBox1.Visible = false;
button1_Click(null,null);
}
catch(Exception wentWrong)
{
// MessageBox.Show(this,wentWrong.Message);
}

}
 
Back
Top