bsp; .wFunc = FO_MOVE End With For i = 0 To List1.ListCount - 1 If List1.Selected(i) Then ''''如果文件被选中则拷贝文件 tCopy.pFrom = List1.List(i) SHFileOperation tCopy End If Next i UpdateList End If Kill sFile End Sub
Private Sub Command3_Click() ''''执行文件删除操作 Dim sPath As String Dim tCopy As SHFILEOPSTRUCT Dim i As Integer
With tCopy .hwnd = Form1.hwnd .lpszProgressTitle = "正在删除" .pTo = sPath .fFlags = FOF_ALLOWUNDO .wFunc = FO_DELETE End With For i = 0 To List1.ListCount - 1 If List1.Selected(i) Then tCopy.pFrom = List1.List(i) SHFileOperation tCopy End If Next i UpdateList Kill sFile End Sub
Private Sub Form_Load() Dim hFileHandle As Long Dim TextLine As String
''''sFile接受由Windows外壳扩展库contextmenu.dll传递过来的文件参数 sFile = Command$ hFileHandle = FreeFile Open sFile For Input As hFileHandle Do While Not EOF(hFileHandle) Line Input #1, TextLine If Dir$(TextLine) <> "" Then List1.AddItem TextLine End If Loop Close hFileHandle End Sub
Private Sub Form_Unload(Cancel As Integer) If Dir$(sFile) <> "" Then Kill sFile End If End Sub
Private Sub List1_Click() If Not Command1.Enabled Then Command1.Enabled = True Command2.Enabled = True Command3.Enabled = True End If End Sub 保存文件并将工程文件编译为FileOP.exe文件,将文件拷贝到C盘根目录下。然后注册contextmenu.dll,注册的方法是,在DOS窗口中进入Windows\system子目录,输入 Regsvr32 x:\xxxxx\contextmenu.dll 。其中x:\xxxxx\为Contextmenu.dll文件所在的驱动器和目录。如果注册成功,系统会弹出对话框,显示 DllRegisterServer in ..\xxx\contextmenu.dll Success 提示注册成功。 注册成功后,再选择文件并单击右键,就会发现在弹出菜单中多了一个“执行文件操作”的菜单项,点击该项,系统就会调用FileOP.exe执行文件操作,在窗口的列表框中会出现用户选择的文件名,点击相应的文件并点击“拷贝”、“移动”或“删除”按钮就可以对列表框中的选中的文件进行相应的操作。