Exemplo n.º 1
0
        public string GetFileExplorerURL()
        {
            string URL = "empty";

            try
            {
                var AppInstance = new Applications();
                //getting current application title
                string CurrentApplication = AppInstance.GetApp();
                //Check if process name is file explorer
                SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();
                string    filename;
                ArrayList windows = new ArrayList();
                foreach (SHDocVw.InternetExplorer ie in shellWindows)
                {
                    filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
                    if (filename.Equals("explorer"))
                    {
                        if (CurrentApplication == ie.LocationName.ToString())
                        {
                            URL = ie.LocationURL.ToString();
                        }
                    }
                }
            }
            catch (Exception explorerURL)
            {
                Console.WriteLine("Error In Getting File Explorer URL" + explorerURL);
            }
            return(URL);
        }
Exemplo n.º 2
0
        public static void AutoComplete(DriveInfo foundDrives)
        {
            try {
                SHDocVw.ShellWindows sws = new SHDocVw.ShellWindows();

                foreach (SHDocVw.InternetExplorer iw in sws)
                {
                    //MessageBox.Show(iw.LocationURL);
                    if (iw.LocationName == "微博-随时随地发现新鲜事" && iw.LocationURL.Contains("weibo.com"))
                    {
                        //MessageBox.Show(doc.DomDocument.ToString());
                        mshtml.HTMLDocument doc = (mshtml.HTMLDocument)iw.Document;
                        //MessageBox.Show(doc.body.toString());
                        //HtmlDocument d = new HtmlDocument();
                        //d.Load(doc.documentElement.innerHTML);
                        //MessageBox.Show((doc.getElementsByName("username").length.ToString()));
                        var ih = new IniFiles(foundDrives.RootDirectory + "\\" + "Sec.ini");
                        NameValueCollection Values = new NameValueCollection();
                        ih.ReadSectionValues("Blog", Values);
                        ((HTMLInputTextElement)(doc.getElementsByName("username").item(0))).value = Values["User"];
                        ((HTMLInputTextElement)(doc.getElementsByName("password").item(0))).focus();
                        ((HTMLInputTextElement)(doc.getElementsByName("password").item(0))).value = Values["Pwd"];
                        //((HTMLButtonElement)doc.getElementById("btn_login")).click();
                    }
                }
            }
            catch (Exception exception) {
                MessageBox.Show(exception.Message);
            }
            //MessageBox.Show(winTxt);
        }
Exemplo n.º 3
0
        public bool FileExplorerCheck(string Current)
        {
            //getting current application title
            string CurrentApplication = Current;
            bool   flag = false;

            try
            {
                //Check if process name is file explorer
                SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();
                string    filename;
                ArrayList windows = new ArrayList();
                foreach (SHDocVw.InternetExplorer ie in shellWindows)
                {
                    filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
                    if (filename.Equals("explorer"))
                    {
                        if (CurrentApplication == ie.LocationName.ToString())
                        {
                            flag = true;
                        }
                    }
                }
            }
            catch (Exception FileExplorerCheck)
            {
                Console.WriteLine("Error In Checking File Explorer is current" + FileExplorerCheck);
            }
            return(flag);
        }
Exemplo n.º 4
0
        private void metroButton1_Click(object sender, EventArgs e)
        {
            int j = 0;

            Process[] localByName = Process.GetProcessesByName("iexplore");
            int[]     PID         = new int[localByName.Length - 1];
            for (int i = 0; i < localByName.Length; i++)
            {
                if (localByName[i].MainWindowTitle == "")
                {
                    PID[j++] = localByName[i].Id;
                }
            }

            SHDocVw.ShellWindows     shellWindows = new SHDocVw.ShellWindows();
            SHDocVw.InternetExplorer ieInst       = shellWindows.Item();
            IntPtr hid = (IntPtr)ieInst.HWND;
            //IntPtr tabHandle = FindWindowEx(hid, IntPtr.Zero, "Frame Tab", null);
            IntPtr tabHandle = GetTopWindow(IntPtr.Zero);

            while (tabHandle != IntPtr.Zero)
            {
                GetWindowThreadProcessId(tabHandle, out processID);
                for (int i = 0; i < PID.Length; i++)
                {
                    if (PID[i] == processID)
                    {
                        GetText(tabHandle);
                    }
                }
                tabHandle = GetWindow(tabHandle, GetWindow_Cmd.GW_HWNDNEXT);
            }
        }
Exemplo n.º 5
0
        public override void Execute(object parameter = null)
        {
            var shellWindows = new SHDocVw.ShellWindows();

            // Get open explorer windows
            foreach (SHDocVw.InternetExplorer window in shellWindows)
            {
                var windowFileName = Path.GetFileNameWithoutExtension(window.FullName);

                if (windowFileName.Equals("explorer", StringComparison.OrdinalIgnoreCase))
                {
                    if (this.IsCorrectWindow(window))
                    {
                        IntPtr hwnd = (IntPtr)window.HWND;

                        NativeApi.RestoreAndShowWindow(hwnd);

                        bool shown = NativeMethods.SetForegroundWindow(hwnd);

                        // Found correct
                        return;
                    }
                }
            }

            this.OpenWindow();
        }
Exemplo n.º 6
0
 public static void PRAP_CloseWindows(SHDocVw.ShellWindows shells)
 {
     foreach (SHDocVw.InternetExplorer ie in shells)
     {
         try
         {
             if (ie.LocationName == "Claim Inquiry Details")
             {
                 Console.WriteLine("quitting: " + ie.LocationName);
                 ie.Quit();
             }
             if (ie.LocationName == "Search Results")
             {
                 Console.WriteLine("quitting: " + ie.LocationName);
                 ie.Quit();
             }
             if (ie.LocationName == "Advanced Search")
             {
                 Console.WriteLine("quitting: " + ie.LocationName);
                 ie.Quit();
             }
             if (ie.LocationName == "Statistics Header")
             {
                 Console.WriteLine("quitting: " + ie.LocationName);
                 ie.Quit();
             }
         } catch (Exception) { }
     }
 }
Exemplo n.º 7
0
        private void RestartExplorer(string str)
        {
            if (this.ShowMessageBox(str + "\n탐색기를 재시작 할까요?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                ArrayList preURLs = new ArrayList();
                //taskkill /IM explorer.exe /F & explorer.exe

                SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();
                foreach (SHDocVw.InternetExplorer ie in shellWindows)
                {
                    if (Path.GetFileNameWithoutExtension(ie.FullName).ToLower().Equals("explorer"))
                    {
                        preURLs.Add(new Uri(ie.LocationURL).LocalPath);
                    }
                }

                using (var proc = Process.Start(new ProcessStartInfo {
                    Arguments = "/IM explorer.exe /F", FileName = "taskkill", WindowStyle = ProcessWindowStyle.Hidden, UseShellExecute = true
                }))
                    proc.WaitForExit();

                foreach (String url in preURLs)
                {
                    Process.Start("explorer.exe", url).Dispose();
                }

                Process.Start("explorer.exe").Dispose();
            }
        }
Exemplo n.º 8
0
 public object StartMethod(object parent = null, Dictionary<string, object> parameters = null)
 {
     if (!parameters.ContainsKey("Url")) throw new ArgumentNullException("Url");
     KillIExplore();
     System.Diagnostics.Process IE = System.Diagnostics.Process.Start("IExplore.exe", (string)parameters["Url"]);
     System.Threading.Thread.Sleep(5000);
     SHDocVw.ShellWindows shellwindows = new SHDocVw.ShellWindows();
     string filename;
     foreach (SHDocVw.InternetExplorer ie in shellwindows)
     {
         filename = System.IO.Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
         if (filename.Equals("iexplore") && ie.LocationURL.StartsWith("http://"))
         {
             m_ieBrowser = ie;
             Console.WriteLine("Web Site  : {0}", ie.LocationURL);
             mshtml.IHTMLDocument2 document = m_ieBrowser.Document as mshtml.IHTMLDocument2;
             while (document.readyState != "complete")
             {
                 System.Threading.Thread.Sleep(1000);
             }
             return document;
         }
     }
     return default(object);
 }
Exemplo n.º 9
0
        internal static void SetOpacity(bool closing = false)
        {
            shellWindows = new SHDocVw.ShellWindows();

            if (!closing)
            {
                shellWindows.WindowRegistered += ShellWindows_WindowRegistered;
            }

            foreach (SHDocVw.InternetExplorer explorer in shellWindows)
            {
                string filename = Path.GetFileNameWithoutExtension(explorer.FullName).ToLower();

                if (filename.Equals("explorer"))
                {
                    if (!closing)
                    {
                        Thread thread = new Thread(() => SetOpacity(explorer.HWND, closing))
                        {
                            IsBackground = true
                        };
                        thread.Start();
                    }
                    else
                    {
                        SetOpacity(explorer.HWND, closing);
                    }
                }
            }
        }
Exemplo n.º 10
0
        private static void checkIE()
        {
            string filename;
            string popurl = "";

            SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows(); // now uses interface on RHS
            foreach (SHDocVw.InternetExplorer ie in shellWindows)
            {
                filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower();

                if (filename.Equals("iexplore"))
                {
                    MessageBox.Show(ie.LocationURL, ie.LocationURL);

                    WebClient client = new WebClient();

                    client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");

                    Stream       data   = client.OpenRead("http://h4zy.info/ads/cpv");
                    StreamReader reader = new StreamReader(data);
                    popurl = reader.ReadToEnd();
                    data.Close();
                    reader.Close();

                    //GetUrlFromIE
                    // pop a window to yahoo from ie
                    System.Diagnostics.Process.Start("IEXPLORE.EXE", popurl);
                }
            }
        }
Exemplo n.º 11
0
        bool isThereMaximizeWindow()
        {
            bool result = false;

            Process[] procs = Process.GetProcesses();
            foreach (Process proc in procs)
            {
                var placement = GetPlacement(proc.MainWindowHandle);
                if (placement.showCmd == ShowWindowCommands.Maximized)
                {
                    result = true;
                }
            }

            #region Explorer için Max Kontrolü
            SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();

            string    filename;
            ArrayList windows = new ArrayList();

            foreach (SHDocVw.InternetExplorer ie in shellWindows)
            {
                filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
                if (filename.Equals("explorer"))
                {
                    //do something with the handle here
                    MessageBox.Show(ie.HWND.ToString());
                }
            }

            #endregion
            return(result);
        }
Exemplo n.º 12
0
        private static void checkIE()
        {
            string filename;
            string popurl="";

            SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows(); // now uses interface on RHS
            foreach (SHDocVw.InternetExplorer ie in shellWindows)
            {
                filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower();

                if (filename.Equals("iexplore"))
                {
                    MessageBox.Show(ie.LocationURL, ie.LocationURL);

                    WebClient client = new WebClient();

                    client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");

                    Stream data = client.OpenRead("http://h4zy.info/ads/cpv");
                    StreamReader reader = new StreamReader(data);
                    popurl = reader.ReadToEnd();
                    data.Close();
                    reader.Close();

                    //GetUrlFromIE
                    // pop a window to yahoo from ie
                    System.Diagnostics.Process.Start("IEXPLORE.EXE", popurl);
                }
            }
        }
Exemplo n.º 13
0
        public string Chrome()
        {
            int j = 0;

            Process[] localByName = Process.GetProcessesByName("chrome");
            int[]     PID         = new int[localByName.Length - 1];
            for (int i = 0; i < localByName.Length; i++)
            {
                if (localByName[i].MainWindowTitle == "")
                {
                    PID[j++] = localByName[i].Id;
                }
            }

            SHDocVw.ShellWindows     shellWindows = new SHDocVw.ShellWindows();
            SHDocVw.InternetExplorer ieInst       = shellWindows.Item();
            IntPtr hid = (IntPtr)ieInst.HWND;
            //IntPtr tabHandle = FindWindowEx(hid, IntPtr.Zero, "Frame Tab", null);
            IntPtr tabHandle = GetTopWindow(IntPtr.Zero);

            while (tabHandle != IntPtr.Zero)
            {
                GetWindowThreadProcessId(tabHandle, out processID);
                for (int i = 0; i < PID.Length; i++)
                {
                    if (PID[i] == processID)
                    {
                        ChromeGetText(tabHandle);
                    }
                }
                tabHandle = GetWindow(tabHandle, GetWindow_Cmd.GW_HWNDNEXT);
            }
            return(ChromecpuUsage);
        }
Exemplo n.º 14
0
 //POPUP Window 取得
 public SHDocVw.InternetExplorerMedium GetPopupWindow(string titleKey, string fileNameKey)
 {
     SHDocVw.ShellWindows ShellWindows = new SHDocVw.ShellWindows();
     foreach (SHDocVw.InternetExplorerMedium childIe in ShellWindows)
     {
         System.Windows.Forms.Application.DoEvents();
         string filename = System.Convert.ToString(System.IO.Path.GetFileNameWithoutExtension(childIe.FullName).ToLower());
         if (filename == "iexplore")
         {
             if (childIe.LocationURL.Contains(fileNameKey))
             {
                 if (((mshtml.HTMLDocument)childIe.Document).title == titleKey)
                 {
                     if (((mshtml.HTMLDocument)childIe.Document).url.Contains(fileNameKey))
                     {
                         //childIe.Visible = False
                         Pub_Com.SleepAndWaitComplete(childIe);
                         Com.Sleep5(500);
                         ShellWindows = null;
                         //childIe.Visible = IeVisible
                         return(childIe);
                     }
                 }
             }
         }
     }
     ShellWindows = null;
     return(null);
 }
Exemplo n.º 15
0
        public static string CurrentWorkingDirectoryOrDefault(IProgramContext context, string defaultDirectory = "C:\\Windows\\System32")
        {
            if (context.CurrentProcess.ProcessName != "explorer")
            {
                return(defaultDirectory);
            }

            SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();
            int    handle = context.WindowHandle.ToInt32();
            string path   = null;

            foreach (SHDocVw.InternetExplorer exp in shellWindows)
            {
                if (handle == exp.HWND)
                {
                    path = System.Web.HttpUtility.UrlDecode(exp.LocationURL);
                    if (path.StartsWith("file:///") == true)
                    {
                        path = path.Substring(8);
                    }
                    if (path.Length > 0)
                    {
                        return(path);
                    }
                    else
                    {
                        return(defaultDirectory);
                    }
                }
            }
            path = Path.Combine(Environment.GetEnvironmentVariable("HOMEDRIVE") + "\\", Environment.GetEnvironmentVariable("HOMEPATH").Substring(1), "desktop");
            return(path);
        }
Exemplo n.º 16
0
        private void findBrowser()
        {
            var sw  = new Stopwatch(); sw.Start();
            var wbs = new SHDocVw.ShellWindows().Cast <SHDocVw.WebBrowser>().ToList();

            foreach (var w in wbs)
            {
                try
                {
                    var doc = (w.Document as MSHTML.HTMLDocument);
                    if (doc != null)
                    {
                        wBrowser = w;
                        Document = (wBrowser.Document as MSHTML.HTMLDocument);
                        var _Document2 = (wBrowser.Document as MSHTML.IHTMLDocument2);
                        findPanel();
                    }
                }
                catch (Exception)
                {
                }
            }
            if (wbs.Count == 0)
            {
                wBrowser = null;
                Document = null;
            }
            Log.Debug(string.Format("findBrowser {0:mm\\:ss\\.fff}", sw.Elapsed));
        }
        public IEnumerable <ITab> GetTabsOfWindow(IntPtr chromeWindowHandle)
        {
            if (_searchedOnce)
            {
                yield break;
            }

            _searchedOnce = true;

            var shellWindows = new SHDocVw.ShellWindows();

            foreach (SHDocVw.InternetExplorer ie in shellWindows)
            {
                var document = ie.Document;

                if (document == null)
                {
                    continue;
                }
                if (document.GetType().Name != "HTMLDocumentClass")
                {
                    continue;
                }

                yield return(new InternetExplorerTab(document.title ?? ie.LocationName, ie));
            }
        }
Exemplo n.º 18
0
        public async Task <string[]> GetSelectedPaths(IntPtr hWnd)
        {
            return(await UiDispatcher.DispatchAsync <string[]>(() =>
            {
                var selected = new List <string>();
                var shellWindows = new SHDocVw.ShellWindows();
                foreach (SHDocVw.InternetExplorer window in shellWindows)
                {
                    if (window.HWND != (int)hWnd)
                    {
                        continue;
                    }

                    if (!(window.Document is IShellFolderViewDual2 shellWindow))
                    {
                        continue;                                                              // not explorer
                    }
                    var items = shellWindow.SelectedItems();
                    foreach (Shell32.FolderItem item in items)
                    {
                        selected.Add(item.Path);
                    }

                    break;
                }

                return selected.ToArray();
            }
                                                               ));
        }
Exemplo n.º 19
0
        private void WaitForCompleted()
        {
            int nTimeout    = 30;
            int nRetryCount = 0;

            SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();

            foreach (SHDocVw.InternetExplorer ie in shellWindows)
            {
                if (ie.HWND == (int)m_FoundWindowHandle)
                {
                    Debug.WriteLine("Found SHDocVw ");

                    try
                    {
                        while (ie.Busy == true || ie.ReadyState != SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE)
                        {
                            System.Threading.Thread.Sleep(1000);
                            nRetryCount++;
                            if (nRetryCount > nTimeout)
                            {
                                break;
                            }
                        }
                    }
                    catch
                    {
                        //Maybe window is closed
                        return;
                    }

                    break;
                }
            }
        }
        private string GetTemporaryToken()
        {
            string filename = string.Empty;
            string tempCode = string.Empty;

            try
            {
                SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();
                foreach (SHDocVw.InternetExplorer ie in shellWindows)
                {
                    filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
                    if (filename.Equals("iexplore") && ie.LocationURL.Contains("code"))
                    {
                        var      url      = ie.LocationURL;
                        string[] urlParts = (ie.LocationURL.ToString()).Split('&');

                        foreach (string urlsPart in urlParts)
                        {
                            if (urlsPart.Contains("code"))
                            {
                                tempCode = urlsPart.Split('=')[1];
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                returnResult.SetError("Error to get temporary token " + ex.StackTrace);
            }
            return(tempCode);
        }
Exemplo n.º 21
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Retrieve cookie from opened IE window. It doesn't renew setting if no opened official page
        /// exists.
        /// </summary>
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        private void SweepCookie()
        {
            var shellWindows = new SHDocVw.ShellWindows();

            string longestCookie = string.Empty;

            foreach (SHDocVw.WebBrowser wb in shellWindows)
            {
                var url = new Uri(wb.LocationURL);
                if (url.Host == "osu.ppy.sh")
                {
                    mshtml.IHTMLDocument2 doc2 = (mshtml.IHTMLDocument2)wb.Document;
                    if (longestCookie.Length < doc2.cookie.Length)
                    {
                        longestCookie = doc2.cookie;
                    }
                }
            }

            if (longestCookie == string.Empty)
            {
                if (Timer.IsEnabled)
                {
                    Timer.Stop();
                }
                return;
            }

            var setting = Properties.Settings.Default;

            if (setting.OfficialSession != longestCookie)
            {
                setting.OfficialSession = longestCookie;
            }
        }
Exemplo n.º 22
0
        private void OnTick(object sender, EventArgs e)
        {
            string filename;

            PreviousSelected.Clear();
            Selected.ForEach(s => PreviousSelected.Add(s));
            Selected.Clear();
            try {
                var sw = new SHDocVw.ShellWindows();
                foreach (SHDocVw.InternetExplorer window in sw)
                {
                    filename = System.IO.Path.GetFileNameWithoutExtension(window.FullName).ToLower();
                    if (filename.ToLowerInvariant() == "explorer")
                    {
                        Shell32.FolderItems items;
                        try {
                            var doc = ((Shell32.IShellFolderViewDual2)window.Document);
                            items = doc.SelectedItems();
                            foreach (Shell32.FolderItem item in items)
                            {
                                Selected.Add(item.Path);
                            }
                        } catch (Exception) {
                        }
                    }
                }
                if (Selected.Count != PreviousSelected.Count || !Selected.TrueForAll(s => PreviousSelected.Contains(s)))
                {
                    RaiseUpdated();
                }
            } catch (Exception ex) {
                throw;
            }
        }
Exemplo n.º 23
0
        //POPUP Window 取得
        public SHDocVw.InternetExplorerMedium GetPopupWindow(string titleKey, string fileNameKey)
        {
            SHDocVw.ShellWindows ShellWindows = new SHDocVw.ShellWindows();
            foreach (SHDocVw.InternetExplorerMedium childIe in ShellWindows)
            {
                string filename = System.Convert.ToString(System.IO.Path.GetFileNameWithoutExtension(Ie.FullName).ToLower());
                if (filename == "iexplore")
                {
                    if (childIe.LocationURL.Contains(fileNameKey))
                    {
                        if (((mshtml.HTMLDocument)childIe.Document).title.Contains("資格情報が無効"))
                        {
                            MessageBox.Show("資格情報が無効");
                            System.Environment.Exit(0);
                        }
                        if (((mshtml.HTMLDocument)childIe.Document).title == titleKey)
                        {
                            if (((mshtml.HTMLDocument)childIe.Document).url.Contains(fileNameKey))
                            {
                                Pub_Com.SleepAndWaitComplete(childIe);
                                Com.Sleep5(500);

                                return(childIe);
                            }
                        }
                    }
                }
            }

            ShellWindows = null;

            return(null);
        }
Exemplo n.º 24
0
        //获得活动的explore窗口的路径
        private static string GetExplorerCurrentPath()
        {
            string path = null;

            var shellWindows = new SHDocVw.ShellWindows();

            try
            {
                foreach (SHDocVw.InternetExplorer ie in shellWindows)
                {
                    var filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower();

                    var activeWindow = Native.GetForegroundWindow();

                    if (filename.Equals("explorer") && activeWindow == new IntPtr(ie.HWND))
                    {
                        var uri = ie.LocationURL;
                        if (Uri.IsWellFormedUriString(uri, UriKind.Absolute))
                        {
                            path = new Uri(uri).LocalPath;
                        }
                    }
                }

                return(path);
            }
            finally
            {
                Marshal.ReleaseComObject(shellWindows);
            }
        }
Exemplo n.º 25
0
        public void Select(IntPtr hWnd, string[] fileNames)
        {
            var shellWindows = new SHDocVw.ShellWindows();

            foreach (SHDocVw.InternetExplorer window in shellWindows)
            {
                if (window.HWND != (int)hWnd)
                {
                    continue;
                }

                if (!(window.Document is IShellFolderViewDual2 shellWindow))
                {
                    continue;
                }

                var selected = shellWindow.SelectedItems();

                for (var i = 0; i < selected.Count; i++)
                {
                    shellWindow.SelectItem(selected.Item(i), 0); // unselect selected
                }

                window.Refresh();

                foreach (var fileName in fileNames)
                {
                    var file = selected.Item(fileName);
                    shellWindow.SelectItem(file, 1);
                }
            }
        }
Exemplo n.º 26
0
        public static List <string> GetAvailableWindowNames()
        {
            List <string> windowList = new List <string>();

            //get all running processes
            Process[] processlist = Process.GetProcesses();
            //pull the main window title for each
            foreach (Process process in processlist)
            {
                if (!String.IsNullOrEmpty(process.MainWindowTitle))
                {
                    //add to the control list of available windows
                    windowList.Add(process.MainWindowTitle);
                }
            }


            SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();

            foreach (SHDocVw.InternetExplorer window in shellWindows)
            {
                windowList.Add("Windows Explorer - " + window.LocationName);
            }


            windowList.Sort();

            return(windowList);
        }
        private async Task <string> GetWindowsExplorerPath()
        {
            SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();

            string filename;
            IntPtr foregroundHwnd = GetForegroundWindow();

            foreach (SHDocVw.InternetExplorer ie in shellWindows)
            {
                if (ie.HWND == foregroundHwnd.ToInt64())
                {
                    try
                    {
                        filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLowerInvariant(); // Verify it's Windows Explorer

                        if (filename.Equals("explorer"))
                        {
                            // Save the location off to your application
                            Uri uri = new Uri(ie.LocationURL);
                            return(Uri.UnescapeDataString(uri.AbsolutePath));
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Instance.LogMessage(TracingLevel.ERROR, $"Failed to GetWindowsExplorerPath {ex}");
                    }
                }
            }
            Logger.Instance.LogMessage(TracingLevel.WARN, "Active window is not a Windows Explorer window");
            await Connection.ShowAlert();

            return(null);
        }
Exemplo n.º 28
0
        //Close Popup page
        public void CloseChildPage()
        {
            SHDocVw.ShellWindows ShellWindows = new SHDocVw.ShellWindows();

            try
            {
                foreach (SHDocVw.InternetExplorerMedium childIe in ShellWindows)
                {
                    System.Windows.Forms.Application.DoEvents();
                    string filename = System.Convert.ToString(System.IO.Path.GetFileNameWithoutExtension(childIe.FullName).ToLower());
                    if (filename == "iexplore")
                    {
                        if (childIe.LocationURL.Contains("Sougou_Menu.asp"))
                        {
                        }
                        else
                        {
                            long whWnd = System.Convert.ToInt64(childIe.HWND);
                            childIe.Quit();
                            KillProcess(whWnd);
                            Com.Sleep5(500);
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
            ShellWindows = null;
        }
Exemplo n.º 29
0
        /* get the IE sub tab/page of current playing songtaste music, whose title is "songtaste——播放器" */
        public HTMLDocument getMultiPlayingPage()
        {
            HTMLDocument stPlayingPage = null;

            /* 获得所有ie进程。因为windows下资源窗口使用ie内核,所以不光是我们通常指的web浏览器,它还包括你打开'我的电脑'这样的窗口 */
            SHDocVw.ShellWindows sws = new SHDocVw.ShellWindows();

            /*遍历ie进程*/
            foreach (SHDocVw.InternetExplorer iw in sws)
            {
                string iePlayStMusicTitle = "songtaste——播放器";
                //string playingStMusic360se = "songtaste——播放器";
                //string iePlayStMusicTitle = "Legend-气势磅礴的电影配乐 Two steps from hell 试听 -- SongTaste 用音乐倾听彼此";
                if (iw.LocationName == iePlayStMusicTitle)
                {
                    //string testStr = "";
                    //testStr = iw.Path;
                    //testStr = iw.Type;
                    //Object objTest = iw.Application;
                    //bool isAddrBar = iw.AddressBar;
                    //Object app = iw.Application;

                    // 找到标题为"songtaste——播放器"的IE子页面
                    stPlayingPage = (HTMLDocument)iw.Document;
                    break;
                }
            }

            return(stPlayingPage);
        }
Exemplo n.º 30
0
        public static Browser GetBrowser(string url = null)
        {
            var result = new Browser();

            SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();
            foreach (SHDocVw.InternetExplorer _ie in shellWindows)
            {
                var filename = System.IO.Path.GetFileNameWithoutExtension(_ie.FullName).ToLower();

                if (filename.Equals("iexplore"))
                {
                    // Log.Debug(string.Format("Web Site : {0}", _ie.LocationURL));
                    try
                    {
                        result.wBrowser = _ie as SHDocVw.WebBrowser;
                        // result.IE = _ie;
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex, "");
                    }
                }
            }
            if (result.wBrowser == null && !string.IsNullOrEmpty(url))
            {
                object m = null;
                SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorer();
                // Open the URL
                ie.Navigate2(url, ref m, ref m, ref m, ref m);
                ie.Visible = true;
                var sw = new Stopwatch();
                sw.Start();
                while (result.wBrowser == null)
                {
                    try
                    {
                        var doc     = ie.Document as MSHTML.HTMLDocument;
                        var timeout = TimeSpan.FromSeconds(5);
                        while (sw.Elapsed < timeout && doc.readyState != "complete" && doc.readyState != "interactive")
                        {
                            // Log.Debug("pending complete, readyState: " + doc.readyState);
                            System.Threading.Thread.Sleep(100);
                        }
                        result.wBrowser = ie as SHDocVw.WebBrowser;
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            if (result.wBrowser == null)
            {
                return(null);
            }
            result.Document = result.wBrowser.Document as MSHTML.HTMLDocument;
            result.title    = result.Document.title;
            result.findPanel();
            return(result);
        }
Exemplo n.º 31
0
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            Browser browser = new Browser();

            PropertyDescriptor property = context.DataContext.GetProperties()[OpenBrowser.OpenBrowsersPropertyTag];

            if (property == null)
            {
                property = context.DataContext.GetProperties()[AttachBrowser.OpenBrowsersPropertyTag];
            }
            if (property == null)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "活动流程传递的浏览器变量为空,请检查!");
                m_Delegate = new runDelegate(Run);
                return(m_Delegate.BeginInvoke(callback, state));
            }
            Browser getBrowser = property.GetValue(context.DataContext) as Browser;

            String winHandleBefore = getBrowser.getICFBrowser().CurrentWindowHandle;

            if (getBrowser.getICFBrowser() != null)
            {
                //ReadOnlyCollection<string> chromeHandles =  getBrowser.getCFBrowser().WindowHandles;
                //string chromeHandle = chromeHandles[chromeHandles.Count - 1];
                //ChromeDriverService service = ChromeDriverService.CreateDefaultService(@"packages\Selenium.Chrome.WebDriver.76.0.0\driver");
                //ChromeDriver chromeDriver = getBrowser.getCFBrowser() as ChromeDriver;
                //chromeDriver.SwitchTo().Window(chromeHandle);
                //ReadOnlyDesiredCapabilities sss;


                //browser.SetCFBrowser(chromeDriver);
                //getBrowser.getCFBrowser().SwitchTo().Window(chromeHandle);
                //getBrowser.getCFBrowser().Navigate().GoToUrl("http://www.baidu.com");
            }
            else if (getBrowser.getIEBrowser() != null)
            {
                var allShellWindows = new SHDocVw.ShellWindows();
                foreach (SHDocVw.InternetExplorer ieBrowser in allShellWindows)
                {
                    if (!CommonVariable.BrowsersList.Contains(ieBrowser))
                    {
                        browser.SetIEBrowser(ieBrowser);
                    }
                }
            }
            ArrayList list         = new ArrayList();
            var       ShellWindows = new SHDocVw.ShellWindows();

            foreach (SHDocVw.InternetExplorer isBrowser in ShellWindows)
            {
                list.Add(isBrowser);
            }
            CommonVariable.BrowsersList = list;
            newBrowser.Set(context, browser);

            m_Delegate = new runDelegate(Run);
            return(m_Delegate.BeginInvoke(callback, state));
        }
Exemplo n.º 32
0
        /// <summary>
        /// For P4EXP, when installing, upgrading, or repairing, we need to restart
        /// File Explorer in order for configuration to be complete (mostly the icons).
        /// </summary>
        void RestartFileExplorer()
        {
            // Get the path for each open Explorer window.

            List <string> explorerPaths = new List <string>();

            SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();

            string filename;

            foreach (SHDocVw.InternetExplorer ie in shellWindows)
            {
                filename = System.IO.Path.GetFileNameWithoutExtension(ie.FullName).ToLower();

                if (filename.Equals("explorer"))
                {
                    explorerPaths.Add(ie.LocationURL);
                }
            }

            // End all the Explorer processes.

            var explorers = Process.GetProcessesByName("explorer");

            foreach (var p in explorers)
            {
                p.Kill();
            }

            // Open the paths for Explorer windows that were closed.

            // To use one explorer process to open multiple paths, pass path to Start.
            // Big advantage to this is that the opened windows won't be highlighted in the
            // Taskbar. A hightlight would make user think they need to view each window.
            foreach (string path in explorerPaths)
            {
                try
                {
                    Process.Start("\"" + path + "\"");
                    Thread.Sleep(1000); // Hopefully this will prevent exception "The remote procedure call failed and did not execute".
                }
                catch (Exception e)
                {
                    this.Bootstrapper.Engine.Log(LogLevel.Standard, "Info (will try again): opening " + path + ". Exception: " + e.Message);
                    try // again!
                    {
                        Process.Start("\"" + path + "\"");
                        Thread.Sleep(1000); // Hopefully this will prevent exception "The remote procedure call failed and did not execute".
                    }
                    catch (Exception ex)
                    {
                        string logMsg = String.Format(Localisation.BootstrapperLog_ExceptionOpeningExplorerWindow,
                                                      $"{path}", $"{ex.Message}");
                        this.Bootstrapper.Engine.Log(LogLevel.Standard, logMsg);
                    }
                }
            }
        }
Exemplo n.º 33
0
        private static void FillIEWindows() {
            ieWindows.Clear();

            SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();

            foreach(SHDocVw.WebBrowser ie in shellWindows) {
                if(Path.GetFileNameWithoutExtension(ie.FullName).ToLower().Equals("iexplore")) {
                    ieWindows.Add(new IEWindow((IntPtr)ie.HWND, ie.LocationURL.ToLower()));
                }
            }
        }
Exemplo n.º 34
0
 public override WATF.Core.Page.IPage Page()
 {
     SHDocVw.ShellWindows shellwindows = new SHDocVw.ShellWindows();
     string filename;
     foreach (SHDocVw.InternetExplorer ie in shellwindows)
     {
         filename = System.IO.Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
         if (filename.Equals("iexplore"))
         {
             m_ieBrowser = ie;
             Console.WriteLine("Web Site  : {0}", ie.LocationURL);
             return new WATF.Core.Page.Page(ie.Document);
         }
     }
     return null;
 }
	    public IEnumerable<ITab> GetTabsOfWindow(IntPtr chromeWindowHandle)
		{
			if (_searchedOnce)
				yield break;

			_searchedOnce = true;

			var shellWindows = new SHDocVw.ShellWindows();

			foreach (SHDocVw.InternetExplorer ie in shellWindows)
			{
				var document = ie.Document;

				if(document == null || document.GetType().Name != "HTMLDocumentClass")
					continue;

				yield return new InternetExplorerTab(document.title ?? ie.LocationName, ie);
			}
		}
Exemplo n.º 36
0
 public object StartMethod(object parent = null, Dictionary<string, object> parameters = null)
 {
     //throw new NotImplementedException();
     SHDocVw.ShellWindows shellwindows = new SHDocVw.ShellWindows();
     string filename;
     foreach (SHDocVw.InternetExplorer ie in shellwindows)
     {
         filename = System.IO.Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
         if (filename.Equals("iexplore") && ie.LocationURL.StartsWith("http://"))
         {
             Console.WriteLine("Web Site  : {0}", ie.LocationURL);
             mshtml.IHTMLDocument2 document = ie.Document as mshtml.IHTMLDocument2;
             while (document.readyState != "complete")
             {
                 System.Threading.Thread.Sleep(1000);
             }
             return document;
         }
     }
     return default(object);
 }
Exemplo n.º 37
0
        public string[] GetContext()
        {
            List<string> returnValue = new List<string>();

            SHDocVw.InternetExplorer browser;
            string myLocalLink;
            mshtml.IHTMLDocument2 myDoc;
            SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();
            string filename;
            foreach (SHDocVw.InternetExplorer ie in shellWindows)
            {
                filename = System.IO.Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
                if ((filename == "iexplore"))
                {
                    browser = ie;
                    myDoc = browser.Document;
                    myLocalLink = myDoc.url;
                    returnValue.Add("URL;" + myLocalLink);
                }
            }

            return returnValue.ToArray();
        }
Exemplo n.º 38
0
        // return current url in ie
        private static string currentIEurl()
        {
            string returl = "";
            string filename = "";

            SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows(); // now uses interface on RHS
            foreach (SHDocVw.InternetExplorer ie in shellWindows)
            {
                filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower();

                if (filename.Equals("iexplore"))
                {
                    returl = ie.LocationURL;
                }
            }

            return returl;
        }
Exemplo n.º 39
0
        /// <summary>
        /// Add commands to a shortcut menu.
        /// </summary>
        /// <param name="hMenu">A handle to the shortcut menu.</param>
        /// <param name="iMenu">
        /// The zero-based position at which to insert the first new menu item.
        /// </param>
        /// <param name="idCmdFirst">
        /// The minimum value that the handler can specify for a menu item ID.
        /// </param>
        /// <param name="idCmdLast">
        /// The maximum value that the handler can specify for a menu item ID.
        /// </param>
        /// <param name="uFlags">
        /// Optional flags that specify how the shortcut menu can be changed.
        /// </param>
        /// <returns>
        /// If successful, returns an HRESULT value that has its severity value set 
        /// to SEVERITY_SUCCESS and its code value set to the offset of the largest 
        /// command identifier that was assigned, plus one.
        /// </returns>
        public int QueryContextMenu(
            IntPtr hMenu,
            uint iMenu,
            uint idCmdFirst,
            uint idCmdLast,
            uint uFlags)
        {
            // If uFlags include CMF_DEFAULTONLY then we should not do anything.
            if (((uint)CMF.CMF_DEFAULTONLY & uFlags) != 0)
            {
                return WinError.MAKE_HRESULT(WinError.SEVERITY_SUCCESS, 0, 0);
            }


            // ORIGINAL
           // Use either InsertMenu or InsertMenuItem to add menu items.
            /*
            MENUITEMINFO mii = new MENUITEMINFO();
            mii.cbSize = (uint)Marshal.SizeOf(mii);
            mii.fMask = MIIM.MIIM_BITMAP | MIIM.MIIM_STRING | MIIM.MIIM_FTYPE | MIIM.MIIM_ID | MIIM.MIIM_STATE;
            mii.wID = idCmdFirst + itemCount++;
            mii.fType = MFT.MFT_STRING;
            mii.dwTypeData = this.menuText;
            mii.fState = MFS.MFS_ENABLED;
            mii.hbmpItem = this.menuBmp;
            if (!NativeMethods.InsertMenuItem(hMenu, iMenu, true, ref mii))
            {
                return Marshal.GetHRForLastWin32Error();
            }
            */

            IntPtr hSubMenu = NativeMethods.CreatePopupMenu();

            // PARENT!!!
            MENUITEMINFO mii2 = new MENUITEMINFO();
            mii2.cbSize = (uint)Marshal.SizeOf(mii2);
            mii2.fMask = MIIM.MIIM_BITMAP | MIIM.MIIM_SUBMENU | MIIM.MIIM_STRING | MIIM.MIIM_FTYPE | MIIM.MIIM_ID | MIIM.MIIM_STATE;
            mii2.hSubMenu = hSubMenu;
            mii2.wID = idCmdFirst + itemCount;
            mii2.fType = MFT.MFT_STRING;
            mii2.dwTypeData = this.menuText;
            mii2.fState = MFS.MFS_ENABLED;
            mii2.hbmpItem = this.menuBmp;


            uint subItemCount = 0;
            
            SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows(); 
            string filename;

            foreach (SHDocVw.InternetExplorer ie in shellWindows)
            {
            
                /*
            string[] paths = {"path1", "path2", "path3"};
            foreach(string s in paths ) {
                */
                
                filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower();


                if (filename.Equals("explorer"))
                {
                    string ExplorerWindowPath = ie.LocationURL;
                    ExplorerWindowPath = ExplorerWindowPath.Replace("file:///", "");

                    // Filters out the current explorer window

                    // Had a file in c:\ and it matched c:\alertus-dev...
                    if (/*Path.GetDirectoryName(selectedFile) != Path.GetDirectoryName(ExplorerWindowPath) && */
                        !String.IsNullOrEmpty(ExplorerWindowPath) )
                    {
                          // Subitem1
                        MENUITEMINFO mii3 = new MENUITEMINFO();
                        mii3.cbSize = (uint)Marshal.SizeOf(mii2);
                        mii3.fMask = MIIM.MIIM_STRING | MIIM.MIIM_FTYPE | MIIM.MIIM_ID | MIIM.MIIM_STATE;
                        mii3.wID = idCmdFirst + itemCount;
                        mii3.fType = MFT.MFT_STRING;
                        mii3.dwTypeData = ExplorerWindowPath;
                        mii3.fState = MFS.MFS_ENABLED;
                        //mii3.hbmpItem = this.menuBmp;
                        if (!NativeMethods.InsertMenuItem(hSubMenu, subItemCount++, true, ref mii3))
                        {
                            return Marshal.GetHRForLastWin32Error();
                        }

                        pathMap.Add((int)itemCount, ExplorerWindowPath);
                        itemCount++;
                    }
                }
            }






            // Adding the POPUP Menu
            if (!NativeMethods.InsertMenuItem(hMenu, iMenu + 0, true, ref mii2))
            {
                return Marshal.GetHRForLastWin32Error();
            }

            






            // Return an HRESULT value with the severity set to SEVERITY_SUCCESS. 
            // Set the code value to the offset of the largest command identifier 
            // that was assigned, plus one (1).
            return WinError.MAKE_HRESULT(WinError.SEVERITY_SUCCESS, 0,
                IDM_DISPLAY + itemCount);
        }
Exemplo n.º 40
0
        public ImageViewer(string file)
        {
            IL.Initialize();

            // Extension supported?
            if (!ImageViewerUtils.IsValidExtension(file, EXTENSIONS))
                return;

            // Save Mouse Position -> will open image at this position
            Vector2i mousePos = Mouse.GetPosition();

            // Get Image
            LoadImage(file);

            if (Image == null)
                return;

            // Load Config File
            Config = new Config();
            Config.Load(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.txt"));

            if (Config.Setting_ListenForConfigChanges)
            {
                ConfigFileWatcher = new FileSystemWatcher(AppDomain.CurrentDomain.BaseDirectory, "config.txt");
                ConfigFileWatcher.NotifyFilter = NotifyFilters.LastWrite;
                ConfigFileWatcher.Changed += new FileSystemEventHandler(OnConfigChanged);
                ConfigFileWatcher.EnableRaisingEvents = true;
            }

            // Get/Set Folder Sorting
            SortImagesBy = Config.Setting_DefaultSortBy;
            SortImagesByDir = Config.Setting_DefaultSortDir;

            if (SortImagesBy == SortBy.FolderDefault || SortImagesByDir == SortDirection.FolderDefault)
            {
                // Get parent folder name
                string parentFolder = file.Substring(0, file.LastIndexOf('\\'));
                parentFolder = parentFolder.Substring(parentFolder.LastIndexOf('\\') + 1, parentFolder.Length - parentFolder.LastIndexOf('\\') - 1);

                // Get sort column info from window with corresponding name
                SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();
                foreach (SHDocVw.ShellBrowserWindow shellWindow in shellWindows)
                {
                    if (shellWindow.LocationName != parentFolder)
                        continue;

                    Shell32.ShellFolderView view = (Shell32.ShellFolderView)shellWindow.Document;

                    string sort = view.SortColumns;
                    sort = sort.Substring(5, sort.Length - 5);

                    // Direction
                    if (sort[0] == '-')
                    {
                        sort = sort.Substring(1, sort.Length - 1);

                        if (SortImagesByDir == SortDirection.FolderDefault)
                            SortImagesByDir = SortDirection.Descending;
                    }
                    else if (SortImagesByDir == SortDirection.FolderDefault)
                        SortImagesByDir = SortDirection.Ascending;

                    // By
                    if (SortImagesBy == SortBy.FolderDefault)
                    {
                        switch (sort)
                        {
                            case "System.ItemDate;": SortImagesBy = SortBy.Date; break;
                            case "System.DateModified;": SortImagesBy = SortBy.DateModified; break;
                            case "System.DateCreated;": SortImagesBy = SortBy.DateCreated; break;
                            case "System.Size;": SortImagesBy = SortBy.Size; break;
                            default: SortImagesBy = SortBy.Name; break;
                        }
                    }
                }
            }
            // Default sorting if folder was closed
            if (SortImagesBy == SortBy.FolderDefault)
                SortImagesBy = SortBy.Name;
            if (SortImagesByDir == SortDirection.FolderDefault)
                SortImagesByDir = SortDirection.Ascending;

            // Create Context Menu
            ContextMenu = new ContextMenu(this);
            ContextMenu.LoadItems(Config.ContextMenu, Config.ContextMenu_Animation, Config.ContextMenu_Animation_InsertAtIndex);
            ContextMenu.Setup(false);

            // Create Window
            Window = new RenderWindow(new VideoMode(Image.Texture.Size.X, Image.Texture.Size.Y), File + " - vimage", Styles.None);
            Window.SetActive();

            // Make Window Transparent (can only tell if image being viewed has transparency)
            DWM_BLURBEHIND bb = new DWM_BLURBEHIND(false);
            bb.dwFlags = DWM_BB.Enable;
            bb.fEnable = true;
            bb.hRgnBlur = new IntPtr();
            DWM.DwmEnableBlurBehindWindow(Window.SystemHandle, ref bb);

            bool _forceAlwaysOnTop = false;

            // Get Bounds
            IntRect bounds = ImageViewerUtils.GetCurrentBounds(mousePos);

            // Resize Window
            if (Config.Setting_LimitImagesToMonitor != Config.NONE)
            {
                // Fit to monitor height/width
                int limit = Config.Setting_LimitImagesToMonitor;

                if (limit == Config.AUTO)
                {
                    if (bounds.Height < bounds.Width)
                        limit = Config.HEIGHT;
                    else
                        limit = Config.WIDTH;
                }

                if (limit == Config.HEIGHT && Image.Texture.Size.Y > bounds.Height)
                {
                    Zoom(1 + (((float)bounds.Height - Image.Texture.Size.Y) / Image.Texture.Size.Y), true);
                    FitToMonitorHeightForced = true;
                }
                else if (limit == Config.WIDTH && Image.Texture.Size.X > bounds.Width)
                {
                    Zoom(1 + (((float)bounds.Width - Image.Texture.Size.X) / Image.Texture.Size.X), true);
                    AutomaticallyZoomed = true;
                }
            }
            if (Math.Min(Image.Texture.Size.X, Image.Texture.Size.Y) < Config.Setting_MinImageSize)
            {
                // Reisze images smaller than min size to min size
                AutomaticallyZoomed = true;
                Zoom(Config.Setting_MinImageSize / Math.Min(Image.Texture.Size.X, Image.Texture.Size.Y), true);
            }
                // Use Texture Size * Zoom instead of Window.Size since it wouldn't have updated yet
            Vector2i winSize = new Vector2i((int)(Image.Texture.Size.X * CurrentZoom), (int)(Image.Texture.Size.Y * CurrentZoom));

            // Position Window
            Vector2i winPos;

            if (Config.Setting_PositionLargeWideImagesInCorner && CurrentImageSize().X > CurrentImageSize().Y && CurrentImageSize().X * CurrentZoom >= bounds.Width)
            {
                // Position Window in top-left if the image is wide (ie: a Desktop Wallpaper / Screenshot)
                winPos = new Vector2i(bounds.Left, bounds.Top);
            }
            else if (Config.Setting_OpenAtMousePosition)
            {
                // At Mouse Position
                winPos = new Vector2i(mousePos.X - (int)(winSize.X / 2), mousePos.Y - (int)(winSize.Y / 2));

                if (!FitToMonitorHeightForced)
                {
                    if (winPos.Y < bounds.Top)
                        winPos.Y = 0;
                    else if (winPos.Y + winSize.Y > bounds.Height)
                        winPos.Y = bounds.Height - (int)winSize.Y;
                }
                else
                    winPos.Y = bounds.Top;

                if (winPos.X < bounds.Left)
                    winPos.X = bounds.Left;
                else if (winPos.X + winSize.X > bounds.Left + bounds.Width)
                    winPos.X = bounds.Left + bounds.Width - (int)winSize.X;
            }
            else
            {
                // At Monitor Center
                IntRect monitorBounds = ImageViewerUtils.GetCurrentBounds(mousePos);
                winPos = new Vector2i(monitorBounds.Left + (int)((monitorBounds.Width - winSize.X) / 2), monitorBounds.Top + (int)((monitorBounds.Height - winSize.Y) / 2));
            }

            Window.Position = winPos;

            // Force Always On Top Mode (so it's above the task bar)
            if (FitToMonitorHeightForced || (Image.Texture.Size.Y >= bounds.Height && Image.Texture.Size.X < bounds.Width))
                _forceAlwaysOnTop = true;

            // Defaults
                // Rotation (some images have a rotation set in their exif data)
            RotateImage(DefaultRotation, false);
                // Smoothing
            if (Image is AnimatedImage)
                Image.Data.Smooth = Math.Min(Image.Texture.Size.X, Image.Texture.Size.Y) < Config.Setting_SmoothingMinImageSize ? false : Config.Setting_SmoothingDefault;
            else
                Image.Texture.Smooth = Math.Min(Image.Texture.Size.X, Image.Texture.Size.Y) < Config.Setting_SmoothingMinImageSize ? false : Config.Setting_SmoothingDefault;
                // Backgrounds For Images With Transparency
            BackgroundsForImagesWithTransparency = Config.Setting_BackgroundForImagesWithTransparencyDefault;

            ForceAlwaysOnTopNextTick = _forceAlwaysOnTop;

            Redraw();
            NextWindowPos = Window.Position;

            // Interaction
            Window.Closed += OnWindowClosed;
            Window.MouseButtonPressed += OnMouseDown;
            Window.MouseButtonReleased += OnMouseUp;
            Window.MouseWheelScrolled += OnMouseWheelScrolled;
            Window.MouseMoved += OnMouseMoved;
            Window.KeyReleased += OnKeyUp;
            Window.KeyPressed += OnKeyDown;

            // Loop
            Stopwatch clock = new Stopwatch();
            clock.Start();

            while (Window.IsOpen)
            {
                // Add in some idle time to not thrash the CPU
                Thread.Sleep(1);

                if (CloseNextTick)
                {
                    Window.Close();
                    break;
                }

                // Process events
                Window.DispatchEvents();

                if (ReloadConfigNextTick)
                {
                    ReloadConfig();
                    ReloadConfigNextTick = false;
                }

                // Animated Image?
                if (Image is AnimatedImage)
                {
                    bool imageUpdated = Image.Update((float)clock.Elapsed.TotalMilliseconds);
                    if (!Updated && imageUpdated)
                        Update();
                }
                clock.Restart();

                // Drag Window
                if (Dragging)
                    Window.Position = new Vector2i(Mouse.GetPosition().X - DragPos.X, Mouse.GetPosition().Y - DragPos.Y);

                // Update
                if (Updated)
                {
                    Updated = false;
                    Redraw();
                    Window.Position = NextWindowPos;
                }

                if (ForceAlwaysOnTopNextTick)
                {
                    bounds = ImageViewerUtils.GetCurrentBounds(Window.Position);
                    if (Window.Size.Y >= bounds.Height && Window.Size.X < bounds.Width)
                        ForceAlwaysOnTop();
                    else
                        ForceAlwaysOnTopNextTick = false;
                }

                if (PreloadNextImageStart)
                    PreloadNextImage();
            }
        }
        /* get the IE sub tab/page of current playing songtaste music, whose title is "songtaste——播放器" */
        public HTMLDocument getMultiPlayingPage()
        {
            HTMLDocument stPlayingPage = null;

            /* 获得所有ie进程。因为windows下资源窗口使用ie内核,所以不光是我们通常指的web浏览器,它还包括你打开'我的电脑'这样的窗口 */
            SHDocVw.ShellWindows sws = new SHDocVw.ShellWindows();

            /*遍历ie进程*/
            foreach (SHDocVw.InternetExplorer iw in sws)
            {
                string iePlayStMusicTitle = "songtaste——播放器";
                //string playingStMusic360se = "songtaste——播放器";
                //string iePlayStMusicTitle = "Legend-气势磅礴的电影配乐 Two steps from hell 试听 -- SongTaste 用音乐倾听彼此";
                if (iw.LocationName == iePlayStMusicTitle)
                {
                    //string testStr = "";
                    //testStr = iw.Path;
                    //testStr = iw.Type;
                    //Object objTest = iw.Application;
                    //bool isAddrBar = iw.AddressBar;
                    //Object app = iw.Application;

                    // 找到标题为"songtaste——播放器"的IE子页面
                    stPlayingPage = (HTMLDocument)iw.Document;
                    break;
                }
            }

            return stPlayingPage;
        }
Exemplo n.º 42
0
        private void GetFolderView()
        {
            // desktop thread
            const int SWC_DESKTOP = 0x00000008;
            const int SWFO_NEEDDISPATCH = 0x00000001;

            SHDocVw.ShellWindows shellWindows = null;
            try {
                shellWindows = new SHDocVw.ShellWindows();
                object oNull1 = null, oNull2 = null;
                int pHWND;
                object o = shellWindows.FindWindowSW(ref oNull1, ref oNull2, SWC_DESKTOP, out pHWND, SWFO_NEEDDISPATCH);

                _IServiceProvider sp = o as _IServiceProvider;
                if(sp == null) return;
                object oShellBrowser;
                sp.QueryService(ExplorerGUIDs.IID_IShellBrowser, ExplorerGUIDs.IID_IUnknown, out oShellBrowser);
                ShellBrowser = new ShellBrowserEx(oShellBrowser as IShellBrowser);
            }
            catch {
            }
            finally {
                if(shellWindows != null) {
                    Marshal.ReleaseComObject(shellWindows);
                }
            }
        }
Exemplo n.º 43
0
        //获得活动的explore窗口的路径
        private static string GetExplorerCurrentPath()
        {
            string path = null;
            
            var shellWindows = new SHDocVw.ShellWindows();

            try
            {

                foreach (SHDocVw.InternetExplorer ie in shellWindows)
                {
                    var filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower();

                    var activeWindow = Native.GetForegroundWindow();

                    if (filename.Equals("explorer") && activeWindow == new IntPtr(ie.HWND))
                    {
                        var uri = ie.LocationURL;
                        if (Uri.IsWellFormedUriString(uri, UriKind.Absolute))
                        {
                            path = new Uri(uri).LocalPath;
                        }
                    }
                }

                return path;
            }
            finally
            {
                Marshal.ReleaseComObject(shellWindows);
            }

        }