//file 剪贴板文件
import win;
import win.clip
namespace win.clip.file;
namespace ..win.clip;
  
class DROPFILES{ 
   INT pFiles = 20; //The offset of the file list from the beginning of this structure, in bytes
   struct pt = {int x;int y};
   bool fNC;
   bool fWide;    
}
var uDropEffect = RegisterClipboardFormat('Preferred DropEffect') 

file.write = function(file,effect="copy"){
	if(!OpenClipboard(0))
		return;	
			
	EmptyClipboard();
	
	var clipbuffer = ::GlobalAlloc(0x40/*_GMEM_ZEROINIT*/ | 0x2/*_GMEM_MOVEABLE*/ | 0x2000/*_GMEM_DDESHARE*/, 4);
    var buffer =  ::GlobalLock(clipbuffer);
    ::CopyMemoryByStruct(buffer,{int effect = ( effect="copy"? 1/*_DROPEFFECT_COPY*/ :2/*_DROPEFFECT_MOVE*/)  },4);
    ::GlobalUnlock(clipbuffer);
    var hdl =  SetClipboardData(uDropEffect,clipbuffer);
		
	var clipbuffer = ::GlobalAlloc(0x40/*_GMEM_ZEROINIT*/ | 0x2/*_GMEM_MOVEABLE*/ | 0x2000/*_GMEM_DDESHARE*/, 20 + #file + 2);
    var buffer =  ::GlobalLock(clipbuffer);
    var stDrop = DROPFILES();
    ::CopyMemoryByStruct(buffer,stDrop,20/*raw.sizeof(DROPFILES()*/);
    buffer = topointer(tonumber(buffer) + 20)
    ::CopyMemory(buffer,file,#file);
	::GlobalUnlock(clipbuffer); 
	var hdl =  SetClipboardData(0xF/*_CF_HDROP*/,clipbuffer);
	CloseClipboard();
	return hdl;
}


file.read = function(){

	if(!OpenClipboard(0))
		return;	
	
	var file = {}; 
	var effect;
	var hdrop = GetClipboardData(15) 
	if(hdrop) {
		effect = GetClipboardData(uDropEffect)  
		if( !effect)
			 effect = "copy"
		else {
			effect  = ..raw.convert(effect,{int num}).num;
			if(  effect & 1/*_DROPEFFECT_COPY*/  )
				effect = "copy"
			elseif( effect & 2/*_DROPEFFECT_MOVE*/ )
				effect = "move"	 
		}
		
		file = ..win.getDropFile(hdrop,false) 
    }
     
	CloseClipboard() 
	
	return file,effect;
		
}
//http://wenku.baidu.com/view/b5498b5abe23482fb4da4c94.html

/**intellisense(win.clip.file)
read() = 返回剪贴板文件路径列表,\n第二个返回值指明复制类型,复制为"copy",剪切则为"move"
write(.(文件) = 将文件复制到剪贴板
write(.(文件,"copy") = 将文件复制到剪贴板
write(.(文件,"move") = 将文件剪切到剪贴板
end intellisense**/

 /**intellisense()
_CF_HDROP=@0xF/*_CF_HDROP*/
_DROPEFFECT_NONE=@0/*_DROPEFFECT_NONE*/
_DROPEFFECT_COPY=@1/*_DROPEFFECT_COPY*/
_DROPEFFECT_MOVE=@2/*_DROPEFFECT_MOVE*/
_DROPEFFECT_LINK=@4/*_DROPEFFECT_LINK*/
_DROPEFFECT_SCROLL=@0x80000000/*_DROPEFFECT_SCROLL*/
end intellisense**/