Jump to content
Sign in to follow this  
quagmire1973

How to detect if current window is a browser

Recommended Posts

quagmire1973

I am writing a utility to work with various windows from multiple applications. The application will perform certain tasks on the active window but if the active window is a web browser, then I need to perform these tasks in a different fashion. So ultimately, I need to know if the active window is a browser, and then act accordingly.

Now I know there are a ton of browsers out there, but for the purposes of my app, let's say we're only dealing with firefox.exe, iexplore.exe, and chrome.exe.

I know we can detect windows and even tabs in a browser, but is there a way to map the window title to the PID/process that owns it? I can detect IE and Firefox by the text in the window because "Firefox" and "Internet Explorer" are always part of the window name. In Chrome they are not and other browsers may be the same.

I'm looking to see if there is a way I can return the process ID of the active window, which I could then use to lookup the name of the process, and compare it to a browser list.

Any ideas?

Share this post


Link to post
Share on other sites
quagmire1973

Well I just now noticed that the actual window name in Chrome does have the browser name in it but I couldn't see it. I'd still like to know how to do the above though.

Share this post


Link to post
Share on other sites
AdmiralAlkex

Would it not make more sense to look at the window class? Exe-files aren't hard to rename. Ehh maybe not.

Anyway, take a look at WinGetProcess() and _ProcessGetName(). The example for _ProcessGetName() is exactly what you're asking for.

Edited by AdmiralAlkex

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×