Exemple #1
0
        public List <string> GetTabCaptions(IntPtr ieHandle)
        {
            AccessibleObjectFromWindow(GetDirectUIHWND(ieHandle), OBJID.OBJID_WINDOW, ref accessible);

            if (accessible == null)
            {
                throw new Exception();
            }

            var ieDirectUIHWND = new IEAccessible(ieHandle);
            var captionList    = new List <string>();

            foreach (IEAccessible accessor in ieDirectUIHWND.Children)
            {
                foreach (var child in accessor.Children)
                {
                    foreach (var tab in child.Children)
                    {
                        captionList.Add(tab.Name);
                    }
                }
            }

            if (captionList.Count > 0)
            {
                captionList.RemoveAt(captionList.Count - 1);
            }

            return(captionList);
        }
Exemple #2
0
        public string GetActiveTabCaption(IntPtr ieHandle)
        {
            AccessibleObjectFromWindow(GetDirectUIHWND(ieHandle), OBJID.OBJID_WINDOW, ref accessible);

            if (accessible == null)
            {
                throw new Exception();
            }

            var ieDirectUIHWND = new IEAccessible(ieHandle);

            foreach (IEAccessible accessor in ieDirectUIHWND.Children)
            {
                foreach (var child in accessor.Children)
                {
                    foreach (var tab in child.Children)
                    {
                        object tabIndex = tab.accessible.get_accState(0);

                        if ((int)tabIndex == IE_ACTIVE_TAB)
                        {
                            return(tab.Name);
                        }
                    }
                }
            }

            return(String.Empty);
        }
Exemple #3
0
        public IEAccessible(IntPtr ieHandle, int tabIndexToActivate)
        {
            AccessibleObjectFromWindow(GetDirectUIHWND(ieHandle), OBJID.OBJID_WINDOW, ref accessible);

            if (accessible == null)
            {
                throw new Exception();
            }

            var index = 0;

            var ieDirectUIHWND = new IEAccessible(ieHandle);

            foreach (IEAccessible accessor in ieDirectUIHWND.Children)
            {
                foreach (var child in accessor.Children)
                {
                    foreach (var tab in child.Children)
                    {
                        if (tabIndexToActivate >= child.ChildCount - 1)
                        {
                            return;
                        }
                        if (index == tabIndexToActivate)
                        {
                            tab.Activate();
                            return;
                        }

                        index++;
                    }
                }
            }
        }
Exemple #4
0
        public IEAccessible(IntPtr ieHandle, string tabCaptionToActivate)
        {
            AccessibleObjectFromWindow(GetDirectUIHWND(ieHandle), OBJID.OBJID_WINDOW, ref accessible);

            if (accessible == null)
            {
                throw new Exception();
            }

            var ieDirectUIHWND = new IEAccessible(ieHandle);

            foreach (IEAccessible accessor in ieDirectUIHWND.Children)
            {
                foreach (var child in accessor.Children)
                {
                    foreach (var tab in child.Children)
                    {
                        if (tab.Name == tabCaptionToActivate)
                        {
                            tab.Activate();
                            return;
                        }
                    }
                }
            }
        }
Exemple #5
0
        public string GetActiveTabUrl(IntPtr ieHandle)
        {
            AccessibleObjectFromWindow(GetDirectUIHWND(ieHandle), OBJID.OBJID_WINDOW, ref accessible);

            if (accessible == null)
            {
                throw new Exception();
            }

            var ieDirectUIHWND = new IEAccessible(ieHandle);

            foreach (IEAccessible accessor in ieDirectUIHWND.Children)
            {
                foreach (var child in accessor.Children)
                {
                    foreach (var tab in child.Children)
                    {
                        object tabIndex = tab.accessible.get_accState(CHILDID_SELF);

                        if ((int)tabIndex == IE_ACTIVE_TAB)
                        {
                            var description = tab.accessible.get_accDescription(CHILDID_SELF);

                            if (!string.IsNullOrEmpty(description))
                            {
                                if (description.Contains(Environment.NewLine))
                                {
                                    var url = description.Substring(description.IndexOf(Environment.NewLine)).Trim();
                                    return(url);
                                }
                            }
                        }
                    }
                }
            }

            return(String.Empty);
        }
Exemple #6
0
        public int GetTabCount(IntPtr ieHandle)
        {
            AccessibleObjectFromWindow(GetDirectUIHWND(ieHandle), OBJID.OBJID_WINDOW, ref accessible);

            if (accessible == null)
            {
                throw new Exception();
            }

            var ieDirectUIHWND = new IEAccessible(ieHandle);

            foreach (IEAccessible accessor in ieDirectUIHWND.Children)
            {
                foreach (var child in accessor.Children)
                {
                    foreach (var tab in child.Children)
                    {
                        return(child.ChildCount - 1);
                    }
                }
            }

            return(0);
        }
        public int GetTabCount(IntPtr ieHandle)
        {
            AccessibleObjectFromWindow(GetDirectUIHWND(ieHandle), OBJID.OBJID_WINDOW, ref accessible);

            if (accessible == null) throw new Exception();

            var ieDirectUIHWND = new IEAccessible(ieHandle);

            foreach (IEAccessible accessor in ieDirectUIHWND.Children)
            {
                foreach (var child in accessor.Children)
                {
                    foreach (var tab in child.Children)
                        return child.ChildCount - 1;
                }
            }

            return 0;
        }
        public List<string> GetTabCaptions(IntPtr ieHandle)
        {
            AccessibleObjectFromWindow(GetDirectUIHWND(ieHandle), OBJID.OBJID_WINDOW, ref accessible);

            if (accessible == null) throw new Exception();

            var ieDirectUIHWND = new IEAccessible(ieHandle);
            var captionList = new List<string>();

            foreach (IEAccessible accessor in ieDirectUIHWND.Children)
            {
                foreach (var child in accessor.Children)
                    foreach (var tab in child.Children)
                        captionList.Add(tab.Name);
            }

            if (captionList.Count > 0) captionList.RemoveAt(captionList.Count - 1);

            return captionList;
        }
        public string GetActiveTabUrl(IntPtr ieHandle)
        {
            AccessibleObjectFromWindow(GetDirectUIHWND(ieHandle), OBJID.OBJID_WINDOW, ref accessible);

            if (accessible == null) throw new Exception();

            var ieDirectUIHWND = new IEAccessible(ieHandle);

            foreach (IEAccessible accessor in ieDirectUIHWND.Children)
            {
                foreach (var child in accessor.Children)
                {
                    foreach (var tab in child.Children)
                    {
                        object tabIndex = tab.accessible.get_accState(CHILDID_SELF);

                        if ((int)tabIndex == IE_ACTIVE_TAB)
                        {
                            var description = tab.accessible.get_accDescription(CHILDID_SELF);

                            if (!string.IsNullOrEmpty(description))
                            {
                                if (description.Contains(Environment.NewLine))
                                {
                                    var url = description.Substring(description.IndexOf(Environment.NewLine)).Trim();
                                    return url;
                                }
                            }
                        }
                    }
                }
            }

            return String.Empty;
        }
        public int GetActiveTabIndex(IntPtr ieHandle)
        {
            AccessibleObjectFromWindow(GetDirectUIHWND(ieHandle), OBJID.OBJID_WINDOW, ref accessible);

            if (accessible == null) throw new Exception();

            var index = 0;
            var ieDirectUIHWND = new IEAccessible(ieHandle);

            foreach (IEAccessible accessor in ieDirectUIHWND.Children)
            {
                foreach (var child in accessor.Children)
                {
                    foreach (var tab in child.Children)
                    {
                        object tabIndex = tab.accessible.get_accState(0);

                        if ((int)tabIndex == IE_ACTIVE_TAB) return index;

                        index++;
                    }
                }
            }

            return -1;
        }
        public IEAccessible(IntPtr ieHandle, int tabIndexToActivate)
        {
            AccessibleObjectFromWindow(GetDirectUIHWND(ieHandle), OBJID.OBJID_WINDOW, ref accessible);

            if (accessible == null) throw new Exception();

            var index = 0;

            var ieDirectUIHWND = new IEAccessible(ieHandle);

            foreach (IEAccessible accessor in ieDirectUIHWND.Children)
            {
                foreach (var child in accessor.Children)
                {
                    foreach (var tab in child.Children)
                    {
                        if (tabIndexToActivate >= child.ChildCount - 1) return;
                        if (index == tabIndexToActivate)
                        {
                            tab.Activate();
                            return;
                        }

                        index++;
                    }
                }
            }
        }
        public IEAccessible(IntPtr ieHandle, string tabCaptionToActivate)
        {
            AccessibleObjectFromWindow(GetDirectUIHWND(ieHandle), OBJID.OBJID_WINDOW, ref accessible);

            if (accessible == null) throw new Exception();

            var ieDirectUIHWND = new IEAccessible(ieHandle);

            foreach (IEAccessible accessor in ieDirectUIHWND.Children)
            {
                foreach (var child in accessor.Children)
                {
                    foreach (var tab in child.Children)
                    {
                        if (tab.Name == tabCaptionToActivate)
                        {
                            tab.Activate();
                            return;
                        }
                    }
                }
            }
        }
        private InfoItem GetActiveItemFromHandle(string processName, IntPtr handle)
        {
            try
            {
                if (processName == ProcessList.iexplore.ToString())
                {
                    #region IE

                    IEAccessible tabs = new IEAccessible();

                    string pageTitle = tabs.GetActiveTabCaption(handle);
                    string pageURL = tabs.GetActiveTabUrl(handle);

                    return new InfoItem
                    {
                        Title = pageTitle,
                        Uri = pageURL,
                        Type = InfoItemType.Web,
                    };

                    #endregion
                }
                else if (processName == ProcessList.firefox.ToString())
                {
                    #region FireFox

                    AutomationElement ff = AutomationElement.FromHandle(handle);

                    System.Windows.Automation.Condition condition1 = new PropertyCondition(AutomationElement.IsContentElementProperty, true);
                    System.Windows.Automation.Condition condition2 = new PropertyCondition(AutomationElement.ClassNameProperty, "MozillaContentWindowClass");
                    TreeWalker walker = new TreeWalker(new AndCondition(condition1, condition2));
                    AutomationElement elementNode = walker.GetFirstChild(ff);
                    ValuePattern valuePattern;

                    if (elementNode != null)
                    {
                        AutomationPattern[] pattern = elementNode.GetSupportedPatterns();

                        foreach (AutomationPattern autop in pattern)
                        {
                            if (autop.ProgrammaticName.Equals("ValuePatternIdentifiers.Pattern"))
                            {
                                valuePattern = elementNode.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;

                                string pageURL = valuePattern.Current.Value.ToString();
                                string pageTitle = GetActiveWindowText(handle);
                                pageTitle = pageTitle.Remove(pageTitle.IndexOf(" - Mozilla Firefox"));

                                return new InfoItem
                                {
                                    Title = pageTitle,
                                    Uri = pageURL,
                                    Type = InfoItemType.Web,
                                };
                            }
                        }
                    }

                    return null;

                    #endregion
                }
                else if (processName == "chrome")
                {
                    String pageURL = string.Empty;
                    String pageTitle = string.Empty;

                    IntPtr urlHandle = FindWindowEx(handle, IntPtr.Zero, "Chrome_AutocompleteEditView", null);
                    //IntPtr titleHandle = FindWindowEx(handle, IntPtr.Zero, "Chrome_WindowImpl_0", null);
                    IntPtr titleHandle = FindWindowEx(handle, IntPtr.Zero, "Chrome_WidgetWin_0", null);

                    const int nChars = 256;
                    StringBuilder Buff = new StringBuilder(nChars);

                    int length = SendMessage(urlHandle, WM_GETTEXTLENGTH, 0, 0);
                    if (length > 0)
                    {
                        //Get URL from chrome tab
                        SendMessage(urlHandle, WM_GETTEXT, nChars, Buff);
                        pageURL = Buff.ToString();

                        //Get the title
                        GetWindowText((int)titleHandle, Buff, nChars);
                        pageTitle = Buff.ToString();

                        return new InfoItem
                        {
                            Title = pageTitle,
                            Uri = pageURL,
                            Type = InfoItemType.Web,
                        };
                    }
                    else
                        return null;

                }
                else if (processName == ProcessList.OUTLOOK.ToString())
                {
                    #region Outlook

                    MS_Outlook.Application outlookApp;
                    MS_Outlook.MAPIFolder currFolder;
                    MS_Outlook.Inspector inspector;
                    MS_Outlook.MailItem mailItem;

                    outlookApp = (MS_Outlook.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Outlook.Application");
                    currFolder = outlookApp.ActiveExplorer().CurrentFolder;
                    inspector = outlookApp.ActiveInspector();

                    if (inspector == null)
                    {
                        mailItem = (MS_Outlook.MailItem)outlookApp.ActiveExplorer().Selection[1];
                    }
                    else
                    {
                        Regex regex = new Regex(@"\w* - Microsoft Outlook");
                        if (regex.IsMatch(GetActiveWindowText(handle)))
                        {
                            mailItem = (MS_Outlook.MailItem)outlookApp.ActiveExplorer().Selection[1];
                        }
                        else
                        {
                            mailItem = (MS_Outlook.MailItem)inspector.CurrentItem;
                        }
                    }

                    string subject = mailItem.Subject;
                    string entryID = mailItem.EntryID;

                    return new InfoItem
                    {
                        Title = subject,
                        Uri = entryID,
                        Type = InfoItemType.Email,
                    };

                    #endregion
                }
                else if (processName == ProcessList.WINWORD.ToString() ||
                    processName == ProcessList.EXCEL.ToString() ||
                    processName == ProcessList.POWERPNT.ToString() ||
                    processName == ProcessList.AcroRd32.ToString())
                {
                    #region Word, Excel, PPT, Adobe Reader

                    return null;

                    #endregion
                }
                else
                {
                    return null;
                }
            }
            catch (Exception)
            {
                return null;
            }
        }
Exemple #14
0
        private InfoItem GetActiveItemFromHandle(string processName, IntPtr handle)
        {
            try
            {
                if (processName == ProcessList.iexplore.ToString())
                {
                    #region IE

                    IEAccessible tabs = new IEAccessible();

                    string pageTitle = tabs.GetActiveTabCaption(handle);
                    string pageURL   = tabs.GetActiveTabUrl(handle);

                    return(new InfoItem
                    {
                        Title = pageTitle,
                        Uri = pageURL,
                        Type = InfoItemType.Web,
                    });

                    #endregion
                }
                else if (processName == ProcessList.firefox.ToString())
                {
                    #region FireFox

                    AutomationElement ff = AutomationElement.FromHandle(handle);

                    System.Windows.Automation.Condition condition1 = new PropertyCondition(AutomationElement.IsContentElementProperty, true);
                    System.Windows.Automation.Condition condition2 = new PropertyCondition(AutomationElement.ClassNameProperty, "MozillaContentWindowClass");
                    TreeWalker        walker      = new TreeWalker(new AndCondition(condition1, condition2));
                    AutomationElement elementNode = walker.GetFirstChild(ff);
                    ValuePattern      valuePattern;

                    if (elementNode != null)
                    {
                        AutomationPattern[] pattern = elementNode.GetSupportedPatterns();

                        foreach (AutomationPattern autop in pattern)
                        {
                            if (autop.ProgrammaticName.Equals("ValuePatternIdentifiers.Pattern"))
                            {
                                valuePattern = elementNode.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;

                                string pageURL   = valuePattern.Current.Value.ToString();
                                string pageTitle = GetActiveWindowText(handle);
                                pageTitle = pageTitle.Remove(pageTitle.IndexOf(" - Mozilla Firefox"));

                                return(new InfoItem
                                {
                                    Title = pageTitle,
                                    Uri = pageURL,
                                    Type = InfoItemType.Web,
                                });
                            }
                        }
                    }

                    return(null);

                    #endregion
                }
                else if (processName == "chrome")
                {
                    String pageURL   = string.Empty;
                    String pageTitle = string.Empty;

                    IntPtr urlHandle = FindWindowEx(handle, IntPtr.Zero, "Chrome_AutocompleteEditView", null);
                    //IntPtr titleHandle = FindWindowEx(handle, IntPtr.Zero, "Chrome_WindowImpl_0", null);
                    IntPtr titleHandle = FindWindowEx(handle, IntPtr.Zero, "Chrome_WidgetWin_0", null);

                    const int     nChars = 256;
                    StringBuilder Buff   = new StringBuilder(nChars);

                    int length = SendMessage(urlHandle, WM_GETTEXTLENGTH, 0, 0);
                    if (length > 0)
                    {
                        //Get URL from chrome tab
                        SendMessage(urlHandle, WM_GETTEXT, nChars, Buff);
                        pageURL = Buff.ToString();

                        //Get the title
                        GetWindowText((int)titleHandle, Buff, nChars);
                        pageTitle = Buff.ToString();

                        return(new InfoItem
                        {
                            Title = pageTitle,
                            Uri = pageURL,
                            Type = InfoItemType.Web,
                        });
                    }
                    else
                    {
                        return(null);
                    }
                }
                else if (processName == ProcessList.OUTLOOK.ToString())
                {
                    #region Outlook

                    MS_Outlook.Application outlookApp;
                    MS_Outlook.MAPIFolder  currFolder;
                    MS_Outlook.Inspector   inspector;
                    MS_Outlook.MailItem    mailItem;

                    outlookApp = (MS_Outlook.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Outlook.Application");
                    currFolder = outlookApp.ActiveExplorer().CurrentFolder;
                    inspector  = outlookApp.ActiveInspector();

                    if (inspector == null)
                    {
                        mailItem = (MS_Outlook.MailItem)outlookApp.ActiveExplorer().Selection[1];
                    }
                    else
                    {
                        Regex regex = new Regex(@"\w* - Microsoft Outlook");
                        if (regex.IsMatch(GetActiveWindowText(handle)))
                        {
                            mailItem = (MS_Outlook.MailItem)outlookApp.ActiveExplorer().Selection[1];
                        }
                        else
                        {
                            mailItem = (MS_Outlook.MailItem)inspector.CurrentItem;
                        }
                    }

                    string subject = mailItem.Subject;
                    string entryID = mailItem.EntryID;

                    return(new InfoItem
                    {
                        Title = subject,
                        Uri = entryID,
                        Type = InfoItemType.Email,
                    });

                    #endregion
                }
                else if (processName == ProcessList.WINWORD.ToString() ||
                         processName == ProcessList.EXCEL.ToString() ||
                         processName == ProcessList.POWERPNT.ToString() ||
                         processName == ProcessList.AcroRd32.ToString())
                {
                    #region Word, Excel, PPT, Adobe Reader

                    return(null);

                    #endregion
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }