简体   繁体   中英

Get window title on new window

我正在编写一个键盘记录程序类型的应用程序,并且我已经完成了几乎所有的事情,我的问题是获取窗口标题,我不想每次他们按下一个键时都写窗口标题,我可以获取窗口标题,例如我知道该怎么做,但是当它有一个新窗口时,我将如何只将其写入日志?

You could maintain an internal list of all windows (with window handles as identifiers to keep memory usage low), and when a new one appears, then you can extract it.

The Win32 API (which I assume you're using) has the function:

EnumChildWindows

which can be used for this task. Call

GetDesktopWindow

to supply as the input window handle, and you'll get every window created under this desktop session.

I'm not sure if this would still work via RDP (and Windows Vista+ have the secure desktop as well as the normal clients), but it depends how vital this functionality is for you.

Store the previous window title and if the current window title is different than the previous window title, print the new window title and set the previous window title to the current window title.

This fails if there's multiple windows with the same name, but it may work for your needs.

Anytime a keypress is detected, call GetForegroundWindow to get the handle to the currently focused window. Store this value as a variable in your program and when it changes, call GetWindowText to get the title of the window and log this title.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM