程序实现,弹出文件或文件夹属性窗口。 就是右击->属性,那个窗口。有路径,怎么实现呢?搜索下了,好像是可以用SHELL做,用到啥PIDL,有点复杂,不是很懂,哪位高手指点一下。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 显示属性页 IShellFolder接口不仅提供对外壳内部数据结构的存取,也可以调用界面元素进行交互。例如,使用IShellFolder.GetUIObjectOf 方法,可以请求上下文相关菜单。在下面代码中演示了如何操作PIDL来获得IContextMenu 接口,并通过IContextMenu来调用菜单命令,比如显示属性页,调用我的电脑的属性命令显示属性页的示意图如图2.17所示procedure ShowProperties(Handle: HWND; ItemList: PItemIDList); overload; var Desktop: IShellFolder; Folder: IShellFolder; ParentList: PItemIDList; RelativeList: PItemIDList; ContextMenu: IContextMenu; CommandInfo: TCMInvokeCommandInfo; Begin ParentList := ILClone(ItemList); if ParentList <> nil then try ILRemoveLastID(ParentList); OleCheck(SHGetDesktopFolder(Desktop)); OleCheck(Desktop.BindToObject( ParentList, nil, IID_IShellFolder,Folder)); RelativeList := ILFindChild(ParentList, ItemList); OleCheck(Folder.GetUIObjectOf(Handle, 1, RelativeList, IID_IContextMenu, nil, ContextMenu)); FillChar(CommandInfo, SizeOf(TCMInvokeCommandInfo), #0); with CommandInfo do begin cbSize := SizeOf(TCMInvokeCommandInfo); hwnd := Handle; lpVerb := 'Properties'; nShow := SW_SHOW; end; OleCheck(ContextMenu.InvokeCommand(CommandInfo)); Finally ILFree(ParentList); end; end; procedure ShowProperties(Handle: HWND; const DisplayName: string); overload; var ItemList: PItemIDList; Begin ItemList := ILCreateFromPath(PChar(DisplayName)); Try ShowProperties(Handle, ItemList) Finally ILFree(ItemList); end; end;VB代码不懂,DesktopILFree,OleCheck,真看不懂! 这是Delphi代码,不是VB。也可以用API ShellExecuteEx,lpVerb给"properties"。 using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Runtime.InteropServices;namespace ThreeTorches{ class ShellExe { [DllImport("shell32.dll", CharSet = CharSet.Auto)] static extern bool ShellExecuteEx(ref SHELLEXECUTEINFO lpExecInfo); [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] private struct SHELLEXECUTEINFO { public int cbSize; public uint fMask; public IntPtr hwnd; [MarshalAs(UnmanagedType.LPTStr)] public string lpVerb; [MarshalAs(UnmanagedType.LPTStr)] public string lpFile; [MarshalAs(UnmanagedType.LPTStr)] public string lpParameters; [MarshalAs(UnmanagedType.LPTStr)] public string lpDirectory; public int nShow; public IntPtr hInstApp; public IntPtr lpIDList; [MarshalAs(UnmanagedType.LPTStr)] public string lpClass; public IntPtr hkeyClass; public uint dwHotKey; public IntPtr hIcon; public IntPtr hProcess; } private const int SW_SHOW = 5; private const uint SEE_MASK_INVOKEIDLIST = 12; /// <summary> /// 显示指定的文件(夹)属性对话框 /// </summary> /// <param name="filename">要显示属性对话框的文件(夹)完整路径</param> public static void ShowFileProperties(string filename) { SHELLEXECUTEINFO info = new SHELLEXECUTEINFO(); info.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(info); info.lpVerb = "properties"; info.lpFile = filename; info.nShow = SW_SHOW; info.fMask = SEE_MASK_INVOKEIDLIST; ShellExecuteEx(ref info); } }} [DllImport("Shell32.dll")] public static extern int ShellExecuteEx(SHELLEXECUTEINFO lpExecInfo); static void Main(string[] args) { SHELLEXECUTEINFO ShExecInfo = new SHELLEXECUTEINFO(); ShExecInfo.cbSize = 90; ShExecInfo.fMask = 0xC; ShExecInfo.hwnd = 0; ShExecInfo.lpVerb = "properties"; ShExecInfo.lpFile = @"c:\"; //can be a file as well ShExecInfo.lpParameters = ""; ShExecInfo.lpDirectory = null; ShExecInfo.nShow =(int)ShowCommands.SW_SHOW; ShExecInfo.hInstApp = 0; ShellExecuteEx( ShExecInfo); }程序一闪而过,怎么没弹出来? 我试验过 XiaNao16888 的代码了。只有1句错了info.lpVerb = "properties"; to:XiaNao16888,帮我把类都写好了,嘿嘿 很菜的问题 c#中不能从控制台直接读入一个整型吗? 自定义异常类的问题 关于google earth的问题!!!求教 求一文件上传问题,要求能上传的内容教大。 如何用一个页面通过接口调用不同的控件实现多个页面的功能》 C# C/S系统中如何实现这种效果, 求助 c#写一个windows服务 .net C/S结构的怎么根据程序界面找到相应的代码页面???????????? 如何在修改ListView的宽度之后修改ColumnHeader的宽度 我想问一下关于TextBox的问题 投票系统的柱状图公式 C#如何完成对EXCEL的读写
IShellFolder接口不仅提供对外壳内部数据结构的存取,也可以调用界面元素进行交互。例如,使用IShellFolder.GetUIObjectOf 方法,可以请求上下文相关菜单。在下面代码中演示了如何操作PIDL来获得IContextMenu 接口,并通过IContextMenu来调用菜单命令,比如显示属性页,调用我的电脑的属性命令显示属性页的示意图如图2.17所示procedure ShowProperties(Handle: HWND; ItemList: PItemIDList); overload;
var
Desktop: IShellFolder;
Folder: IShellFolder;
ParentList: PItemIDList;
RelativeList: PItemIDList;
ContextMenu: IContextMenu;
CommandInfo: TCMInvokeCommandInfo;
Begin
ParentList := ILClone(ItemList);
if ParentList <> nil then
try
ILRemoveLastID(ParentList);
OleCheck(SHGetDesktopFolder(Desktop));
OleCheck(Desktop.BindToObject(
ParentList, nil, IID_IShellFolder,Folder));
RelativeList := ILFindChild(ParentList, ItemList);
OleCheck(Folder.GetUIObjectOf(Handle, 1, RelativeList,
IID_IContextMenu, nil, ContextMenu));
FillChar(CommandInfo, SizeOf(TCMInvokeCommandInfo), #0);
with CommandInfo do
begin
cbSize := SizeOf(TCMInvokeCommandInfo);
hwnd := Handle;
lpVerb := 'Properties';
nShow := SW_SHOW;
end;
OleCheck(ContextMenu.InvokeCommand(CommandInfo));
Finally
ILFree(ParentList);
end;
end;
procedure ShowProperties(Handle: HWND;
const DisplayName: string); overload;
var
ItemList: PItemIDList;
Begin
ItemList := ILCreateFromPath(PChar(DisplayName));
Try
ShowProperties(Handle, ItemList)
Finally
ILFree(ItemList);
end;
end;VB代码不懂,
Desktop
ILFree,OleCheck,
真看不懂!
也可以用API ShellExecuteEx,lpVerb给"properties"。
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;namespace ThreeTorches
{
class ShellExe
{
[DllImport("shell32.dll", CharSet = CharSet.Auto)]
static extern bool ShellExecuteEx(ref SHELLEXECUTEINFO lpExecInfo); [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
private struct SHELLEXECUTEINFO
{
public int cbSize;
public uint fMask;
public IntPtr hwnd;
[MarshalAs(UnmanagedType.LPTStr)]
public string lpVerb;
[MarshalAs(UnmanagedType.LPTStr)]
public string lpFile;
[MarshalAs(UnmanagedType.LPTStr)]
public string lpParameters;
[MarshalAs(UnmanagedType.LPTStr)]
public string lpDirectory;
public int nShow;
public IntPtr hInstApp;
public IntPtr lpIDList;
[MarshalAs(UnmanagedType.LPTStr)]
public string lpClass;
public IntPtr hkeyClass;
public uint dwHotKey;
public IntPtr hIcon;
public IntPtr hProcess;
} private const int SW_SHOW = 5;
private const uint SEE_MASK_INVOKEIDLIST = 12;
/// <summary>
/// 显示指定的文件(夹)属性对话框
/// </summary>
/// <param name="filename">要显示属性对话框的文件(夹)完整路径</param>
public static void ShowFileProperties(string filename)
{
SHELLEXECUTEINFO info = new SHELLEXECUTEINFO();
info.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(info);
info.lpVerb = "properties";
info.lpFile = filename;
info.nShow = SW_SHOW;
info.fMask = SEE_MASK_INVOKEIDLIST;
ShellExecuteEx(ref info);
} }
}
[DllImport("Shell32.dll")]
public static extern int ShellExecuteEx(SHELLEXECUTEINFO lpExecInfo); static void Main(string[] args)
{
SHELLEXECUTEINFO ShExecInfo = new SHELLEXECUTEINFO();
ShExecInfo.cbSize = 90;
ShExecInfo.fMask = 0xC;
ShExecInfo.hwnd = 0;
ShExecInfo.lpVerb = "properties";
ShExecInfo.lpFile = @"c:\"; //can be a file as well
ShExecInfo.lpParameters = "";
ShExecInfo.lpDirectory = null;
ShExecInfo.nShow =(int)ShowCommands.SW_SHOW;
ShExecInfo.hInstApp = 0;
ShellExecuteEx( ShExecInfo);
}
程序一闪而过,怎么没弹出来?
XiaNao16888,
帮我把类都写好了,嘿嘿