Esempio n. 1
0
        public bool execute(string strExec, Keys modifiers)
        {
            string curdir = System.Environment.CurrentDirectory;


            if (fileType == FileType.NORMAL)
            {
                System.Environment.CurrentDirectory = Path.GetDirectoryName(path);
            }

            try
            {
                SearchCmd sc = Util.analyzeSearchCmd(strExec);
                if ((modifiers & Keys.Shift) == Keys.Shift)
                {
                    System.Diagnostics.Process.Start("explorer", "/select,\"" + path + "\"");
                }
                else if ((modifiers & Keys.Control) == Keys.Control)
                {
                    // run as admin
                    SHFILEINFO shFileInfo = new SHFILEINFO();

                    //reference: http://dobon.net/vb/dotnet/system/runelevated.html
                    System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();
                    psi.UseShellExecute = true;
                    psi.FileName = path;
                    psi.Verb = "runas"; // as Admin
                    psi.Arguments = sc.strOption;
                    psi.ErrorDialog = false;
                    System.Diagnostics.Process.Start(psi);

                }
                else
                {
                    // run
                    if (string.IsNullOrEmpty(sc.strOption))
                        System.Diagnostics.Process.Start(path);
                    else
                        System.Diagnostics.Process.Start(path, sc.strOption);
                }
            }
            finally
            {
                if (fileType == FileType.NORMAL)
                {
                    System.Environment.CurrentDirectory = curdir;
                }
            }

            return true;
        }
Esempio n. 2
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            Trace.WriteLine("form loaded!");

            int interval = 0;
            if (NativeMethods.SystemParametersInfo(22, 0, ref interval, 0)) // 22=SPI_GETKEYBOARDDELAY
            {
                timerInput.Interval = (interval + 1) * 250; // /* 1unit = approximately 250 */
            }
            timerInput.Enabled = true;
            timerInput.Stop();

            // initial position
            int MainWinHeight = Properties.Settings.Default.MainWinHeight;
            if (MainWinHeight > 0)
            {
                this.Size = new Size(Properties.Settings.Default.MainWinWidth, MainWinHeight);
                this.Location = new Point(Properties.Settings.Default.MainWinPosX, Properties.Settings.Default.MainWinPosY);
            }
            else
            {
                this.CenterToScreen();
            }

            cmbbxSearcText.Items.AddRange(envmngr.getSearchHistory());

            SetFontAndColor();

            // prepare LSV
            // lsvFileList.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);

            // reference: http://acha-ya.cocolog-nifty.com/blog/2010/11/2-f06c.html
            SHFILEINFO shFileInfo = new SHFILEINFO();
            SmallImageListHandle = NativeMethods.SHGetFileInfo(String.Empty, 0,
                out shFileInfo, (uint)Marshal.SizeOf(shFileInfo),
                NativeMethods.SHGFI_SMALLICON | NativeMethods.SHGFI_SYSICONINDEX);
            LargeImageListHandle = NativeMethods.SHGetFileInfo(String.Empty, 0,
                out shFileInfo, (uint)Marshal.SizeOf(shFileInfo),
                NativeMethods.SHGFI_LARGEICON | NativeMethods.SHGFI_SYSICONINDEX);
            NativeMethods.SendMessage(lsvFileList.Handle, NativeMethods.LVM_SETIMAGELIST,
                new IntPtr(NativeMethods.LVSIL_SMALL), SmallImageListHandle);
            NativeMethods.SendMessage(lsvFileList.Handle, NativeMethods.LVM_SETIMAGELIST,
                new IntPtr(NativeMethods.LVSIL_NORMAL), LargeImageListHandle);

            updateView("", true);

            envmngr.setNotifyFinished(EnvFinished);
        }
Esempio n. 3
0
        private void setIconIndex()
        {
            if (bIconCached || iconIndex == -1 || iconIndex == 0) // 0 は serialize 対策
            {
                // reference: http://acha-ya.cocolog-nifty.com/blog/2010/11/2-f06c.html
                SHFILEINFO shFileInfo = new SHFILEINFO();
                shFileInfo.iIcon = -1;
                shFileInfo.hIcon = IntPtr.Zero;
                if (fileType == FileType.NORMAL)
                {
                    NativeMethods.SHGetFileInfo(path, 0, out shFileInfo,
                        (uint)Marshal.SizeOf(shFileInfo), 
                        NativeMethods.SHGFI_ICON | NativeMethods.SHGFI_SYSICONINDEX |
                        NativeMethods.SHGFI_OVERLAYINDEX);

                }
                else if (fileType == FileType.CLSID)
                {
                    IntPtr pidl;
                    uint sfgaoOut;
                    NativeMethods.SHParseDisplayName(path, IntPtr.Zero, out pidl, 0, out sfgaoOut);
                    NativeMethods.SHGetFileInfo(pidl, 0, out shFileInfo,
                        (uint)Marshal.SizeOf(shFileInfo),
                        NativeMethods.SHGFI_ICON | NativeMethods.SHGFI_SYSICONINDEX |
                        NativeMethods.SHGFI_OVERLAYINDEX | NativeMethods.SHGFI_PIDL);

                }

                if (shFileInfo.iIcon == -1)
                {
                    iconIndex = 1; // for dummy
                }
                else
                {
                    iconIndex = shFileInfo.iIcon;
                }
                if (shFileInfo.hIcon != IntPtr.Zero)
                {
                    NativeMethods.DestroyIcon(shFileInfo.hIcon);
                }
            }
        }
Esempio n. 4
0
        private void setItemPath(string path)
        {
            itemType = ItemType.TYPE_NORMAL;

            // set path
            this.path = path;

            if (bIconCached)
            {
                // set icon
                setIconIndex();
            }

            if (name == null)
            {
                // set name
                SHFILEINFO shFileInfo = new SHFILEINFO();
                NativeMethods.SHGetFileInfo(path, 0, out shFileInfo, (uint)Marshal.SizeOf(shFileInfo), NativeMethods.SHGFI_DISPLAYNAME);
                if (shFileInfo.szDisplayName != null && shFileInfo.szDisplayName.Length > 0)
                {
                    name = shFileInfo.szDisplayName;
                }
                else
                {
                    name = Path.GetFileName(path);
                }
            }

            if (convName == null)
            {
                // set convName
                convName = Util.SafeStrConv(name);
            }
        }
Esempio n. 5
0
        public int getIconIndex()
        {
            SHFILEINFO shFileInfo = new SHFILEINFO();
            shFileInfo.iIcon = -1;
            shFileInfo.hIcon = IntPtr.Zero;

            string iconpath;
            if (itemType == ItemType.TYPE_FIX)
            {
                iconpath = System.IO.Path.GetFullPath(System.Environment.SystemDirectory + "\\..\\explorer.exe");
            }
            else
            {
                iconpath = System.Environment.SystemDirectory + "\\taskmgr.exe";
            }

            NativeMethods.SHGetFileInfo(iconpath, 0, out shFileInfo,
                (uint)Marshal.SizeOf(shFileInfo),
                NativeMethods.SHGFI_ICON | NativeMethods.SHGFI_SYSICONINDEX |
                NativeMethods.SHGFI_OVERLAYINDEX);

            if (shFileInfo.iIcon == -1)
            {
                iconIndex = 1; // for dummy
            }
            else
            {
                iconIndex = shFileInfo.iIcon;
            }
            if (shFileInfo.hIcon != IntPtr.Zero)
            {
                NativeMethods.DestroyIcon(shFileInfo.hIcon);
            }

            return iconIndex;
        }
 public static extern IntPtr SHGetFileInfo(IntPtr pIDL, uint dwFileAttributes,
     out SHFILEINFO psfi, uint cbFileInfo, uint uFlags);
		public static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes,
			out SHFILEINFO psfi, uint cbFileInfo, uint uFlags);