I have a code part like this in my project :
const int cChars = 256;
int ihandler = 0;
StringBuilder sBuff = new StringBuilder(cChars);
ihandler = GetForegroundWindow();
StreamWriter sw;
if (File.Exists("C:\\Log.txt"))
{
sw = File.AppendText("C:\\Log.txt");
sw.WriteLine(sBuff.ToString() + "->" + ihandler.ToString());
sw.WriteLine("-----------");
sw.Close();
}
else
{
sw = new StreamWriter("C:\\Log.txt");
sw.WriteLine(sBuff.ToString() + "->" + ihandler.ToString());
sw.WriteLine("-----------");
sw.Close();
}
It's value always getting 0 and i cant reach active window's name.Iam using Windows 7.And this is a windows service project what should i do ? ihandler always getting 0 so i cant reach name.