#include <WindowsAPI.js>
Screen=new dobject("TScreen");

search_browser=new dobject("MiniBrowser");
search_browser.SetNoMenu();
search_browser.SetNoTitle();
//search_browser.SetSilent();

w=667;
h=520;

search_browser.SetPosition((Screen.WorkAreaWidth-w)/2,(Screen.WorkAreaHeight-h)/2,w,h);

hParentRgn=CreateRoundRectRgn(10,10,w-9,h-1,5,5);
SetWindowRgn(search_browser.GetHandle(),hParentRgn,true);
DeleteObject(hParentRgn);

search_browser.Show();

search_browser.Navigate2("file://"+System.GetAppPath()+"search.htm");

function DWE_CreateDesktopShortcut_WhileSearch(widget_name,description)
{
  widget_path=System.GetFileNameByWidgetName(widget_name,description);
  WshShell=new ActiveXObject( "WScript.Shell" );
  shutcut_path=WshShell.SpecialFolders("Desktop");

  ShellLink=WshShell.CreateShortcut(shutcut_path + "\\" + widget_name + ".lnk");
  ShellLink.TargetPath=System.GetAppPath()+"DucelandWidgetsEngine.exe";
  ShellLink.WindowStyle=1;
  ShellLink.Description=description;
  ShellLink.WorkingDirectory=System.GetAppPath();
  ShellLink.Arguments="\""+widget_path+"\" -r";
  ShellLink.Save();
  WshShell=null;
}

var Downloading=false;
function DWE_Download_WhileSearch(url)
{
 if(Downloading)
   Downloading=true;
   
 search_browser.InvokeFunction("ShowTip","正在下载");

 temp_fn=System.GetAppPath()+"OnlineWidgets\\temp~.dwidget";
 if(!System.DownloadFile(url,temp_fn))
 {
   alert("下载失败");
 }
 else
 if(!System.UnpackWidget(temp_fn))
 {
   alert("解包失败");
 }else
 {
   Downloading=false;

   name=System.GetWidgetNameByFileName(temp_fn);
   System.MakeWidgetToTop(name);

   search_browser.InvokeFunction("ShowTip","下载成功");
 }
}
