问题
I am trying to get the active tab url for Safari, so far I was able to get the url from all prominent browsers (IE, Firefox, Chrome, Opera) through a mix of Win32 API calls or DDE.
The issue with safari is even when I enumerate through the windows and call GetWindowText it's always null.
Any solutions out there? thanks!
回答1:
public static string getChromeURL() {
uint MAX_PATH=255;
IntPtr hChrome, hAddressBox;
hChrome=GetForegroundWindow();
hAddressBox = FindWindowEx(hChrome, IntPtr.Zero,
"Chrome_AutocompleteEditView", IntPtr.Zero);
StringBuilder sb = new StringBuilder(256);
SendMessage(hAddressBox, WM_GETTEXT, (IntPtr)MAX_PATH, sb);
string s = sb.ToString().Trim(new Char[] { ' ', '\0', '\n' });
return s;
}
来源:https://stackoverflow.com/questions/5041141/getting-active-tab-url-from-safari