public static void ShowProperties(byte[] idl, IntPtr hwnd = default(IntPtr)) { using (SafePtr sptr = new SafePtr("properties")) using (IDLWrapper wrapper = new IDLWrapper(idl)) { if (wrapper.Available) { SHELLEXECUTEINFO structure = new SHELLEXECUTEINFO { hwnd = hwnd, fMask = 0x40C, lpVerb = sptr, lpIDList = wrapper.PIDL }; structure.cbSize = Marshal.SizeOf(structure); PInvoke.ShellExecuteEx(ref structure); } } }
public static void ShowProperties(byte[] idl) { SHELLEXECUTEINFO structure = new SHELLEXECUTEINFO(); structure.cbSize = Marshal.SizeOf(structure); structure.fMask = 0x40c; structure.lpVerb = Marshal.StringToHGlobalUni("properties"); try { using (IDLWrapper wrapper = new IDLWrapper(idl)) { if (wrapper.Available) { structure.lpIDList = wrapper.PIDL; PInvoke.ShellExecuteEx(ref structure); } } } finally { if (structure.lpVerb != IntPtr.Zero) { Marshal.FreeHGlobal(structure.lpVerb); } } }
public static void ShowProperties(byte[] idl) { SHELLEXECUTEINFO structure = new SHELLEXECUTEINFO(); structure.cbSize = Marshal.SizeOf(structure); structure.fMask = 0x40c; structure.lpVerb = Marshal.StringToHGlobalUni("properties"); try { using(IDLWrapper wrapper = new IDLWrapper(idl)) { if(wrapper.Available) { structure.lpIDList = wrapper.PIDL; PInvoke.ShellExecuteEx(ref structure); } } } finally { if(structure.lpVerb != IntPtr.Zero) { Marshal.FreeHGlobal(structure.lpVerb); } } }
private static void OpenWindow(IDLWrapper pidl) { const int SW_SHOWNORMAL = 1; const int SEE_MASK_IDLIST = 0x00000004; SHELLEXECUTEINFO sei = new SHELLEXECUTEINFO { cbSize = Marshal.SizeOf(typeof(SHELLEXECUTEINFO)), nShow = SW_SHOWNORMAL, fMask = SEE_MASK_IDLIST, lpIDList = pidl.PIDL }; PInvoke.ShellExecuteEx(ref sei); }
private void subDirTip_MenuItemClicked(object sender, ToolStripItemClickedEventArgs e) { // this can run in both desktop and taskbar thread IntPtr hwndDialogParent = sender == subDirTip ? hwndListView : hwndShellTray; // desktop thread or taskbar thread QMenuItem qmi = (QMenuItem)e.ClickedItem; if(qmi.Genre == MenuGenre.SubDirTip_QTGRootItem) { Thread thread = new Thread(OpenGroup); thread.SetApartmentState(ApartmentState.STA); thread.IsBackground = true; thread.Start(new object[] {new string[] {qmi.Name}, ModifierKeys}); } else if(qmi.Target == MenuTarget.Folder) { using(IDLWrapper idlw = new IDLWrapper(qmi.IDL)) { if(!idlw.IsDeadLink(hwndDialogParent)) { Keys modKey = ModifierKeys; if(!Config.Bool(Scts.ActivateNewTab)) { if(modKey == Keys.Shift) { modKey = Keys.None; } else if(modKey == Keys.None) { modKey = Keys.Shift; } } if(idlw.IsLink) { if(!String.IsNullOrEmpty(qmi.TargetPath) && qmi.TargetPath.StartsWith(IDLWrapper.INDICATOR_NETWORK) && -1 == qmi.TargetPath.IndexOf(@"\", 2) && !ShellMethods.IsIDLNullOrEmpty(qmi.IDLTarget)) { // link target is network server root ( "\\server" ), prevent opening window OpenTab(new object[] {null, modKey, qmi.IDLTarget}); return; } } OpenTab(new object[] {null, modKey, idlw.IDL}); } } } else { using(IDLWrapper idlw = new IDLWrapper(qmi.IDL)) { if(!idlw.IsDeadLink(hwndDialogParent)) { string work = String.Empty; SHELLEXECUTEINFO sei = new SHELLEXECUTEINFO(); sei.cbSize = Marshal.SizeOf(sei); sei.nShow = SHOWWINDOW.SHOWNORMAL; sei.fMask = SEEMASK.IDLIST; sei.lpIDList = idlw.PIDL; sei.hwnd = hwndDialogParent; if(!String.IsNullOrEmpty(qmi.Path)) { work = QTUtility2.MakeDefaultWorkingDirecotryStr(qmi.Path); if(work.Length > 0) { sei.lpDirectory = Marshal.StringToCoTaskMemUni(work); } } try { if(PInvoke.ShellExecuteEx(ref sei)) { QTUtility.AddRecentFiles( new string[][] { work.Length > 0 ? new string[] {qmi.Path, String.Empty, work} : new string[] {qmi.Path} }, hwndThis); } } finally { if(sei.lpDirectory != IntPtr.Zero) { Marshal.FreeCoTaskMem(sei.lpDirectory); } } } } } }
private void subDirTip_MenuItemClicked(object sender, ToolStripItemClickedEventArgs e) { QMenuItem clickedItem = (QMenuItem)e.ClickedItem; if(clickedItem.Target == MenuTarget.Folder) { if(clickedItem.IDLData == null) { OpenTab(new object[] { clickedItem.TargetPath, ModifierKeys }); return; } using(IDLWrapper wrapper = new IDLWrapper(clickedItem.IDLData)) { SHELLEXECUTEINFO structure = new SHELLEXECUTEINFO(); structure.cbSize = Marshal.SizeOf(structure); structure.nShow = 1; structure.fMask = 4; structure.lpIDList = wrapper.PIDL; try { PInvoke.ShellExecuteEx(ref structure); } catch { } return; } } try { string path = clickedItem.Path; ProcessStartInfo startInfo = new ProcessStartInfo(path); startInfo.WorkingDirectory = Path.GetDirectoryName(path); startInfo.ErrorDialog = true; Process.Start(startInfo); if(!QTUtility.CheckConfig(Settings.NoRecentFiles)) { QTUtility.ExecutedPathsList.Add(path); } } catch { } }
public bool ExecuteCommand(Commands command, object arg) { if(tabBar != null) { IntPtr ptr; switch(command) { case Commands.GoBack: case Commands.GoForward: if(arg is int) { return tabBar.NavigateToIndex(command == Commands.GoBack, (int)arg); } break; case Commands.GoUpOneLevel: tabBar.UpOneLevel(); return true; case Commands.RefreshBrowser: tabBar.Explorer.Refresh(); return true; case Commands.CloseCurrentTab: return tabBar.CloseTab(tabBar.CurrentTab); case Commands.CloseLeft: case Commands.CloseRight: tabBar.CloseLeftRight(command == Commands.CloseLeft, -1); return true; case Commands.CloseAllButCurrent: if(tabBar.tabControl1.TabCount > 1) { foreach(QTabItem item in tabBar.tabControl1.TabPages) { if(item != tabBar.CurrentTab) { tabBar.CloseTab(item); } } } return true; case Commands.CloseAllButOne: { TabWrapper wrapper = arg as TabWrapper; if(wrapper == null) { break; } foreach(QTabItem item2 in tabBar.tabControl1.TabPages) { if(item2 != wrapper.Tab) { tabBar.CloseTab(item2); } } return true; } case Commands.CloseWindow: WindowUtils.CloseExplorer(tabBar.ExplorerHandle, 2); return true; case Commands.UndoClose: tabBar.RestoreLastClosed(); return true; case Commands.BrowseFolder: tabBar.ChooseNewDirectory(); return true; case Commands.ToggleTopMost: tabBar.ToggleTopMost(); tabBar.SyncButtonBarCurrent(0x40); return true; case Commands.FocusFileList: tabBar.listView.SetFocus(); return true; case Commands.OpenTabBarOptionDialog: tabBar.OpenOptionsDialog(); return true; case Commands.OpenButtonBarOptionDialog: if(!QTUtility.instanceManager.TryGetButtonBarHandle(tabBar.ExplorerHandle, out ptr)) { break; } QTUtility2.SendCOPYDATASTRUCT(ptr, (IntPtr)12, "showop", IntPtr.Zero); return true; case Commands.IsFolderTreeVisible: return tabBar.ShellBrowser.IsFolderTreeVisible(); case Commands.IsButtonBarVisible: return QTUtility.instanceManager.TryGetButtonBarHandle(tabBar.ExplorerHandle, out ptr); case Commands.ShowFolderTree: if(!QTUtility.IsXP || !(arg is bool)) { break; } tabBar.ShowFolderTree((bool)arg); return true; case Commands.ShowButtonBar: if(!QTUtility.instanceManager.TryGetButtonBarHandle(tabBar.ExplorerHandle, out ptr)) { } break; case Commands.MD5: if(!(arg is string[])) { break; } if(md5Form == null) { md5Form = new FileHashComputerForm(); } if(md5Form.InvokeRequired) { md5Form.Invoke(new FormMethodInvoker(ShowMD5FormCore), new object[] { arg }); } else { ShowMD5FormCore(arg); } return true; case Commands.ShowProperties: { if((arg == null) || !(arg is Address)) { break; } Address address = (Address)arg; IntPtr pv = AddressToPIDL(address); if(!(pv != IntPtr.Zero)) { break; } SHELLEXECUTEINFO structure = new SHELLEXECUTEINFO(); structure.cbSize = Marshal.SizeOf(structure); structure.hwnd = tabBar.ExplorerHandle; structure.fMask = 0x40c; structure.lpVerb = Marshal.StringToHGlobalUni("properties"); structure.lpIDList = pv; PInvoke.ShellExecuteEx(ref structure); PInvoke.CoTaskMemFree(pv); if(structure.lpVerb != IntPtr.Zero) { Marshal.FreeHGlobal(structure.lpVerb); } return true; } case Commands.SetModalState: if(((arg == null) || !(arg is bool)) || !((bool)arg)) { tabBar.NowModalDialogShown = false; break; } tabBar.NowModalDialogShown = true; break; case Commands.SetSearchBoxStr: if(((arg == null) || !(arg is string)) || !QTUtility.instanceManager.TryGetButtonBarHandle(tabBar.ExplorerHandle, out ptr)) { break; } return (IntPtr.Zero == QTUtility2.SendCOPYDATASTRUCT(ptr, (IntPtr)0x10, (string)arg, IntPtr.Zero)); case Commands.ReorderTabsByName: case Commands.ReorderTabsByPath: case Commands.ReorderTabsByActv: case Commands.ReorderTabsRevers: if(tabBar.tabControl1.TabCount > 1) { bool fDescending = ((arg != null) && (arg is bool)) && ((bool)arg); tabBar.ReorderTab(((int)command) - 0x18, fDescending); } break; } } return false; }
public static void Execute(MenuItemArguments mia, IntPtr hwnd) { if(((mia == null) || (mia.Genre != MenuGenre.Application)) || string.IsNullOrEmpty(mia.Path)) { QTUtility2.MakeErrorLog(null, "Applauncher.Execute bug found"); } else { string path = mia.Path; string argument = mia.Argument; string workingDirectory = mia.WorkingDirectory; if(!string.Equals(path, "separator", StringComparison.OrdinalIgnoreCase)) { bool flag = false; if(path.StartsWith("::")) { using(IDLWrapper wrapper = new IDLWrapper(path)) { if(wrapper.Available) { SHELLEXECUTEINFO structure = new SHELLEXECUTEINFO(); structure.cbSize = Marshal.SizeOf(structure); structure.nShow = 1; structure.fMask = 4; structure.lpIDList = wrapper.PIDL; structure.hwnd = hwnd; PInvoke.ShellExecuteEx(ref structure); return; } } flag = true; } if(path.StartsWith(@"\\")) { using(IDLWrapper wrapper2 = new IDLWrapper(path)) { if(!wrapper2.Available) { flag = true; } } } if(!flag && Directory.Exists(path)) { ProcessStartInfo startInfo = new ProcessStartInfo(path); startInfo.ErrorDialog = true; try { Process.Start(startInfo); } catch { } return; //flag = true; } if(!flag) { SHELLEXECUTEINFO shellexecuteinfo2 = new SHELLEXECUTEINFO(); shellexecuteinfo2.cbSize = Marshal.SizeOf(shellexecuteinfo2); shellexecuteinfo2.nShow = 1; shellexecuteinfo2.fMask = 0x4000200; shellexecuteinfo2.hwnd = hwnd; try { shellexecuteinfo2.lpFile = Marshal.StringToHGlobalUni(path); if(!string.IsNullOrEmpty(argument)) { shellexecuteinfo2.lpParameters = Marshal.StringToHGlobalUni(argument); } if(!string.IsNullOrEmpty(workingDirectory)) { workingDirectory = workingDirectory.Trim(new char[] { '"', '\'' }); shellexecuteinfo2.lpDirectory = Marshal.StringToHGlobalUni(workingDirectory); } else { try { shellexecuteinfo2.lpDirectory = Marshal.StringToHGlobalUni(Path.GetDirectoryName(path)); } catch { } } if(PInvoke.ShellExecuteEx(ref shellexecuteinfo2)) { string extension = Path.GetExtension(path); if(!string.Equals(".exe", extension, StringComparison.OrdinalIgnoreCase) && !string.Equals(".com", extension, StringComparison.OrdinalIgnoreCase)) { QTUtility.ExecutedPathsList.Add(path); } } } finally { if(shellexecuteinfo2.lpFile != IntPtr.Zero) { Marshal.FreeHGlobal(shellexecuteinfo2.lpFile); } if(shellexecuteinfo2.lpParameters != IntPtr.Zero) { Marshal.FreeHGlobal(shellexecuteinfo2.lpParameters); } if(shellexecuteinfo2.lpDirectory != IntPtr.Zero) { Marshal.FreeHGlobal(shellexecuteinfo2.lpDirectory); } } } else { if(!string.IsNullOrEmpty(argument)) { path = path + ", " + argument; } if(!string.IsNullOrEmpty(workingDirectory)) { path = path + ", " + workingDirectory; } MessageBox.Show("Operation failed.\r\nPlease make sure the file or the target of link exists:\r\n\r\n" + path, "Error - QTTabBar", MessageBoxButtons.OK, MessageBoxIcon.Hand); } } } }
public static extern bool ShellExecuteEx(ref SHELLEXECUTEINFO lpExecInfo);
public static extern bool ShellExecuteEx(ref SHELLEXECUTEINFO lpExecInfo);
public static void ShowProperties(byte[] idl, IntPtr hwnd = default(IntPtr)) { using(SafePtr sptr = new SafePtr("properties")) using(IDLWrapper wrapper = new IDLWrapper(idl)) { if(wrapper.Available) { SHELLEXECUTEINFO structure = new SHELLEXECUTEINFO { hwnd = hwnd, fMask = 0x40C, lpVerb = sptr, lpIDList = wrapper.PIDL }; structure.cbSize = Marshal.SizeOf(structure); PInvoke.ShellExecuteEx(ref structure); } } }