谢谢。我把我在vb中实现的代码拷贝给你,帮我看看怎么转换,谢谢你! 'API用タイプ Private Type BROWSEINFO hOwner As Long pidlRoot As Long pszDisplayName As String lpszTitle As String ulFlags As Long lpfn As Long lParam As Long iImage As Long End TypePrivate Declare Function SHGetPathFromIDList _ Lib "shell32.dll" _ Alias "SHGetPathFromIDListA" _ (ByVal pidl As Long, _ ByVal pszPath As String) As Long Private Declare Function SHBrowseForFolder _ Lib "shell32.dll" _ Alias "SHBrowseForFolderA" _ (lpBrowseInfo As BROWSEINFO) As Long'モジュール共有定数定義 Private Const BIF_RETURNONLYFSDIRS = &H1 Dim biBrowseInfo As BROWSEINFO Dim lngRtn As Long Dim lngPidl As Long Dim strPath As String Dim intPos As Integer
'API用タイプ
Private Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End TypePrivate Declare Function SHGetPathFromIDList _
Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" _
(ByVal pidl As Long, _
ByVal pszPath As String) As Long
Private Declare Function SHBrowseForFolder _
Lib "shell32.dll" _
Alias "SHBrowseForFolderA" _
(lpBrowseInfo As BROWSEINFO) As Long'モジュール共有定数定義
Private Const BIF_RETURNONLYFSDIRS = &H1 Dim biBrowseInfo As BROWSEINFO
Dim lngRtn As Long
Dim lngPidl As Long
Dim strPath As String
Dim intPos As Integer
biBrowseInfo.hOwner = Me.Hwnd
biBrowseInfo.pidlRoot = 0&
biBrowseInfo.lpszTitle = "出力先フォルダパスを選択したください。:"
biBrowseInfo.ulFlags = BIF_RETURNONLYFSDIRS
lngPidl = SHBrowseForFolder(biBrowseInfo)
strPath = Space$(512)
lngRtn = SHGetPathFromIDList(ByVal lngPidl&, ByVal strPath)
我找到了 hohoho [DllImport("shell32.dll", EntryPoint="SHBrowseForFolder")]
public static extern int SHBrowseForFolder
(
ref BrowseInfo lpbi
);
c# 的写法 !
我定义了这个结构,
然后再调用时用SHBrowseForFolder(ref lpbi)这样,他报错说抛出外部组件异常。
我把我写的代码贴出来,麻烦大家帮我看看,谢谢。BROWSEINFO biBrowseInfo = new BROWSEINFO();
long lngRtn;
long lngPidl;
string strPath;
//int intPos; biBrowseInfo.hOwner = (long)(this.Handle);
biBrowseInfo.pidlRoot = 0x0;
biBrowseInfo.lpszTitle = "出力先フォルダパスを選択したください。:";
biBrowseInfo.ulFlags = BIF_RETURNONLYFSDIRS;
lngPidl = SHBrowseForFolder(ref biBrowseInfo);
public sealed class FolderBrowserDialog : CommonDialog 可以轻松解决这个问题
注意:此命名空间、类或成员仅在 .NET Framework 1.1 版中受支持。
内有自定义结构,需要用C#中新建一个与BROWSEINFO差不多的struct数据结构.
而且还有回调函数需要用到自定义委托.
最近我比较忙.你也只是想试验一下,等我忙过以后解决再给你答复.