//桌面图标排圆圈
//根据4920614代码修改 http://www.ecranesoft.com/bbs/showtopic-9744.aspx

import winex;
import win.ui;
/*DSG{{*/
var winform = win.form(parent=...; text="桌面图标排圆圈";right=333;bottom=93 )
winform.add( 
button={ bottom=36;text="桌面图标排个圈圈";left=202;top=10;font=LOGFONT( name="宋体";h=-12 );z=1;right=315;cls="button" };
static={ right=111;bottom=33;text="圈圈半径(px):";left=33;top=17;font=LOGFONT( name="宋体";h=-12 );z=4;transparent=1;cls="static" };
autoOrder={ bottom=72;text="恢复自动排列";left=203;top=46;font=LOGFONT( name="宋体";h=-12 );z=2;right=316;cls="button" };
editR={ bottom=34;right=170;left=119;top=12;font=LOGFONT( name="宋体";h=-12 );z=3;text="300";edge=1;cls="edit" }
)
/*}}*/

//桌面句柄
var hDskManager,hShellView = winex.findExists("Program Manager",,"Progman","SHELLDLL_DefView")

import win.ui.ctrl.listview;
listview = win.ui.ctrl.listview();
listview.hwnd = win.findEx(hShellView,0,"SysListView32");//桌面图标列表控件

winform.button.oncommand = function(id,event){

    //取消桌面右键对齐到网格 
	listview.setExtended(0x80000/*_LVS_EX_SNAPTOGRID*/,false)
    //取消桌面自动排列
    listview.modifyStyle(0x100/*_LVS_AUTOARRANGE*/); 

	var scrWidth,scrHeight = win.getScreen()
    var centerX = scrWidth/2;
    var centerY = scrHeight/2;
   	var r =  math.min(
    	tonumber(winform.editR.text),
    	math.min(centerX,centerY)
    ) 
    
    var count = listview.count //桌面图标个数
    var rad = 2*math.pi/count; //相邻图标间的弧度2π/count   
    for(i=1;count ){ 
        var x=centerX+math.floor(r*math.sin(i*rad)); // 图标的X坐标 
        var y=centerY+math.floor(r*math.cos(i*rad));// 图标的Y坐标 
        
        win.delay(10)
        listview.setItemPos(i,x,y) 
    }  
}



winform.autoOrder.oncommand = function(id,event){
	//恢复自动排列
    listview.modifyStyle( , 0x100/*_LVS_AUTOARRANGE*/ );
    listview.setExtended(0x80000/*_LVS_EX_SNAPTOGRID*/,true) 
    
/*
    import win.reg;
    reg = win.reg("HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Update")
    reg.setDwValue("UpdateMode",1) 
    reg.close()
*/
}

winform.show() 
win.loopMessage();
return winform;
