C#调用系统的复制、移动、删除文件对话框

3 篇文章 0 订阅
3 篇文章 0 订阅

arp]  view plain copy
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Text;  
  7. using System.Windows.Forms;  
  8. using System.Runtime.InteropServices;  
  9. namespace Learn  
  10. {  
  11.     public partial class Form1 : Form  
  12.     {  
  13.         [DllImport("shell32.dll", SetLastError = true, CharSet = CharSet.Unicode)]  
  14.         private static extern bool  SHFileOperation([In, Out]  SHFILEOPSTRUCT str);  
  15.         private const int FO_MOVE = 0x1;  
  16.         private const int FO_COPY = 0x2;  
  17.         private const int FO_DELETE = 0x3;  
  18.         private const ushort FOF_NOCONFIRMATION = 0x10;  
  19.         private const ushort FOF_ALLOWUNDO = 0x40;  
  20.         [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]  
  21.         public class SHFILEOPSTRUCT  
  22.         {  
  23.             public IntPtr hwnd;  
  24.             /// <summary>  
  25.             /// 设置操作方式,移动:FO_MOVE,复制:FO_COPY,删除:FO_DELETE  
  26.             /// </summary>  
  27.             public UInt32 wFunc;  
  28.             /// <summary>  
  29.             /// 源文件路径  
  30.             /// </summary>  
  31.             public string pFrom;  
  32.             /// <summary>  
  33.             /// 目标文件路径  
  34.             /// </summary>  
  35.             public string pTo;  
  36.             /// <summary>  
  37.             /// 允许恢复  
  38.             /// </summary>  
  39.             public UInt16 fFlags;  
  40.             /// <summary>  
  41.             /// 监测有无中止  
  42.             /// </summary>  
  43.             public Int32 fAnyOperationsAborted;  
  44.             public IntPtr hNameMappings;  
  45.             /// <summary>  
  46.             /// 设置标题  
  47.             /// </summary>  
  48.             public string lpszProgressTitle;  
  49.         }  
  50.         public Form1()  
  51.         {  
  52.             InitializeComponent();  
  53.         }  
  54.    
  55.         private void button1_Click(object sender, EventArgs e)  
  56.         {  
  57.             MessageBox.Show(CopyFile().ToString());  
  58.         }  
  59.         private bool CopyFile()  
  60.         {  
  61.             SHFILEOPSTRUCT pm = new SHFILEOPSTRUCT();  
  62.             pm.wFunc = FO_COPY;  
  63.             pm.pFrom = @"F:/Office2003sp2_xunchi.exe";  
  64.             pm.pTo = @"c:/a.exe";  
  65.             pm.fFlags = FOF_ALLOWUNDO;//允许恢复  
  66.             pm.lpszProgressTitle = "哈哈";  
  67.             return !SHFileOperation(pm);  
  68.    
  69.         }  
  70.     }  
  71. }  
  72.    

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值