那为大侠帮忙把以下VB代码转成 VC的?我实在是不会了
Dim sh As New Shell32.Shell
Const stra = "windows"
Private Sub Form_Load()
printFolder (6)
End Sub
Sub printFolder(namespace As Variant)
Dim f As Folder
Dim itm As Shell32.FolderItem
Dim l As Shell32.ShellLinkObject
Set f = sh.namespace(namespace)
For i = 0 To f.Items.Count - 1
Debug.Print f.Items.Item(i).Name,
Debug.Print f.Items.Item(i).IsLink,
If f.Items.Item(i).IsLink Then
Set l = f.Items.Item(i).GetLink
Debug.Print l.Path
If InStr(1, l.Path, stra) <> 0 Then MsgBox "got!"
If InStr(1, f.Items.Item(i).Name, stra) <> 0 Then MsgBox "got!"
ElseIf f.Items.Item(i).IsFolder Then
printFolder f.Items.Item(i).Path
End If
Debug.Print
Next
End Sub
问题点数:20、回复次数:4Top
1 楼blueblood7()回复于 2003-06-04 13:09:28 得分 20
#import "shell32.dll"
const char* stra = "windows";
void printFolder( _variant_t vPath );
HRESULT hr = 0;
Shell32::IShellDispatchPtr sh = NULL;
void CTest5Dlg::OnButton1()
{
// TODO: Add your control notification handler code here
hr = CoInitialize(NULL);
if( FAILED(hr) ) return;
hr = sh.CreateInstance( __uuidof(Shell) );
if( SUCCEEDED(hr) )
printFolder( (long)6 );
CoUninitialize();
}
void printFolder( _variant_t vPath )
{
Shell32::FolderPtr f = NULL;
Shell32::FolderItemsPtr itms = NULL;
Shell32::FolderItemPtr itm = NULL;
Shell32::IShellLinkDualPtr l = NULL;
f = sh->NameSpace( vPath );
itms = f->Items();
for( long i=0; i<=itms->Count-1; i++ )
{
itm = itms->Item(i);
TRACE( "%s ", (char*)itm->Name );
TRACE( "%d ", itm->IsLink );
if( itm->IsLink )
{
l = itm->GetGetLink();
TRACE( "%s", (char*)l->Path );
if( NULL != strstr((char*)l->Path, stra) ) AfxMessageBox("got!");
if( NULL != strstr((char*)itm->Name, stra) ) AfxMessageBox("got!");
}
else
{
printFolder( itm->Path );
}
TRACE( "\n" );
}
}Top
2 楼zzyx(菜农)回复于 2003-06-04 16:39:19 得分 0
blueblood7() 太cool了Top
3 楼xiaohedou(小河豆(充电中.18%.))回复于 2003-06-05 14:02:36 得分 0
经典!
#import "shell32.dll"
hr = CoInitialize(NULL);
...
hr = sh.CreateInstance( __uuidof(Shell) );
...
printFolder( (long)6 );
CoUninitialize();
绝妙!Top
4 楼xiaohedou(小河豆(充电中.18%.))回复于 2003-06-05 14:07:01 得分 0
我说的是blueblood7Top




