954,541 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Get Current Active Window Title/Name

I just need some code that will return a string of the name of the current activated window title/name.

I've spent almost hours looking for a simple example though...

================================================================

I've seen other people say to hook windows messages and listen for wm_activate, and others...

I already have when to check, I just need something like...

print window.name.current
>> Get Current Active Window Title/Name - Python - Mozilla Firefox

Shadow14l
Light Poster
39 posts since May 2008
Reputation Points: 10
Solved Threads: 8
 

Windows calls this the "Foreground Window". It might not be the one your program is running.

HWND GetForegroundWindow(VOID);


Once you have the HWND you can call GetWindowText(hWnd,outbuf,outlen) to get the title bar contents.

I assume pywin32 supports these calls, but haven't looked them up.

BearofNH
Posting Whiz
323 posts since May 2007
Reputation Points: 94
Solved Threads: 48
 

It doesn't support those, I was looking for a module, or another method to do that.

Shadow14l
Light Poster
39 posts since May 2008
Reputation Points: 10
Solved Threads: 8
 

Very easy, using pywin32.

import win32gui
w=win32gui
w.GetWindowText (w.GetForegroundWindow())
antoniodosvox
Newbie Poster
1 post since May 2008
Reputation Points: 10
Solved Threads: 1
 

Thanks a lot, I was looking for an easy answer like this!!!!!

Shadow14l
Light Poster
39 posts since May 2008
Reputation Points: 10
Solved Threads: 8
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You