开发者

Get object extension from AccessibleObjectFromWindow?

I managed to get the selected file in the current working folder from Windows Explorer using SystemAccessibleObject from http://mwinapi.sourceforge.net/

I want to get the filename with extension but if you enable "Hide extensions for known file types" then there will be only the filename. I'm stuck on this step.

My code:

SystemAccessibleObject currentWorkingWindow = SystemAccessibleObject.FromWindow(new SystemWindow(GetForegroundWindow()), AccessibleObjectID.OBJID_WINDOW).Children.Where(c => c.RoleString.Equals("client")).FirstOrDefault();

            if (null != currentWorkingWindow)
            {
                SystemWindow addressBar = currentWorkingWindow.Window.AllDescendantWindows.Where(w => w.ClassName.Equals("ComboBox")).FirstOrDefault();

                if (null != addressBar)
                {
                    string addressBarContent = addressBar.Content.LongDescription;

                    Match m = Regex.Match(addressBarContent, "Address \\[push button\\]\\n[A-Z]: \\n[A-Z]: ([A-Z]:\\\\[^/:*?<>|\"\\r\\n\\t]+)");

                    if (null != m || null != m.Groups[1])
                    {
                        SystemWindow currentListView = currentWorkingWindow.Window.AllDescendantWindows.Where(w => w.ClassName.Equals("SysListView32")).FirstOrDefault();

                        if (null != currentListView)
                        {
                            SystemAccessibleObject currentListViewItems = SystemAccessibleObject.FromWindow(currentListView, AccessibleObjectID.OBJID_WINDOW).Children.Where(c => c.RoleString.Equals("list")).FirstOrDefault();

                            if (null != currentListViewItems)
                            {
                                SystemAccessibleObject[] selectedItems = currentListViewItems.SelectedObjects;

                                string currentWorkingFolderPath = m.Groups[1].Value;

                                if (0 != selectedItems.Count())
                                {
                                    string[] fileNames = currentListView.Content.PropertyList.Select(p => p.Value).ToArray();
                                }
                            }
                        }

                        currentListView = null;
                    }

                    m = null;
                }

                addressBar = null;
 开发者_运维问答           }

            currentWorkingWindow = null;

Any helps would be appreciated!


I do not know anything about the SystemAccessibleObject but why not approach this from a different angle. You know the directory and the file name without extension, so you could use the Directory.GetFiles and "find" your file with extension.

foreach (string fileName in fileNames)
{
  string[] matchedFiles = Directory.GetFiles(currentWorkingFolderPath, fileName+"*");
  etc...
}


I didn't figure out the perfect solution yet but using Clipboard is not a very bad idea.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜