I've been having trouble finding a way to check if the user of the program is visiting a specific website. If I wanted to open a pop up box telling me which website I was currently on, what would be the best way to do it?
I've been thinking about various ways but I can never come to a definite conclusion. Thought about checking which browser is open by browsing the processes or checking the window, but how would I find it out? Even if I didn't find out exact website address but just the name, would be fine.
For example, right now the window open says 'Check Which Website is Visited - Stack Overflow - Mozilla Firefox', is there a way to get that from a programming standpoint? Like somehow check and read what windows are currently open.
Thanks for any help.
Getting the exact URL of the current site from a web browser is going to be specific to each browser. In most cases the easiest way is going to be creating a browser plugin or extension that your application can communicate with to retrieve the desired information. Whether that is a viable option or not is going to be specific to what you are trying to do and whether the user is willing to install the plugin. A lot of applications such as Yahoo Messenger used to do this to integrate messenger functionality into the browser but I don't know if they still do.
Even retrieving just the title is going to be problematic as each browser is different. In some cases you can use
GetWindowText
to retrieve the caption bar title. Unfortunately browsers such as Internet Explorer and Chrome use tabs or custom embedded controls to present that information to users so usingGetWindowText
is of limited use in this case.In order to use
GetWindowText
to retrieve the text in the caption bar you will have to obtain the handle to the specific web browser window though. You can do this withEnumWindows
and use information like process ID with that owns the window or the window class (not a C++ class) to determine if it's a browser window. You will also need to deal with the possibility that there could be more than own browser window open. In this case you could prompt the user with a list of titles and have them select one, it just depends on what you are actually trying to accomplish.To get the title of the active window use this code:
The active window will be under "title".
To get the active running application use this code:
filename will hold the active application