Get current active Window title in C

匿名 (未验证) 提交于 2019-12-03 03:10:03

问题:

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.

回答1:

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); } 


回答2:

Here are the APIs to use:

GetActiveWindow()

http://msdn.microsoft.com/en-us/library/windows/desktop/ms646292(v=vs.85).aspx

GetWindowText()

http://msdn.microsoft.com/en-us/library/windows/desktop/ms633520(v=vs.85).aspx



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!