Jump to content

How to detect if current window is a browser


Recommended Posts

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?

Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...