简体   繁体   中英

Get current active Window title in C

I want to write an X-Chat plugin where users will be able to perform a CTCP request to my client, whereby the plugin/X-Chat will respond with my current active window title.

This would be really cool for fellow IRC users to see what I'm up to to allow them to determine what I'm doing if I'm full screen (playing a game, watching a video etc).

Plugins for X-Chat are written in C, so I need a way of determining the current active Window title using Windows API calls from C. Can anyone advise on how this might be done?

Thanks.

I think you can use GetForegroundWindow() to get a handle to the window the user is using and then use GetWindowText() to get the title:

HWND foreground = GetForegroundWindow();
if (foreground)
{
    char window_title[256];
    GetWindowText(foreground, window_title, 256);
}

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