【发布时间】:2014-11-06 16:22:09
【问题描述】:
我正在编写一个键盘记录程序。在我的程序中,我想写入日志文件当前处于活动状态的窗口标题。如果用户更改到其他窗口,日志文件将附加新的标题窗口。这里我有获取窗口标题的代码:
[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();
}
所以,我不知道在发生变化时如何更新窗口标题。请给我一个想法。非常感谢!
【问题讨论】:
-
I'm writing a keylogger---> 祝你在这里获得帮助 -
您的意思是希望在窗口标题更改时收到通知,以便您可以再次调用
GetWindowText? -
写恶意软件的请求是题外话。
-
无论此代码的目的是什么,都不清楚您的问题是什么。你的问题是“如何检测前台窗口发生变化”?