我在写一个键盘记录程序。在我的程序中,我想写入日志文件当前窗口标题,它是活动的。如果用户更改为其他窗口,则日志文件将附加新的标题窗口。在这里,我有代码获取Windows标题:c# - 获取当前窗口标题
[System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
public static extern int GetWindowText(IntPtr hwnd, string lpString, int cch);
public static string ActiveApplTitle()
{
//This method is used to get active application's title using GetWindowText() method present in user32.dll
IntPtr hwnd = GetForegroundWindow();
if (hwnd.Equals(IntPtr.Zero)) return "";
string lpText = new string((char)0, 100);
int intLength = GetWindowText(hwnd, lpText, lpText.Length);
if ((intLength <= 0) || (intLength > lpText.Length)) return "unknown";
return lpText.Trim();
}
所以,我不知道如何更新窗口标题,当有变化。请给我一个主意。非常感谢!
'我正在写一个键盘记录程序--- --->祝您在这里获得帮助 – 2014-11-06 16:22:42
您的意思是您希望在窗口标题更改时得到通知,以便您可以再次调用'GetWindowText'? – 2014-11-06 16:24:02
撰写恶意软件的请求不太明确。 – MatthewMartin 2014-11-06 16:25:28