//
PB11里直接按网上的写法。执行是有OK有错误。还是pfrom和pto末尾需要两个null字符的问题。本想在string后面直接加两个字符,也是不行(因为字符串后面你加再多的"\0"都不起作用,null本来就是字符串的结束符--我是这样理解的)。后面看到blob的例子。方才搞定。看来对数据块的引用传递时,还是blob好。另外记得EncodingANSI!
声明:
Function long SHFileOperation(ref SHFILEOPSTRUCT lpFileOp) Library "shell32.dll" Alias FOR "SHFileOperationA;ansi"
//变量
Private Constant int FO_MOVE = 1 // &H1
Private Constant int FO_COPY = 2 //&H2
Private Constant int FO_DELETE =3 //&H3
Private Constant int FO_RENAME =4 //&H4
Private Constant int FOF_NOCONFIRMATION =16 //&H10
Private Constant int FOF_SILENT = 4 //&H4
Private Constant int FOF_NOERRORUI = 1024 //&H400
//stru
type SHFILEOPSTRUCT from structure
uLong hwnd
uLong wFunc
blob pFrom
blob pTo
long fFlags
long fAnyOperationsAborted
long hNameMappings
string lpszProgressTitle
end type
//func
//public function long of_rename_file (long lfrmhwnd, string sfrom, string sto, boolean fshowprogress)
SHFILEOPSTRUCT udtPath
udtPath.hwnd = lfrmhWnd
udtPath.wFunc = FO_RENAME
udtPath.pFrom = blob(sfrom,EncodingANSI!) + blob(char(0),EncodingANSI!) + blob(char(0),EncodingANSI!)
udtPath.pTo = blob(sto,EncodingANSI!) + blob(char(0),EncodingANSI!) + blob(char(0),EncodingANSI!)
long ll_bitvalues[]
ll_bitvalues[1] = FOF_NOCONFIRMATION
ll_bitvalues[2] = FOF_NOERRORUI
If fShowProgress then
ll_bitvalues[3] = 0
else
ll_bitvalues[3] = FOF_SILENT
end if
udtPath.fFlags = gf_bit_or(ll_bitvalues)
return SHFileOperation(udtPath)