AkelPad Forum Index AkelPad
Support forum
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Scripts collection
Goto page Previous  1, 2, 3 ... , 17, 18, 19  Next
 
Post new topic   Reply to topic    AkelPad Forum Index -> Plugins
View previous topic :: View next topic  
Author Message
Andrey_A_A



Joined: 03 Jun 2010
Posts: 559
Location: Сочи, Хоста

PostPosted: Fri Jan 10, 2014 1:30 pm    Post subject: Reply with quote

На днях готовил релиз AkelPad Image, собралось немало интересных наработок.

Выкладываю одним архивом 130 скриптов, написанных с 2010 года на vbs (возможно что-то из этого списка понравится и принесёт пользу)

Архив скриптов

Список с описанием всех скриптов

Если нужно будет, то архив можно залить на внутренний ресурс и добавить ссылку на первую страницу.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
KDJ



Joined: 06 Mar 2010
Posts: 1373
Location: Poland

PostPosted: Fri Jan 10, 2014 8:30 pm    Post subject: Reply with quote

Right click on LineBoard panel, calls any script or ContextMenu::Show instead of LineBoard menu.

LineBoardRClickPanel.js

Code:
/*
LineBoardRClickPanel.js - ver. 2014-02-02 (x86/x64)

Right click on LineBoard panel, calls any script or ContextMenu::Show instead of LineBoard menu.

Usage:
  Call("Scripts::Main", 1, "LineBoardRClickPanel.js", '"ScriptOrMenu" "Parameters"')

Arguments (are optional):
  "ScriptOrMenu"
    script name or submenu defined in ContextMenu::Show, default is "LineBoardBookmarks.js"
  "Parameters"
    parameters passed to the script; if script is "LineBoardBookmarks.js", default parameter is "MM"

Notes:
  After first call, the script resides in the memory.
  Second script call, closes the script.

For autostart, in AkelPad.ini or registry CmdLineBegin key, need to add eg:
  /Call("Scripts::Main", 1, "LineBoardRClickPanel.js")
    show menu from script LineBoardBookmarks.js at mouse cursor position
  /Call("Scripts::Main", 1, "LineBoardRClickPanel.js", '"Bookmarks"')
    show user submenu "Bookmarks" from ContextMenu plugin at cursor position
      #menu example
      "Bookmarks"
      {
        "Set bookmarks"
        {
          -"In selection" Call("Scripts::Main", 1, "LineBoardBookmarks.js", "BS")
          -"All" Call("Scripts::Main", 1, "LineBoardBookmarks.js", "B")
        }
        "Delete bookmarks"
        {
          -"In selection" Call("Scripts::Main", 1, "LineBoardBookmarks.js", "US")
          -"All" Call("Scripts::Main", 1, "LineBoardBookmarks.js", "U"')
        }
        "Inverse bookmarks"
        {
          -"In selection" Call("Scripts::Main", 1, "LineBoardBookmarks.js", "IS")
          -"All" Call("Scripts::Main", 1, "LineBoardBookmarks.js", "I"')
        }
        SEPARATOR
        "Settings" Call("LineBoard::Settings")
      }
*/

var hScript = AkelPad.ScriptHandle(WScript.ScriptName, 3 /*SH_FINDSCRIPT*/);

if (hScript && AkelPad.ScriptHandle(hScript, 13 /*SH_GETMESSAGELOOP*/))
{
  //script already is running, close it
  AkelPad.ScriptHandle(hScript, 33 /*SH_CLOSESCRIPT*/);
}
else
{
  var hSubClassEdit = AkelPad.WindowSubClass(2 /*WSC_EDITPROC*/, EditCallback, 123 /*WM_CONTEXTMENU*/);
  var sArg0, sArg1;
  var bMenu;

  if (hSubClassEdit)
  {
    if (WScript.Arguments.length)
    {
      sArg0 = WScript.Arguments(0).toUpperCase();

      if ((sArg0.slice(-3) == ".JS") || (sArg0.slice(-4) == ".VBS"))
      {
        if (WScript.Arguments.length > 1)
          sArg1 = WScript.Arguments(1);
        else if (sArg0 == "LINEBOARDBOOKMARKS.JS")
          sArg1 = "MM";
      }
      else
        bMenu = true;
    }
    else
    {
      sArg0 = "LineBoardBookmarks.js";
      sArg1 = "MM";
    }

    //Allow other scripts running
    AkelPad.ScriptNoMutex();

    //Message loop
    AkelPad.WindowGetMessage();

    AkelPad.WindowUnsubClass(2 /*WSC_EDITPROC*/);
  }
}

function EditCallback(hWnd, uMsg, wParam, lParam)
{
  if ((uMsg == 123 /*WM_CONTEXTMENU*/) && AkelPad.IsPluginRunning("LineBoard::Main") && IsRClickPanel(hWnd, lParam & 0xFFFF, (lParam >> 16) & 0xFFFF))
  {
    AkelPad.WindowNoNextProc(hSubClassEdit);

    if (bMenu)
      AkelPad.Call("ContextMenu::Show", 1, "-6", "-6", -1, sArg0);
    else
      AkelPad.Call("Scripts::Main", 1, sArg0, sArg1);

    AkelPad.WindowNoNextProc(hSubClassEdit);
  }

  return 0;
}

function IsRClickPanel(hWnd, nCursorX, nCursorY)
{
  var lpRect = AkelPad.MemAlloc(16 /*sizeof(RECT)*/);

  //get rectangle outside panels
  AkelPad.CallW("LineBoard::Main", 11, hWnd, 0, lpRect);

  AkelPad.SystemFunction().Call("User32::ClientToScreen", hWnd, lpRect);
  AkelPad.SystemFunction().Call("User32::ClientToScreen", hWnd, lpRect + 8);

  var nX = AkelPad.MemRead(lpRect,      3 /*DT_DWORD*/);
  var nY = AkelPad.MemRead(lpRect +  4, 3 /*DT_DWORD*/);
  var nH = AkelPad.MemRead(lpRect + 12, 3 /*DT_DWORD*/);
  AkelPad.MemFree(lpRect);

  if ((nCursorX <= nX) && (nCursorY >= nY) && (nCursorY <= nH))
    return true;

  return false;
}


Last edited by KDJ on Sun Feb 02, 2014 7:54 pm; edited 1 time in total
Back to top
View user's profile Send private message
KDJ



Joined: 06 Mar 2010
Posts: 1373
Location: Poland

PostPosted: Wed Jan 29, 2014 7:24 pm    Post subject: Reply with quote

Preview of AkelPad docs files (...\AkelPad\AkelFiles\Docs\).

AkelPadDocsView.js

Code:
// AkelPadDocsView.js - ver. 2014-09-18 (x86/x64)
//
// Preview of AkelPad docs files (...\AkelPad\AkelFiles\Docs\)
//
// Usage:
//   Call("Scripts::Main", 1, "AkelPadDocsView.js")
//
// Required to include: BrowseForFolder_function.js and CreateDialog_functions.js
//
// Keyboard and mouse:
//   Tab - rigth <-> left panel
//   Ctrl(+Shift)+Tab - next/previous document
//   F1 - menu
//   F4 - maximize/restore window (also Alt+Enter)
//   double click on document name - open/close file in AkelPad
//
// Remark:
//   For proper operation of preview the files "AkelHelp-*.htm" on Win7, AkelPad must be run as administrator.

var oSys   = AkelPad.SystemFunction();
var sClass = "AkelPad::Scripts::" + WScript.ScriptName + "::" + AkelPad.GetInstanceDll();

if (IsScriptRunning() || (! (AkelPad.Include("BrowseForFolder_function.js") && AkelPad.Include("CreateDialog_functions.js"))))
  WScript.Quit();

GetLangStrings();

var oFSO         = new ActiveXObject("Scripting.FileSystemObject");
var hMainWnd     = AkelPad.GetMainWnd();
var sAltDir      = "";
var sFindText    = "";
var bCaseFT      = 0;
var bAllDocFT    = 1;
var nDirectFT    = 0;
var bWordWrap    = 0;
var bSeparateWnd = 0;
var nLang        = 0;
var nAPDSel      = 0;
var aAPD         = [];
var aAESel       = [{}, {}];
var aIsLang;
var oIE;
var hWndIE;
var hWndIEServer;
var bCloseDlg;
var bNewFT;

var nTextMax = 512;
var lpTextLV = AkelPad.MemAlloc(nTextMax * 2);
var lpLVITEM = AkelPad.MemAlloc(_X64 ? (72) : (60)); //sizeof(LVITEM)
AkelPad.MemCopy(lpLVITEM, 0x0001 /*LVIF_TEXT*/, 3 /*DT_DWORD*/);
AkelPad.MemCopy(lpLVITEM + (_X64 ? 24 : 20), lpTextLV, 2 /*DT_QWORD*/);
AkelPad.MemCopy(lpLVITEM + (_X64 ? 32 : 24), nTextMax, 3 /*DT_DWORD*/);

var IDFILE  = 1000;
var IDNAME  = 1001;
var IDTEXT  = 1002;
var IDLANG1 = 1003;
var IDLANG2 = 1004;
var IDMENU  = 1005;
var IDCLOSE = 1006;
var aDlg    = [];

aDlg.Class    = sClass;
aDlg.Title    = sTxtDlgTitle;
aDlg.Style    = WS_POPUP|WS_CAPTION|WS_SYSMENU|WS_SIZEBOX|WS_MINIMIZEBOX|WS_MAXIMIZEBOX;
aDlg.Callback = DlgCallback;
aDlg.CtlFirst = IDFILE;
aDlg.CtlStyle = WS_VISIBLE;
aDlg.CtlFont  = oSys.Call("Gdi32::GetStockObject", 17 /*DEFAULT_GUI_FONT*/);
aDlg.MinW     = 640;
aDlg.MinH     = 300;
aDlg.X        = 100;
aDlg.Y        = 100;
aDlg.W        = aDlg.MinW;
aDlg.H        = aDlg.MinH;
aDlg.Maxim    = 0;

aDlg[IDFILE]  = {Class: "STATIC",        Style: SS_CENTER};
aDlg[IDNAME]  = {Class: "SysListView32", Style: WS_BORDER|LVS_NOSORTHEADER|LVS_SHOWSELALWAYS|LVS_SINGLESEL|LVS_REPORT};
aDlg[IDTEXT]  = {Class: "AkelEditW",     Style: WS_BORDER|WS_VSCROLL|WS_HSCROLL|ES_READONLY|ES_MULTILINE};
aDlg[IDLANG1] = {Style: BS_AUTORADIOBUTTON, Title: sTxtEnglish};
aDlg[IDLANG2] = {Style: BS_AUTORADIOBUTTON, Title: sTxtRussian};
aDlg[IDMENU]  = {Title: sTxtMenu};
aDlg[IDCLOSE] = {Title: sTxtClose};

var IDFTWHAT   = 2000;
var IDFTTEXT   = 2001;
var IDFTCASE   = 2002;
var IDFTALLDOC = 2003;
var IDFTDIRECT = 2004;
var IDFTBEGIN  = 2005;
var IDFTDOWN   = 2006;
var IDFTUP     = 2007;
var IDFTEND    = 2008;
var IDFTFIND   = 2009;
var IDFTCANCEL = 2010;
var aDlgFT     = [];

aDlgFT.Title    = sTxtFindInTxt;
aDlgFT.Style    = WS_POPUP|WS_VISIBLE|WS_CAPTION|WS_SYSMENU;
aDlgFT.W        = 275;
aDlgFT.H        = 138;
aDlgFT.Callback = FTDlgCallback;
aDlgFT.CtlFirst = IDFTWHAT;
aDlgFT.PosPix   = 1;
aDlgFT.PosPar   = 2;
aDlgFT.PosEdge  = "CC";
aDlgFT.CtlStyle = WS_VISIBLE;
aDlgFT.CtlFontN = "MS Shell Dlg";

aDlgFT[IDFTWHAT]   = {X:  10, Y:  13, W:  30, H: 13, Title: sTxtWhat,      Class: "STATIC"};
aDlgFT[IDFTTEXT]   = {X:  40, Y:  10, W: 225, H: 21,                       Class: "EDIT",   Style: WS_TABSTOP|ES_AUTOHSCROLL, ExStyle: WS_EX_CLIENTEDGE};
aDlgFT[IDFTCASE]   = {X:  10, Y:  35, W:  85, H: 20, Title: sTxtMatchCase, Class: "BUTTON", Style: WS_TABSTOP|BS_AUTOCHECKBOX};
aDlgFT[IDFTALLDOC] = {X:  10, Y:  55, W:  85, H: 20, Title: sTxtAllDocs,   Class: "BUTTON", Style: WS_TABSTOP|BS_AUTOCHECKBOX};
aDlgFT[IDFTDIRECT] = {X: 105, Y:  37, W:  80, H: 91, Title: sTxtDirection, Class: "BUTTON", Style: BS_GROUPBOX};
aDlgFT[IDFTBEGIN]  = {X: 113, Y:  53, W:  65, H: 16, Title: sTxtBeginning, Class: "BUTTON", Style: BS_AUTORADIOBUTTON};
aDlgFT[IDFTDOWN]   = {X: 113, Y:  71, W:  65, H: 16, Title: sTxtDown,      Class: "BUTTON", Style: BS_AUTORADIOBUTTON};
aDlgFT[IDFTUP]     = {X: 113, Y:  89, W:  65, H: 16, Title: sTxtUp,        Class: "BUTTON", Style: BS_AUTORADIOBUTTON};
aDlgFT[IDFTEND]    = {X: 113, Y: 107, W:  65, H: 16, Title: sTxtEnd,       Class: "BUTTON", Style: BS_AUTORADIOBUTTON};
aDlgFT[IDFTFIND]   = {X: 195, Y:  79, W:  70, H: 23, Title: sTxtFindNext,  Class: "BUTTON", Style: WS_TABSTOP|BS_DEFPUSHBUTTON};
aDlgFT[IDFTCANCEL] = {X: 195, Y: 105, W:  70, H: 23, Title: sTxtCancel,    Class: "BUTTON", Style: WS_TABSTOP|BS_PUSHBUTTON};

AkelPad.ScriptNoMutex();
AkelPad.WindowRegisterClass(sClass);

while (! bCloseDlg)
{
  bCloseDlg = true;

  ReadIni();
  GetArrayAPD(hMainWnd);
  if (! aAPD.length)
    break;

  aDlg.HWND   = 0;
  aDlg.Parent = bSeparateWnd ? 0 : hMainWnd;

  CreateDialogWindow(aDlg, 1);
  oSys.Call("User32::ShowWindow", aDlg.HWND, aDlg.Maxim ? 3 /*SW_MAXIMIZE*/ : 1 /*SW_SHOWNORMAL*/);
  AkelPad.WindowGetMessage();
}

AkelPad.WindowUnregisterClass(sClass);
AkelPad.MemFree(lpTextLV);
AkelPad.MemFree(lpLVITEM);

SetForegroundWindow(hMainWnd);

function DlgCallback(hWnd, uMsg, wParam, lParam)
{
  if (uMsg == 1) //WM_CREATE
  {
    aDlg.HWND = hWnd;
    CreateDialogWindow(aDlg, 2, hWnd);
    InitDialog();
    PostMessage(hWnd, 0x8000 /*WM_APP*/, 0, 0);
  }

  else if (uMsg == 0x8000 /*WM_APP*/)
  {
    if (aAESel[nLang][aAPD[nAPDSel][0]])
      SetSelAE(aAESel[nLang][aAPD[nAPDSel][0]][0], aAESel[nLang][aAPD[nAPDSel][0]][1]);
  }

  else if (uMsg == 7) //WM_SETFOCUS
    oSys.Call("User32::SetFocus", aDlg.Focus);

  else if (uMsg == 36) //WM_GETMINMAXINFO
  {
    AkelPad.MemCopy(lParam + 24, Scale.X(aDlg.MinW), 3 /*DT_DWORD*/); //ptMinTrackSize_x
    AkelPad.MemCopy(lParam + 28, Scale.Y(aDlg.MinH), 3 /*DT_DWORD*/); //ptMinTrackSize_y
  }

  else if (uMsg == 3) //WM_MOVE
  {
    if (! (oSys.Call("User32::IsZoomed", hWnd) || oSys.Call("User32::IsIconic", hWnd)))
      GetWindowPos(hWnd, aDlg);
  }

  else if (uMsg == 5) //WM_SIZE
  {
    if (wParam == 0 /*SIZE_RESTORED*/)
      GetWindowPos(hWnd, aDlg);

    ResizeDlg(LoWord(lParam), HiWord(lParam));
  }

  else if (uMsg == 20) //WM_ERASEBKGND
    PostMessage(hWnd, 0x8001 /*WM_APP+1*/, 0, 0);

  else if (uMsg == 0x8001 /*WM_APP+1*/)
  {
    if (IEIsRunning() && oIE.Visible)
      oSys.Call("User32::RedrawWindow", hWndIE, 0, 0, 0x0485 /*RDW_ERASE|RDW_FRAME|RDW_INVALIDATE|RDW_ALLCHILDREN*/);
  }

  else if (uMsg == 15) //WM_PAINT
    PaintSizeGrip();

  else if (uMsg == 256) //WM_KEYDOWN
  {
    if (wParam == 9 /*VK_TAB*/)
    {
      if (Ctrl())
      {
        if (Shift())
        {
          if (--nAPDSel < 0)
            nAPDSel = aAPD.length - 1;
        }
        else
        {
          if (++nAPDSel >= aAPD.length)
            nAPDSel = 0;
        }

        SetCurSelLV(nAPDSel);

        if (IEIsRunning() && oIE.Visible)
        {
          if (aDlg.Focus == aDlg[IDTEXT].HWND)
            aDlg.Focus = hWndIEServer;
        }
        else if (aDlg.Focus != aDlg[IDNAME].HWND)
          aDlg.Focus = aDlg[IDTEXT].HWND;
      }
      else
      {
        if (aDlg.Focus == aDlg[IDNAME].HWND)
        {
          if (IEIsRunning() && oIE.Visible)
            aDlg.Focus = hWndIEServer;
          else
            aDlg.Focus = aDlg[IDTEXT].HWND;
        }
        else
          aDlg.Focus = aDlg[IDNAME].HWND;
      }
      oSys.Call("User32::SetFocus", aDlg.Focus);
    }
    else if ((wParam == 0x43 /*C key*/) || (wParam == 0x2D /*VK_INSERT*/))
    {
      if  (Ctrl() && (! Alt()))
      {
        if (aDlg.Focus == aDlg[IDNAME].HWND)
          InsertNameTo(! Shift(), false);
        else if (aDlg.Focus == aDlg[IDTEXT].HWND)
          InsertTextTo(! Shift());
      }
    }
    else if (wParam == 0x46 /*F key*/)
    {
      if (Ctrl() && (! Shift()) && (! Alt()))
        FTDialog();
    }
    else if (wParam == 0x55 /*U key*/)
    {
      if (Ctrl() && (! Shift()) && (! Alt()))
      {
        bWordWrap = ! bWordWrap;
        SetWordWrapAE();
      }
    }
    else if (wParam == 0x70 /*VK_F1*/)
    {
      if ((! Ctrl()) && (! Shift()))
        MenuMain();
    }
    else if (wParam == 0x72 /*VK_F3*/)
    {
      if (! Ctrl())
        FindTextNext(Shift() ? 2 : 1);
    }
    else if (wParam == 0x73 /*VK_F4*/)
    {
      if ((! Ctrl()) && (! Shift()))
        oSys.Call("User32::ShowWindow", hWnd, oSys.Call("User32::IsZoomed", hWnd) ? 9 /*SW_RESTORE*/ : 3 /*SW_MAXIMIZE*/);
    }
    else if (wParam == 13 /*VK_RETURN*/)
    {
      if ((aDlg.Focus == aDlg[IDNAME].HWND) && (Ctrl() || Shift()) && !Alt())
        OpenOrCloseFile();
    }
    else if (wParam == 27 /*VK_ESCAPE*/)
      PostMessage(hWnd, 16 /*WM_CLOSE*/, 0, 0);
  }

  else if (uMsg == 260) //WM_SYSKEYDOWN
  {
    if ((wParam == 0x43 /*C key*/) || (wParam == 0x2D /*VK_INSERT*/))
    {
      if (aDlg.Focus == aDlg[IDNAME].HWND)
        InsertNameTo(! Shift(), true);
    }
    else if ((wParam == 13 /*VK_RETURN*/) && (! Shift()))
      oSys.Call("User32::ShowWindow", hWnd, oSys.Call("User32::IsZoomed", hWnd) ? 9 /*SW_RESTORE*/ : 3 /*SW_MAXIMIZE*/);
  }

  else if ((uMsg == 0x004E /*WM_NOTIFY*/) && (wParam == IDNAME))
  {
    switch (AkelPad.MemRead(lParam + (_X64 ? 16 : 8), 3 /*DT_DWORD*/))
    {
      case -101 : //LVN_ITEMCHANGED
        if (AkelPad.MemRead(lParam + (_X64 ? 32 : 20) /*NMLISTVIEW.uNewState*/, 3 /*DT_DWORD*/) & 0x2 /*LVIS_SELECTED*/)
        {
          nAPDSel = GetCurSelLV();
          SendMessage(aDlg[IDFILE].HWND, 12 /*WM_SETTEXT*/, 0, aAPD[nAPDSel][2]);

          if ((aAPD[nAPDSel][2].slice(-3) == "htm") && oFSO.FileExists(aAPD[nAPDSel][2]) && (! IEIsRunning()))
            IERun();

          if ((aAPD[nAPDSel][2].slice(-3) == "htm") && oFSO.FileExists(aAPD[nAPDSel][2]) && IEIsRunning())
          {
            oSys.Call("User32::ShowWindow", aDlg[IDTEXT].HWND, 0 /*SW_HIDE*/);
            oIE.Visible = true;
            if (oIE.LocationName != aAPD[nAPDSel][2].substr(aAPD[nAPDSel][2].lastIndexOf("\\") + 1))
              IENavigate(aAPD[nAPDSel][2]);
          }
          else
          {
            if (IEIsRunning())
              oIE.Visible = false;
            oSys.Call("User32::ShowWindow", aDlg[IDTEXT].HWND, 5 /*SW_SHOW*/);
            SendMessage(aDlg[IDTEXT].HWND, 12 /*WM_SETTEXT*/, 0, aAPD[nAPDSel][1]);

            if (aAESel[nLang][aAPD[nAPDSel][0]])
              SetSelAE(aAESel[nLang][aAPD[nAPDSel][0]][0], aAESel[nLang][aAPD[nAPDSel][0]][1]);
          }
        }
        break;
      case -3 : //NM_DBLCLK
        if (AkelPad.MemRead(lParam + (_X64 ? 24 : 12) /*NMITEMACTIVATE.iItem*/, 3 /*DT_DWORD*/) > -1)
        {
          OpenOrCloseFile();
          break;
        }
      case -2 : //NM_CLICK
      case -5 : //NM_RCLICK
      case -6 : //NM_RDBLCLK
        if (AkelPad.MemRead(lParam + (_X64 ? 24 : 12) /*NMITEMACTIVATE.iItem*/, 3 /*DT_DWORD*/) == -1)
          SetCurSelLV(GetCurFocLV());
        break;
      case -7 : //NM_SETFOCUS
        aDlg.Focus = aDlg[IDNAME].HWND;
        break;
    }
  }

  else if (uMsg == 123) //WM_CONTEXTMENU
  {
    if (wParam == aDlg[IDNAME].HWND)
      MenuName(LoWord(lParam), HiWord(lParam));
    else if (wParam == aDlg[IDTEXT].HWND)
    {
      oSys.Call("User32::SetFocus", aDlg[IDTEXT].HWND);
      MenuText(LoWord(lParam), HiWord(lParam));
    }
  }

  else if (uMsg == 273) //WM_COMMAND
  {
    var nLowParam = LoWord(wParam);
    var nHiwParam = HiWord(wParam);
    var sFind;

    if (nLowParam == IDTEXT)
    {
      if (nHiwParam == 0x0100 /*EN_SETFOCUS*/)
      {
        if (SendMessage(AkelPad.GetEditWnd(), 3227 /*AEM_GETOPTIONS*/, 0, 0) & 0x00000800 /*AECO_ACTIVELINE*/)
          SendMessage(lParam, 3228 /*AEM_SETOPTIONS*/, 2 /*AECOOP_OR*/, 0x00000800 /*AECO_ACTIVELINE*/);
        aDlg.Focus = lParam;
      }
      else if (nHiwParam == 0x0200 /*EN_KILLFOCUS*/)
      {
        SendMessage(lParam, 3228 /*AEM_SETOPTIONS*/, 4 /*AECOOP_XOR*/, 0x00000800 /*AECO_ACTIVELINE*/);
        aAESel[nLang][aAPD[nAPDSel][0]] = [GetSelStartAE(), GetSelEndAE()];
      }
    }
    else if ((nLowParam >= IDLANG1) && (nLowParam <= IDLANG2))
    {
      sFind = aAPD[nAPDSel][0].toUpperCase();
 
      CheckButtons(nLowParam);
      GetArrayAPD(hWnd);

      if (aAPD.length)
      {
        CheckButtons();
        FillLV(nAPDSel, sFind);
        oSys.Call("User32::SetFocus", aDlg.Focus);
      }
      else
        PostMessage(hWnd, 16 /*WM_CLOSE*/, 0, 0);
    }
    else if (nLowParam == IDMENU)
    {
      oSys.Call("User32::SetFocus", aDlg.Focus);
      MenuMain();
      SendMessage(aDlg[IDMENU].HWND, 0xF4 /*BM_SETSTYLE*/, BS_PUSHBUTTON, 1);
    }
    else if (nLowParam == IDCLOSE)
      PostMessage(hWnd, 16 /*WM_CLOSE*/, 0, 0);
  }

  else if (uMsg == 16) //WM_CLOSE
  {
    if (IEIsRunning())
      IEQuit();
    aAESel[nLang][aAPD[nAPDSel][0]] = [GetSelStartAE(), GetSelEndAE()];
    WriteIni();
    oSys.Call("User32::DestroyWindow", hWnd);
  }

  else if (uMsg == 2) //WM_DESTROY
    oSys.Call("User32::PostQuitMessage", 0);

  return 0;
}

function InitDialog()
{
  var hEditWnd = AkelPad.GetEditWnd();
  var lpRect;
  var lpAECOLORS;
  var lpPOINT;
  var lpLVCOLUMN;

  CheckButtons();

  //AkelEdit
  lpRect = AkelPad.MemAlloc(16); //sizeof(RECT)
  AkelPad.MemCopy(lpRect,      4, 3 /*DT_DWORD*/);
  AkelPad.MemCopy(lpRect +  4, 4, 3 /*DT_DWORD*/);
  AkelPad.MemCopy(lpRect +  8, 4, 3 /*DT_DWORD*/);
  AkelPad.MemCopy(lpRect + 12, 4, 3 /*DT_DWORD*/);
  SendMessage(aDlg[IDTEXT].HWND, 3178 /*AEM_SETRECT*/, 0x03 /*AERC_MARGINS|AERC_UPDATE*/, lpRect);
  AkelPad.MemFree(lpRect);

  SendMessage(aDlg[IDTEXT].HWND, 48 /*WM_SETFONT*/, SendMessage(hMainWnd, 1233 /*AKD_GETFONTW*/, 0, 0), true);
  SetWordWrapAE();

  if (hEditWnd)
  {
    lpAECOLORS = AkelPad.MemAlloc(17 * 4);
    AkelPad.MemCopy(lpAECOLORS, 0x0001FFFE /*AECLR_ALL*/, 3 /*DT_DWORD*/);
    SendMessage(hEditWnd, 3231 /*AEM_GETCOLORS*/, 0, lpAECOLORS);
    SendMessage(aDlg[IDTEXT].HWND, 3232 /*AEM_SETCOLORS*/, 0, lpAECOLORS);
    AkelPad.MemFree(lpAECOLORS);

    if (SendMessage(hEditWnd, 3227 /*AEM_GETOPTIONS*/, 0, 0) & 0x00001000 /*AECO_ACTIVELINEBORDER*/)
      SendMessage(aDlg[IDTEXT].HWND, 3228 /*AEM_SETOPTIONS*/, 2 /*AECOOP_OR*/, 0x00001000 /*AECO_ACTIVELINEBORDER*/);

    lpPOINT = AkelPad.MemAlloc(8);
    SendMessage(hEditWnd, 3237 /*AEM_GETCARETWIDTH*/, 0, lpPOINT);
    SendMessage(aDlg[IDTEXT].HWND, 3238 /*AEM_SETCARETWIDTH*/, 0, lpPOINT);
    AkelPad.MemFree(lpPOINT);

    SendMessage(aDlg[IDTEXT].HWND, 3260 /*AEM_SETLINEGAP*/, SendMessage(hEditWnd, 3259 /*AEM_GETLINEGAP*/, 0, 0), 0);
  }

  //ListView
  lpLVCOLUMN = AkelPad.MemAlloc(_X64 ? 56 : 44); //sizeof(LVCOLUMN)
  AkelPad.MemCopy(lpLVCOLUMN, 4 /*mask=LVCF_TEXT*/, 3 /*DT_DWORD*/);
  AkelPad.MemCopy(lpLVCOLUMN + (_X64 ? 16 : 12), lpTextLV, 2 /*DT_QWORD*/);
  AkelPad.MemCopy(lpTextLV, sTxtDocument, 1 /*DT_UNICODE*/);

  SendMessage(aDlg[IDNAME].HWND, 0x1036 /*LVM_SETEXTENDEDLISTVIEWSTYLE*/, 0x0020 /*LVS_EX_FULLROWSELECT*/, 0x0020);
  SendMessage(aDlg[IDNAME].HWND, 0x1061 /*LVM_INSERTCOLUMNW*/, 0, lpLVCOLUMN);
  AkelPad.MemFree(lpLVCOLUMN);

  FillLV(nAPDSel, AkelPad.GetSelText().toUpperCase());

  oSys.Call("User32::SetFocus", aDlg[IDTEXT].HWND);
  oSys.Call("User32::SetFocus", aDlg[IDNAME].HWND);
}

function SendMessage(hWnd, uMsg, wParam, lParam)
{
  return oSys.Call("User32::SendMessageW", hWnd, uMsg, wParam, lParam);
}

function PostMessage(hWnd, uMsg, wParam, lParam)
{
  return oSys.Call("User32::PostMessageW", hWnd, uMsg, wParam, lParam);
}

function LoWord(nDwNum)
{
  return nDwNum & 0xFFFF;
}

function HiWord(nDwNum)
{
  return (nDwNum >> 16) & 0xFFFF;
}

function MkLong(nLoWord, nHiWord)
{
  return (nLoWord & 0xFFFF) | (nHiWord << 16);
}

function Ctrl()
{
  return oSys.Call("User32::GetKeyState", 0x11 /*VK_CONTROL*/) & 0x8000;
}

function Shift()
{
  return oSys.Call("User32::GetKeyState", 0x10 /*VK_SHIFT*/) & 0x8000;
}

function Alt()
{
  return oSys.Call("user32::GetKeyState", 0x12 /*VK_MENU*/) & 0x8000;
}

function PaintSizeGrip()
{
  var lpPaint = AkelPad.MemAlloc(_X64 ? 72 : 64); //sizeof(PAINTSTRUCT)
  var lpRect  = AkelPad.MemAlloc(16); //sizeof(RECT)
  var hDC;

  if (hDC = oSys.Call("User32::BeginPaint", aDlg.HWND, lpPaint))
  {
    oSys.Call("User32::GetClientRect", aDlg.HWND, lpRect);

    AkelPad.MemCopy(lpRect,     AkelPad.MemRead(lpRect +  8, 3 /*DT_DWORD*/) - oSys.Call("User32::GetSystemMetrics",  2 /*SM_CXVSCROLL*/), 3 /*DT_DWORD*/);
    AkelPad.MemCopy(lpRect + 4, AkelPad.MemRead(lpRect + 12, 3 /*DT_DWORD*/) - oSys.Call("User32::GetSystemMetrics", 20 /*SM_CYVSCROLL*/), 3 /*DT_DWORD*/);

    oSys.Call("User32::DrawFrameControl", hDC, lpRect, 3 /*DFC_SCROLL*/, 0x8 /*DFCS_SCROLLSIZEGRIP*/);
    oSys.Call("User32::EndPaint", aDlg.HWND, lpPaint);
  }

  AkelPad.MemFree(lpPaint);
  AkelPad.MemFree(lpRect);
}

function ResizeDlg(nW, nH)
{
  var nFlags = 0x14; //SWP_NOACTIVATE|SWP_NOZORDER
  var nGapW  = Scale.X(10);
  var nGapH  = Scale.Y(10);
  var nLVW   = Scale.X(110);
  var nAEW   = nW - nLVW - 3 * nGapW;
  var i;

  oSys.Call("User32::SetWindowPos",
    aDlg[IDFILE].HWND, 0,
    nW - nAEW - nGapW,
    nGapH,
    nAEW,
    Scale.Y(13),
    nFlags);
  oSys.Call("User32::SetWindowPos",
    aDlg[IDNAME].HWND, 0,
    nGapW,
    nGapH,
    nLVW,
    nH - nGapH - Scale.Y(23) - 2 * Scale.Y(25) - 2 * Scale.Y(20),
    nFlags);
  oSys.Call("User32::SetWindowPos",
    aDlg[IDTEXT].HWND, 0,
    nW - nAEW - nGapW,
    3 * nGapH,
    nAEW,
    nH - 4 * nGapH,
    nFlags);
  if (IEIsRunning())
  {
    oSys.Call("User32::SetWindowPos",
      hWndIE, 0,
      nW - nAEW - nGapW,
      3 * nGapH,
      nAEW,
      nH - 4 * nGapH,
      nFlags);
  }
  for (i = IDLANG1; i <= IDLANG2; ++i)
  {
    oSys.Call("User32::SetWindowPos",
      aDlg[i].HWND, 0,
      Scale.X(30),
      nH - nGapH - Scale.Y(23) - 2 * Scale.Y(25) - (IDLANG2 - i) * Scale.Y(20),
      Scale.X(70),
      Scale.Y(16),
      nFlags);
  }
  for (i = IDMENU; i <= IDCLOSE; ++i)
  {
    oSys.Call("User32::SetWindowPos",
      aDlg[i].HWND, 0,
      nGapW,
      nH - nGapH - Scale.Y(23) - (IDCLOSE - i) * Scale.Y(25),
      nLVW,
      Scale.Y(23),
      nFlags);
  }

  SendMessage(aDlg[IDNAME].HWND, 0x101E /*LVM_SETCOLUMNWIDTH*/, 0, -2 /*LVSCW_AUTOSIZE_USEHEADER*/);
  SendMessage(aDlg[IDNAME].HWND, 0x1013 /*LVM_ENSUREVISIBLE*/, GetCurSelLV(), false);
}

function CheckButtons(nButton)
{
  if ((nButton == IDLANG1) || (nButton == IDLANG2))
    nLang = nButton - IDLANG1;

  SendMessage(aDlg[IDLANG1].HWND, 241 /*BM_SETCHECK*/, (nLang == 0), 0);
  SendMessage(aDlg[IDLANG2].HWND, 241 /*BM_SETCHECK*/, (nLang == 1), 0);

  oSys.Call("User32::EnableWindow", aDlg[IDLANG1].HWND, aIsLang[0]);
  oSys.Call("User32::EnableWindow", aDlg[IDLANG2].HWND, aIsLang[1]);
}

function GetWindowPos(hWnd, oRect, bClient)
{
  var lpRect = AkelPad.MemAlloc(16); //sizeof(RECT)

  if (bClient)
    oSys.Call("User32::GetClientRect", hWnd, lpRect);
  else
    oSys.Call("User32::GetWindowRect", hWnd, lpRect);

  oRect.X = AkelPad.MemRead(lpRect,      3 /*DT_DWORD*/);
  oRect.Y = AkelPad.MemRead(lpRect +  4, 3 /*DT_DWORD*/);
  oRect.W = AkelPad.MemRead(lpRect +  8, 3 /*DT_DWORD*/) - oRect.X;
  oRect.H = AkelPad.MemRead(lpRect + 12, 3 /*DT_DWORD*/) - oRect.Y;

  AkelPad.MemFree(lpRect);
}

function SetForegroundWindow(hWnd)
{
  if (! oSys.Call("User32::IsWindowVisible", hWnd))
    oSys.Call("User32::ShowWindow", hWnd, 8 /*SW_SHOWNA*/);
  if (oSys.Call("User32::IsIconic", hWnd))
    oSys.Call("User32::ShowWindow", hWnd, 9 /*SW_RESTORE*/);

  oSys.Call("User32::SetForegroundWindow", hWnd);
}

function GetSelStartAE()
{
  AkelPad.SetEditWnd(aDlg[IDTEXT].HWND);
  var nSelStart = AkelPad.GetSelStart();
  AkelPad.SetEditWnd(0);
  return nSelStart;
}

function GetSelEndAE()
{
  AkelPad.SetEditWnd(aDlg[IDTEXT].HWND);
  var nSelEnd = AkelPad.GetSelEnd();
  AkelPad.SetEditWnd(0);
  return nSelEnd;
}

function SetSelAE(nSelStart, nSelEnd)
{
  AkelPad.SetEditWnd(aDlg[IDTEXT].HWND);
  AkelPad.SetSel(nSelStart, nSelEnd);
  AkelPad.SetEditWnd(0);
}

function GetSelTextAE()
{
  AkelPad.SetEditWnd(aDlg[IDTEXT].HWND);
  var sText = AkelPad.GetSelText(0);
  AkelPad.SetEditWnd(0);
  return sText;
}

function SetWordWrapAE()
{
  SendMessage(aDlg[IDTEXT].HWND, 0x0CAA /*AEM_SETWORDWRAP*/, bWordWrap ? 1 /*AEWW_WORD*/ : 0 /*AEWW_NONE*/, 0);
}

function GetCurFocLV()
{
  return SendMessage(aDlg[IDNAME].HWND, 0x100C /*LVM_GETNEXTITEM*/, -1, 0x0001 /*LVNI_FOCUSED*/);
}

function GetCurSelLV()
{
  return SendMessage(aDlg[IDNAME].HWND, 0x100C /*LVM_GETNEXTITEM*/, -1, 0x0002 /*LVNI_SELECTED*/);
}

function SetCurSelLV(nItem)
{
  AkelPad.MemCopy(lpLVITEM + 12, 0x0003 /*LVIS_SELECTED|LVIS_FOCUSED*/, 3 /*DT_DWORD*/);
  AkelPad.MemCopy(lpLVITEM + 16, 0x0003 /*LVIS_SELECTED|LVIS_FOCUSED*/, 3 /*DT_DWORD*/);
  SendMessage(aDlg[IDNAME].HWND, 0x102B /*LVM_SETITEMSTATE*/, nItem, lpLVITEM);
  SendMessage(aDlg[IDNAME].HWND, 0x1013 /*LVM_ENSUREVISIBLE*/, nItem, false);
}

function FillLV(nSel, sFind)
{
  var i;

  SendMessage(aDlg[IDNAME].HWND, 0x000B /*WM_SETREDRAW*/, false, 0);
  SendMessage(aDlg[IDNAME].HWND, 0x1009 /*LVM_DELETEALLITEMS*/, 0, 0);

  for (i = 0; i < aAPD.length; ++i)
  {
    AkelPad.MemCopy(lpLVITEM + 4, i, 3 /*DT_DWORD*/);
    AkelPad.MemCopy(lpTextLV, aAPD[i][0], 1 /*DT_UNICODE*/);
    SendMessage(aDlg[IDNAME].HWND, 0x104D /*LVM_INSERTITEMW*/, 0, lpLVITEM);

    if (aAPD[i][0].toUpperCase() == sFind)
      nSel  = i;
  }

  if (nSel >= aAPD.length)
    nSel = aAPD.length - 1;
  if (nSel < 0)
    nSel = 0;

  SetCurSelLV(nSel);
  SendMessage(aDlg[IDNAME].HWND, 0x000B /*WM_SETREDRAW*/, true, 0);
}

function GetArrayAPD(hWnd)
{
  var aDoc = [
        ["AkelHelp",       ".htm"],
        ["AkelHistory",    ".txt"],
        ["Clipboard",      ".txt"],
        ["Coder",          ".txt"],
        ["ContextMenu",    ".txt"],
        ["Exit",           ".txt"],
        ["Explorer",       ".txt"],
        ["Fonts",          ".txt"],
        ["Format",         ".txt"],
        ["FullScreen",     ".txt"],
        ["HexSel",         ".txt"],
        ["Hotkeys",        ".txt"],
        ["LineBoard",      ".txt"],
        ["Log",            ".txt"],
        ["Macros",         ".txt"],
        ["MinimizeToTray", ".txt"],
        ["QSearch",        ".txt"],
        ["RecentFiles",    ".txt"],
        ["SaveFile",       ".txt"],
        ["Scripts",        ".txt"],
        ["Scroll",         ".txt"],
        ["Sessions",       ".txt"],
        ["SmartSel",       ".txt"],
        ["Sounds",         ".txt"],
        ["SpecialChar",    ".txt"],
        ["Speech",         ".txt"],
        ["SpellCheck",     ".txt"],
        ["Stats",          ".txt"],
        ["Templates",      ".txt"],
        ["ToolBar",        ".txt"],
        ["XBrackets",      ".txt"]];

  var aLang    = ["-Eng", "-Rus"];
  var sExt     = ".txt";
  var sDocsDir = AkelPad.GetAkelDir(2 /*ADTYPE_DOCS*/) + "\\";
  var lpFile;
  var lpDetectFile;
  var sFile;
  var nCodePage;
  var bBOM;
  var i, n;

  aIsLang     = [false, false];
  aAPD.length = 0;

  while (! (aIsLang[0] || aIsLang[1]))
  {
    if (sAltDir)
    {
      for (i = 0; i < 2; ++i)
      {
        for (n = 0; n < aDoc.length; ++n)
        {
          if (oFSO.FileExists(sAltDir + aDoc[n][0] + aLang[i] + aDoc[n][1]))
          {
            aIsLang[i] = true;
            break;
          }
        }
      }
    }

    if (aIsLang[0] || aIsLang[1])
      sDocsDir = sAltDir;
    else
    {
      for (i = 0; i < 2; ++i)
      {
        for (n = 0; n < aDoc.length; ++n)
        {
          if (oFSO.FileExists(sDocsDir + aDoc[n][0] + aLang[i] + aDoc[n][1]))
          {
            aIsLang[i] = true;
            break;
          }
        }
      }

      if (! (aIsLang[0] || aIsLang[1]))
      {
        AkelPad.MessageBox(hWnd, sTxtNoFilesInDir + "\n" + ((sAltDir && (sAltDir.toUpperCase() != sDocsDir.toUpperCase())) ? (sAltDir + "\n") : "") + sDocsDir, sTxtDlgTitle, 0x30 /*MB_ICONWARNING*/);

        if (! sAltDir)
          sAltDir = AkelPad.GetAkelDir(1 /*ADTYPE_AKELFILES*/) + "\\";

        sAltDir = BrowseForFolder(hWnd, sTxtChooseDir, sAltDir);

        if (! sAltDir)
          return;
        else if (sAltDir.slice(-1) != "\\")
          sAltDir += "\\";
      }
    }
  }

  if (! aIsLang[nLang])
    nLang = Number(! nLang);

  lpFile       = AkelPad.MemAlloc(260 * 2 /*MAX_PATH * sizeof(wchar_t)*/);
  lpDetectFile = AkelPad.MemAlloc(_X64 ? 24 : 20 /*sizeof(DETECTFILEW)*/);

  AkelPad.MemCopy(lpDetectFile, lpFile, 2 /*DT_QWORD*/);
  AkelPad.MemCopy(lpDetectFile + (_X64 ?  8 : 4), 1024, 3 /*DT_DWORD*/); //dwBytesToCheck
  AkelPad.MemCopy(lpDetectFile + (_X64 ? 12 : 8), 0x1D /*ADT_BINARY_ERROR|ADT_DETECT_CODEPAGE|ADT_DETECT_BOM|ADT_NOMESSAGES*/, 3 /*DT_DWORD*/); //dwFlags

  for (n = 0; n < aDoc.length; ++n)
  {
    sFile = sDocsDir + aDoc[n][0] + aLang[nLang] + aDoc[n][1];

    if (oFSO.FileExists(sFile))
    {
      if (aDoc[n][1] == ".htm")
          aAPD.push([aDoc[n][0], "", sFile]);
      else
      {
        AkelPad.MemCopy(lpFile, sFile, 1 /*DT_UNICODE*/);
        AkelPad.MemCopy(lpDetectFile + (_X64 ? 16 : 12), 0, 3 /*DT_DWORD*/); //nCodePage
        AkelPad.MemCopy(lpDetectFile + (_X64 ? 20 : 16), 0, 3 /*DT_DWORD*/); //bBOM

        if (SendMessage(hMainWnd, 1177 /*AKD_DETECTFILEW*/, 0, lpDetectFile) == 0 /*EDT_SUCCESS*/)
        {
          nCodePage = AkelPad.MemRead(lpDetectFile + (_X64 ? 16 : 12), 3 /*DT_DWORD*/);
          bBOM      = AkelPad.MemRead(lpDetectFile + (_X64 ? 20 : 16), 3 /*DT_DWORD*/);

          if ((nCodePage != 65000) && (nCodePage != 65001) && (nCodePage != 1200) && (nCodePage != 1201) && (nCodePage != 12000) && (nCodePage != 12001))
            nCodePage = 1251 /*ANSI Cyrillic*/;

          aAPD.push([aDoc[n][0], AkelPad.ReadFile(sFile, 0, nCodePage, bBOM).replace(/\r\n/g, "\n"), sFile]);
        }
      }
    }
  }

  AkelPad.MemFree(lpFile);
  AkelPad.MemFree(lpDetectFile);
}

function IERun()
{
  var lpCallback;
  var lpClass;
  var oRect;

  hWndIEServer = 0;

  try
  {
    oIE = new ActiveXObject("InternetExplorer.Application");
  }
  catch (oError)
  {
    AkelPad.MessageBox(aDlg.HWND, sTxtNoIE + "\n\n" + sTxtErrMessage + oError.message + "\n" + sTxtErrNumber + oError.number, sTxtDlgTitle, 0x10 /*MB_ICONERROR*/);
    return;
  }

  try
  {
    lpCallback = oSys.RegisterCallback(EnumChildProc);
  }
  catch (oError)
  {
    AkelPad.MessageBox(aDlg.HWND, sTxtNoCallback, sTxtDlgTitle, 0x10 /*MB_ICONERROR*/);
  }

  if (lpCallback)
  {
    lpClass = AkelPad.MemAlloc(257 * 2);
    hWndIE  = oIE.HWND;

    oIE.AddressBar = false;
    oIE.MenuBar    = false;
    oIE.StatusBar  = false;
    oIE.ToolBar    = false;

    IENavigate("");

    oSys.Call("User32::EnumChildWindows", hWndIE, lpCallback, lpClass);
    oSys.UnregisterCallback(lpCallback);
    AkelPad.MemFree(lpClass);

    oSys.Call("User32::SetWindowLongW", hWndIE, -16 /*GWL_STYLE*/, 0x40000000 /*WS_CHILD*/);
    oSys.Call("User32::SetWindowPos", hWndIE, 0, 0, 0, 0, 0, 0x37 /*SWP_FRAMECHANGED|SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE*/);

    if (hWndIEServer && oSys.Call("User32::SetParent", oIE.HWND, aDlg.HWND)) //after SetParent oIE.HWND = aDlg.HWND
    {
      SendMessage(aDlg.HWND, 0x0128 /*WM_UPDATEUISTATE*/, MkLong(2 /*UIS_CLEAR*/, 0x7 /*UISF_ACTIVE|UISF_HIDEACCEL|UISF_HIDEFOCUS*/), 0);
      SendMessage(hWndIE,    0x0128 /*WM_UPDATEUISTATE*/, MkLong(2 /*UIS_CLEAR*/, 0x7 /*UISF_ACTIVE|UISF_HIDEACCEL|UISF_HIDEFOCUS*/), 0);
 
      oRect = {};
      GetWindowPos(aDlg.HWND, oRect, 1);
      ResizeDlg(oRect.W, oRect.H);
      return;
    }
  }

  IEQuit();
}

function EnumChildProc(hWnd, lParam)
{
  if (oSys.Call("User32::GetClassNameW", hWnd, lParam, 257) && (AkelPad.MemRead(lParam, 1 /*DT_UNICODE*/) == "Internet Explorer_Server"))
  {
    hWndIEServer = hWnd;
    return false;
  }

  return true;
}

function IEIsRunning()
{
  return oIE && (typeof oIE.Application == "object");
}

function IENavigate(sFile)
{
  var sUrl = sFile || "about:blank";

  oIE.Navigate(sUrl);
  while (oIE.Busy)
    WScript.Sleep(10);

  if (sFile)
  {
    oIE.Document.focus();
    try
    {
      //in IE11 attachEvent is replaced by addEventListener
      oIE.Document.attachEvent("onfocusin", IEDocument_onfocusin);
      oIE.Document.attachEvent("onkeydown", IEDocument_onkeydown);
    }
    catch (oError)
    {
      oIE.Document.addEventListener("onfocusin", IEDocument_onfocusin, true);
      oIE.Document.addEventListener("onkeydown", IEDocument_onkeydown, true);
    }
  }
}

function IEDocument_onfocusin(oEvent)
{
  aDlg.Focus = hWndIEServer;
}

function IEDocument_onkeydown(oEvent)
{
  switch (oEvent.keyCode)
  {
    case 0x09 /*VK_TAB*/:
    case 0x1B /*VK_ESC*/:
    case 0x55 /*U key*/:
    case 0x57 /*W key*/:
    case 0x73 /*VK_F4*/:
      oEvent.returnValue = false;
      SendMessage(aDlg.HWND, 256 /*WM_KEYDOWN*/, oEvent.keyCode, 0);
      break;
    case 0x0D /*VK_RETURN*/:
      if (oEvent.altKey)
      {
        oEvent.returnValue = false;
        SendMessage(aDlg.HWND, 260 /*WM_SYSKEYDOWN*/, oEvent.keyCode, 0);
      }
      break;
    case 0x21 /*VK_PRIOR*/:
    case 0x22 /*VK_NEXT*/:
    case 0x23 /*VK_END*/:
    case 0x24 /*VK_HOME*/:
    case 0x25 /*VK_LEFT*/:
    case 0x26 /*VK_UP*/:
    case 0x27 /*VK_RIGHT*/:
    case 0x28 /*VK_DOWN*/:
      if (oEvent.ctrlKey && !oEvent.shiftKey && oEvent.altKey)
      {
        oEvent.returnValue = false;
        SendMessage(aDlg.HWND, 256 /*WM_KEYDOWN*/, oEvent.keyCode, 0);
      }
      break;
    case 0x45 /*E key*/:
    case 0x52 /*R key*/:
      if (!oEvent.ctrlKey && !oEvent.shiftKey && oEvent.altKey)
      {
        oEvent.returnValue = false;
        aDlg.Focus = aDlg[IDNAME].HWND;
        PostMessage(aDlg.HWND, 273 /*WM_COMMAND*/, (oEvent.keyCode == 0x45 /*E key*/) ? IDLANG1 : IDLANG2, 0);
      }
      break;
    case 0x4D /*M key*/:
      if (!oEvent.ctrlKey && !oEvent.shiftKey && oEvent.altKey)
      {
        oEvent.returnValue = false;
        PostMessage(aDlg.HWND, 273 /*WM_COMMAND*/, IDMENU, 0);
      }
      break;
  }
}

function IEQuit()
{
  oIE.Quit();

  while (typeof oIE.Application == "object")
    WScript.Sleep(20);
}

function MenuMain()
{
  var MF_STRING    = 0x0000;
  var MF_CHECKED   = 0x0008;
  var MF_POPUP     = 0x0010;
  var MF_SEPARATOR = 0x0800;
  var hMenu1 = oSys.Call("User32::CreatePopupMenu");
  var hMenu  = oSys.Call("User32::CreatePopupMenu");
  var oRect  = {};
  var nCmd;
  var nCmd1;

  oSys.Call("User32::AppendMenuW", hMenu1, MF_STRING, 0x0001, sTxtFind + "\tCtrl+F");
  oSys.Call("User32::AppendMenuW", hMenu1, MF_STRING, 0x0101, sTxtFindNextDn + "\tF3");
  oSys.Call("User32::AppendMenuW", hMenu1, MF_STRING, 0x0201, sTxtFindNextUp + "\tShift+F3");

  oSys.Call("User32::AppendMenuW", hMenu, MF_POPUP,  hMenu1, sTxtFindInTxt);
  oSys.Call("user32::AppendMenuW", hMenu, MF_SEPARATOR, 0);
  oSys.Call("User32::AppendMenuW", hMenu, (bWordWrap ? MF_CHECKED : MF_STRING), 0x0002, sTxtWrapLines + "\tCtrl+U");
  oSys.Call("User32::AppendMenuW", hMenu, (bSeparateWnd ? MF_CHECKED : MF_STRING), 0x0003, sTxtSeparateWnd);

  GetWindowPos(aDlg[IDMENU].HWND, oRect);

  nCmd = oSys.Call("User32::TrackPopupMenu", hMenu, 0x01A0 /*TPM_NONOTIFY|TPM_RETURNCMD|TPM_BOTTOMALIGN*/, oRect.X, oRect.Y, 0, aDlg.HWND, 0);

  oSys.Call("User32::DestroyMenu", hMenu1);
  oSys.Call("User32::DestroyMenu", hMenu);

  nCmd1 = (nCmd >> 8) & 0xFF;
  nCmd  = nCmd & 0xFF;

  if (nCmd == 1)
  {
    if (nCmd1 == 0)
      FTDialog();
    else
      FindTextNext(nCmd1);
  }
  else if (nCmd == 2)
  {
    bWordWrap = ! bWordWrap;
    SetWordWrapAE();
  }
  else if (nCmd == 3)
  {
    bSeparateWnd = ! bSeparateWnd;
    bCloseDlg    = false;
    PostMessage(aDlg.HWND, 16 /*WM_CLOSE*/, 0, 0);
  }
}

function MenuName(nX, nY)
{
  var lpRect;
  var nX1, nY1, nY2;
  var hMenu;
  var nCmd;

  if ((nAPDSel < 0) || (aAPD[nAPDSel][0].charAt(0) == "*"))
    return;

  //menu from keyboard
  if (nX == 0xFFFF)
    SendMessage(aDlg[IDNAME].HWND, 0x1013 /*LVM_ENSUREVISIBLE*/, nAPDSel, false);

  lpRect = AkelPad.MemAlloc(16 /*sizeof(RECT)*/);
  SendMessage(aDlg[IDNAME].HWND, 0x100E /*LVM_GETITEMRECT*/, nAPDSel, lpRect);
  oSys.Call("User32::ClientToScreen", aDlg[IDNAME].HWND, lpRect);
  oSys.Call("User32::ClientToScreen", aDlg[IDNAME].HWND, lpRect + 8);
  nX1 = AkelPad.MemRead(lpRect,      3 /*DT_DWORD*/);
  nY1 = AkelPad.MemRead(lpRect +  4, 3 /*DT_DWORD*/);
  nY2 = AkelPad.MemRead(lpRect + 12, 3 /*DT_DWORD*/);
  AkelPad.MemFree(lpRect);

  if (nX == 0xFFFF)
  {
    nX = nX1;
    nY = nY2;
  }
  else if ((nY < nY1) || (nY > nY2))
    return;

  hMenu = oSys.Call("User32::CreatePopupMenu");
  oSys.Call("User32::AppendMenuW", hMenu, 0 /*MF_STRING*/, 1, sTxtOpenClose + "\tShift+Enter");
  oSys.Call("User32::AppendMenuW", hMenu, 0x01 /*MF_GRAYED*/, 0, sTxtFileName);
  oSys.Call("User32::AppendMenuW", hMenu, 0 /*MF_STRING*/, 2, "   " + sTxtCopyToCB + "\tCtrl+C");
  oSys.Call("User32::AppendMenuW", hMenu, AkelPad.GetEditWnd() && (! AkelPad.GetEditReadOnly(0)) ? 0 /*MF_STRING*/ : 0x01 /*MF_GRAYED*/, 3, "   " + sTxtInsertToAP + "\tCtrl+Shift+C");
  oSys.Call("User32::AppendMenuW", hMenu, 0x01 /*MF_GRAYED*/, 0, sTxtFileNamePath);
  oSys.Call("User32::AppendMenuW", hMenu, 0 /*MF_STRING*/, 4, "   " + sTxtCopyToCB + "\tAlt+C");
  oSys.Call("User32::AppendMenuW", hMenu, AkelPad.GetEditWnd() && (! AkelPad.GetEditReadOnly(0)) ? 0 /*MF_STRING*/ : 0x01 /*MF_GRAYED*/, 5, "   " + sTxtInsertToAP + "\tShift+Alt+C");

  nCmd = oSys.Call("User32::TrackPopupMenu", hMenu, 0x0180 /*TPM_NONOTIFY|TPM_RETURNCMD*/, nX, nY, 0, aDlg.HWND, 0);

  oSys.Call("User32::DestroyMenu", hMenu);

  if (nCmd == 1)
    OpenOrCloseFile();
  else if (nCmd == 2)
    InsertNameTo(true, false);
  else if (nCmd == 3)
    InsertNameTo(false, false);
  else if (nCmd == 4)
    InsertNameTo(true, true);
  else if (nCmd == 5)
    InsertNameTo(false, true);
}

function MenuText(nX, nY)
{
  var bSel  = SendMessage(aDlg[IDTEXT].HWND, 3125 /*AEM_GETSEL*/, 0, 0);
  var hMenu = oSys.Call("User32::CreatePopupMenu");
  var lpPoint;
  var nCmd;

  //menu from keyboard
  if (nX == 0xFFFF)
  {
    lpPoint = AkelPad.MemAlloc(8 /*sizeof(POINT)*/);
    oSys.Call("User32::GetCaretPos", lpPoint);
    oSys.Call("User32::ClientToScreen", aDlg[IDTEXT].HWND, lpPoint);
    nX = AkelPad.MemRead(lpPoint,     3 /*DT_DWORD*/);
    nY = AkelPad.MemRead(lpPoint + 4, 3 /*DT_DWORD*/) + SendMessage(aDlg[IDTEXT].HWND, 3188 /*AEM_GETCHARSIZE*/, 0 /*AECS_HEIGHT*/, 0);
    AkelPad.MemFree(lpPoint);
  }

  oSys.Call("User32::AppendMenuW", hMenu, bSel ? 0 /*MF_STRING*/ : 0x01 /*MF_GRAYED*/, 1, sTxtCopyToCB + "\tCtrl+C");
  oSys.Call("User32::AppendMenuW", hMenu, AkelPad.GetEditWnd() && (! AkelPad.GetEditReadOnly(0)) && bSel ? 0 /*MF_STRING*/ : 0x01 /*MF_GRAYED*/, 2, sTxtInsertToAP + "\tCtrl+Shift+C");
  oSys.Call("user32::AppendMenuW", hMenu, 0x0800 /*MF_SEPARATOR*/, 0);
  oSys.Call("User32::AppendMenuW", hMenu, 0 /*MF_STRING*/, 3, sTxtSelectAll + "\tCtrl+A");

  nCmd = oSys.Call("User32::TrackPopupMenu", hMenu, 0x0180 /*TPM_NONOTIFY|TPM_RETURNCMD*/, nX, nY, 0, aDlg.HWND, 0);

  oSys.Call("User32::DestroyMenu", hMenu);

  if (nCmd == 1)
    InsertTextTo(true);
  else if (nCmd == 2)
    InsertTextTo(false);
  else if (nCmd == 3)
    SetSelAE(0, -1);
}

function OpenOrCloseFile()
{
  if (bSeparateWnd)
  {
    oSys.Call("User32::SetForegroundWindow", hMainWnd);
    oSys.Call("User32::SetForegroundWindow", aDlg.HWND);
  }

  if (aAPD[nAPDSel][2].toUpperCase() == AkelPad.GetEditFile(0).toUpperCase())
  {
    if (AkelPad.IsMDI())
      AkelPad.Command(4318 /*IDM_WINDOW_FRAMECLOSE*/);
    else
      AkelPad.Command(4324 /*IDM_WINDOW_FILECLOSE*/);
  }
  else
  {
    if (oFSO.FileExists(aAPD[nAPDSel][2]))
      AkelPad.OpenFile(aAPD[nAPDSel][2]);
    else
      AkelPad.MessageBox(aDlg.HWND, aAPD[nAPDSel][2] + "\n\n" + sTxtNoFile, sTxtDlgTitle, 0x30 /*MB_ICONWARNING*/);
  }
}

function InsertNameTo(bClipboard, bFull)
{
  if (nAPDSel >= 0)
  {
    var sName = aAPD[nAPDSel][2];

    if (! bFull)
      sName = sName.replace(/.+\\/, "");

    if (bClipboard)
      AkelPad.SetClipboardText(sName);
    else if (AkelPad.GetEditWnd() && (! AkelPad.GetEditReadOnly(0)))
      AkelPad.ReplaceSel(sName, true);
  }
}

function InsertTextTo(bClipboard)
{
  var sText = GetSelTextAE();

  if (sText)
  {
    if (bClipboard)
      AkelPad.SetClipboardText(sText);
    else
      AkelPad.ReplaceSel(sText, true);
  }
}

function FTDialog()
{
  aDlgFT.Parent = aDlg[IDTEXT].HWND;
  aDlgFT.Icon   = oSys.Call("User32::LoadImageW", AkelPad.GetInstanceDll(), 101, 1 /*uType=IMAGE_ICON*/, 0, 0, 0x40 /*LR_DEFAULTSIZE*/);

  oSys.Call("User32::SetFocus", aDlg[IDTEXT].HWND);
  SendMessage(aDlg[IDTEXT].HWND, 3228 /*AEM_SETOPTIONS*/, 2 /*AECOOP_OR*/, 0x00000004 /*AECO_NOHIDESEL*/);

  CreateDialogBox(aDlgFT);

  SendMessage(aDlg[IDTEXT].HWND, 3228 /*AEM_SETOPTIONS*/, 4 /*AECOOP_XOR*/, 0x00000004 /*AECO_NOHIDESEL*/);
  oSys.Call("user32::DestroyIcon", aDlgFT.Icon);
}

function FTDlgCallback(hWnd, uMsg, wParam, lParam)
{
  if (uMsg == 272 /*WM_INITDIALOG*/)
  {
    SendMessage(aDlgFT[IDFTTEXT].HWND, 12 /*WM_SETTEXT*/, 0, GetSelTextAE() || sFindText);
    SendMessage(aDlgFT[IDFTCASE].HWND, 241 /*BM_SETCHECK*/, bCaseFT, 0);
    SendMessage(aDlgFT[IDFTALLDOC].HWND, 241 /*BM_SETCHECK*/, bAllDocFT, 0);
    SendMessage(aDlgFT[IDFTBEGIN + nDirectFT].HWND, 241 /*BM_SETCHECK*/, 1, 0);

    if (SendMessage(AkelPad.GetEditWnd(), 3227 /*AEM_GETOPTIONS*/, 0, 0) & 0x00000800 /*AECO_ACTIVELINE*/)
      PostMessage(aDlg[IDTEXT].HWND, 3228 /*AEM_SETOPTIONS*/, 2 /*AECOOP_OR*/, 0x00000800 /*AECO_ACTIVELINE*/);
  }

  else if (uMsg == 6 /*WM_ACTIVATE*/)
  {
    if (wParam)
    {
      oSys.Call("User32::RegisterHotKey", hWnd, 1, 0, 0x72 /*VK_F3*/);
      oSys.Call("User32::RegisterHotKey", hWnd, 2, 0x4 /*MOD_SHIFT*/, 0x72 /*VK_F3*/);
    }
    else
    {
      oSys.Call("User32::UnregisterHotKey", hWnd, 1);
      oSys.Call("User32::UnregisterHotKey", hWnd, 2);
    }
  }

  else if (uMsg == 786 /*WM_HOTKEY*/)
  {
    if (oSys.Call("User32::IsWindowEnabled", aDlgFT[IDFTFIND].HWND) && ((wParam == 1) || (wParam == 2)))
    {
      FindText(wParam);
      PostMessage(aDlgFT.HWND, 16 /*WM_CLOSE*/, 0, 0);
    }
  }

  else if (uMsg == 273 /*WM_COMMAND*/)
  {
    var nLowParam = LoWord(wParam);
    var nHiwParam = HiWord(wParam);

    if (nLowParam == IDFTTEXT)
    {
      if (nHiwParam == 0x0300 /*EN_CHANGE*/)
      {
        oSys.Call("User32::EnableWindow", aDlgFT[IDFTFIND].HWND, SendMessage(lParam, 14 /*WM_GETTEXTLENGTH*/, 0, 0));
        bNewFT = 1;
      }
    }
    else if (nLowParam == IDFTCASE)
    {
      bCaseFT = ! bCaseFT;
      bNewFT  = 1;
    }
    else if (nLowParam == IDFTALLDOC)
    {
      bAllDocFT = ! bAllDocFT;
      bNewFT    = 1;
    }
    else if ((nLowParam >= IDFTBEGIN) && (nLowParam <= IDFTEND))
    {
      nDirectFT = nLowParam - IDFTBEGIN;
      bNewFT    = 1;
    }
    else if (nLowParam == IDFTFIND)
      FindText(nDirectFT, 1);
    else if ((nLowParam == IDFTCANCEL) || (nLowParam == 2 /*IDCANCEL*/))
      PostMessage(hWnd, 16 /*WM_CLOSE*/, 0, 0);
  }

  else if (uMsg == 16 /*WM_CLOSE*/)
    oSys.Call("User32::EndDialog", hWnd, wParam);
}

function FindText(nDirection, bMessage)
{
  var nTextLen = SendMessage(aDlgFT[IDFTTEXT].HWND, 14 /*WM_GETTEXTLENGTH*/, 0, 0);
  var lpText   = AkelPad.MemAlloc((nTextLen + 1) * 2);

  SendMessage(aDlgFT[IDFTTEXT].HWND, 13 /*WM_GETTEXT*/, nTextLen + 1, lpText);
  sFindText = AkelPad.MemRead(lpText, 1 /*DT_UNICODE*/);
  AkelPad.MemFree(lpText);

  if (! bNewFT)
  {
    if (nDirection == 0)
      nDirection = 1;
    else if (nDirection == 3)
      nDirection = 2;
  }

  if (FindTextNext(nDirection))
    bNewFT = 0;
  else
  {
    bNewFT = 1;
    if (bMessage)
      AkelPad.MessageBox(aDlgFT.HWND, sTxtNotFound, aDlgFT.Title, 0x30 /*MB_ICONWARNING*/);
  }
}

function FindTextNext(nDirection)
{
  var bFound = false;
  var nNameStart;
  var nNameEnd;
  var nTextStart;
  var nSel;
  var i;

  oSys.Call("User32::SetFocus", aDlg[IDTEXT].HWND);

  if (nDirection < 2)
  {
    nNameStart = (nDirection == 0) && bAllDocFT ? 0 : nAPDSel;
    nNameEnd   = bAllDocFT ? aAPD.length - 1 : nAPDSel;
    nTextStart = (nDirection == 0) ? 0 : GetSelEndAE();

    for (i = nNameStart; i <= nNameEnd; ++i)
    {
      if (bCaseFT)
        nSel = aAPD[i][1].indexOf(sFindText, (i == nNameStart) ? nTextStart : 0);
      else
        nSel = aAPD[i][1].toUpperCase().indexOf(sFindText.toUpperCase(), (i == nNameStart) ? nTextStart : 0);

      if (nSel > -1)
      {
        SetCurSelLV(i);
        SetSelAE(nSel, nSel + sFindText.length);
        bFound = true;
        break;
      }
    }
  }
  else
  {
    nNameEnd = bAllDocFT ? 0 : nAPDSel;

    if (nDirection == 2)
    {
      nNameStart = nAPDSel;
      nTextStart = GetSelStartAE() - sFindText.length;

      if ((nTextStart < 0) && (--nNameStart >= 0))
        nTextStart = aAPD[nNameStart][1].length;
    }
    else
    {
      nNameStart = bAllDocFT ? aAPD.length - 1 : nAPDSel;
      nTextStart = aAPD[nNameStart][1].length;
    }

    for (i = nNameStart; i >= nNameEnd; --i)
    {
      if (bCaseFT)
        nSel = aAPD[i][1].lastIndexOf(sFindText, (i == nNameStart) ? nTextStart : aAPD[i][1].length);
      else
        nSel = aAPD[i][1].toUpperCase().lastIndexOf(sFindText.toUpperCase(), (i == nNameStart) ? nTextStart : aAPD[i][1].length);

      if (nSel > -1)
      {
        SetCurSelLV(i);
        SetSelAE(nSel, nSel + sFindText.length);
        bFound = true;
        break;
      }
    }
  }

  return bFound;
}

function IsScriptRunning()
{
  var hDlg = oSys.Call("User32::FindWindowExW", 0, 0, sClass, 0);

  if (hDlg)
  {
    if (! oSys.Call("User32::IsWindowVisible", hDlg))
      oSys.Call("User32::ShowWindow", hDlg, 8 /*SW_SHOWNA*/);
    if (oSys.Call("User32::IsIconic", hDlg))
      oSys.Call("User32::ShowWindow", hDlg, 9 /*SW_RESTORE*/);

    oSys.Call("User32::SetForegroundWindow", hDlg);
    return true;
  }

  return false;
}

function ReadIni()
{
  try
  {
    eval(AkelPad.ReadFile(WScript.ScriptFullName.replace(/\.js$/i, ".ini"), 0x10 /*OD_ADT_NOMESSAGES*/, 1200 /*UTF-16LE*/, true));
  }
  catch (oError)
  {}

  aDlg.W = Math.max(aDlg.W, aDlg.MinW);
  aDlg.H = Math.max(aDlg.H, aDlg.MinH);
}

function WriteIni()
{
  var oRW = {};
  var oRC = {};
  var sIniTxt;
  var i;

  GetWindowPos(aDlg.HWND, oRW);
  GetWindowPos(aDlg.HWND, oRC, 1);

  sIniTxt =
    'aDlg.X='       + Scale.UX(aDlg.X) + ';\r\n' +
    'aDlg.Y='       + Scale.UY(aDlg.Y) + ';\r\n' +
    'aDlg.W='       + (Scale.UX(aDlg.W - (oRW.W - oRC.W)) + (oRW.W - oRC.W)) + ';\r\n' +
    'aDlg.H='       + (Scale.UY(aDlg.H - (oRW.H - oRC.H)) + (oRW.H - oRC.H)) + ';\r\n' +
    'aDlg.Maxim='   + oSys.Call("User32::IsZoomed", aDlg.HWND) + ';\r\n' +
    'sAltDir="'     + EscapeStr(sAltDir) + '";\r\n' +
    'sFindText="'   + EscapeStr(sFindText) + '";\r\n' +
    'bCaseFT='      + bCaseFT + ';\r\n' +
    'bAllDocFT='    + bAllDocFT + ';\r\n' +
    'nDirectFT='    + nDirectFT + ';\r\n' +
    'bWordWrap='    + bWordWrap + ';\r\n' +
    'bSeparateWnd=' + bSeparateWnd + ';\r\n' +
    'nLang='        + nLang + ';\r\n' +
    'nAPDSel='      + nAPDSel + ';\r\n' +
    'aAESel[0]={';

  for (i in aAESel[0])
    sIniTxt += '"' + i + '":[' + aAESel[0][i] + '],';

  if (sIniTxt.slice(-1) == ',')
    sIniTxt = sIniTxt.slice(0, -1);

  sIniTxt += '};\r\naAESel[1]={';

  for (i in aAESel[1])
    sIniTxt += '"' + i + '":[' + aAESel[1][i] + '],';

  if (sIniTxt.slice(-1) == ',')
    sIniTxt = sIniTxt.slice(0, -1);

  sIniTxt += '};';
   
  AkelPad.WriteFile(WScript.ScriptFullName.replace(/\.js$/i, ".ini"), sIniTxt, sIniTxt.length, 1200 /*UTF-16LE*/, true);
}

function EscapeStr(sText)
{
  return sText.replace(/[\\"]/g, '\\$&').replace(/\n/g, '\\n').replace(/\r/g, '\\r');
}

function GetLangStrings()
{
//  if (AkelPad.GetLangId(0 /*LANGID_FULL*/) == 1049 /*Russian*/)
//  {
//  }
//  else
  {
    sTxtDlgTitle     = "AkelPad documents view";
    sTxtDocument     = "Document";
    sTxtEnglish      = "&English";
    sTxtRussian      = "&Russian";
    sTxtMenu         = "&Menu";
    sTxtClose        = "Close";
    sTxtFindInTxt    = "Find in *.txt documents";
    sTxtWrapLines    = "Wrap text lines";
    sTxtSeparateWnd  = "Run in separate window";
    sTxtOpenClose    = "Open/close file in AkelPad";
    sTxtFileName     = "File name:";
    sTxtFileNamePath = "Full  file name with path:";
    sTxtCopyToCB     = "Copy to clipboard";
    sTxtInsertToAP   = "Insert to AkelPad";
    sTxtSelectAll    = "Select all";
    sTxtWhat         = "&What:";
    sTxtMatchCase    = "&Match case";
    sTxtAllDocs      = "&All documents";
    sTxtDirection    = "Direction";
    sTxtBeginning    = "&Beginning";
    sTxtDown         = "&Down";
    sTxtUp           = "&up";
    sTxtEnd          = "&End";
    sTxtFindNext     = "&Find next";
    sTxtCancel       = "Cancel";
    sTxtFind         = "Find...";
    sTxtFindNextDn   = "Find next down";
    sTxtFindNextUp   = "Find next up";
    sTxtNotFound     = "Not found.";
    sTxtNoFilesInDir = "Files not found in directory:";
    sTxtChooseDir    = "Choose directory with AkelPad documentation:";
    sTxtNoFile       = "File does not exists.";
    sTxtNoIE         = "Internet Explorer is not available.";
    sTxtNoCallback   = "Unable to register callback function.";
    sTxtErrMessage   = "Error message: ";
    sTxtErrNumber    = "Error number: ";
  }
}


Last edited by KDJ on Thu Sep 18, 2014 8:10 pm; edited 5 times in total
Back to top
View user's profile Send private message
KDJ



Joined: 06 Mar 2010
Posts: 1373
Location: Poland

PostPosted: Thu Feb 06, 2014 8:23 pm    Post subject: Reply with quote

Select tab by pressing Ctrl/Shift/Alt+Number (MDI/PMDI).

TabNumberByKeyboard.js

Code:
/*
TabNumberByKeyboard.js - ver. 2014-02-06 (x86/x64)

Select tab by pressing Ctrl/Shift/Alt+Number (MDI/PMDI)

Usage:
  Call("Scripts::Main", 1, "TabNumberByKeyboard.js")
  Call("Scripts::Main", 1, "TabNumberByKeyboard.js", "Argument")

Argument:
  "A" - Alt (default)
  "C" - Ctrl
  "S" - Shift (only in combination with Ctrl and/or Alt)
  can be: "C", "A", "CS", "CA", "CSA", "SA"

Notes:
  After first call, the script resides in the memory.
  Second script call, closes the script.

For autostart, in AkelPad.ini or registry CmdLineBegin key, need to add eg:
  /Call("Scripts::Main", 1, "TabNumberByKeyboard.js", "SC")
*/

var hScript = AkelPad.ScriptHandle(WScript.ScriptName, 3 /*SH_FINDSCRIPT*/);

if (hScript && AkelPad.ScriptHandle(hScript, 13 /*SH_GETMESSAGELOOP*/))
{
  //script already is running, close it
  AkelPad.ScriptHandle(hScript, 33 /*SH_CLOSESCRIPT*/);
}
else if (AkelPad.IsMDI())
{
  var oSys     = AkelPad.SystemFunction();
  var hMainWnd = AkelPad.GetMainWnd();
  var bCtrl    = false;
  var bShift   = false;
  var bAlt     = false;
  var sArg;
  var hSubClass;
  var lpFrame;
  var nTab;

  if (WScript.Arguments.length)
  {
    sArg = WScript.Arguments(0).toUpperCase();

    if (sArg.indexOf("C") >= 0)
      bCtrl = true;
    if (sArg.indexOf("S") >= 0)
      bShift = true;
    if (sArg.indexOf("A") >= 0)
      bAlt = true;

    if (bShift && (! bCtrl) && (! bAlt))
    {
      bShift = false;
      bAlt   = true;
    }
  }
  else
    bAlt = true;

  hSubClass = AkelPad.WindowSubClass(2 /*WSC_EDITPROC*/, EditCallback, bCtrl ? 256 /*WM_KEYDOWN*/ : 260 /*WM_SYSKEYDOWN*/);

  if (hSubClass)
  {
    //Allow other scripts running
    AkelPad.ScriptNoMutex();

    //Message loop
    AkelPad.WindowGetMessage();

    AkelPad.WindowUnsubClass(2 /*WSC_EDITPROC*/);
  }
}

function EditCallback(hWnd, uMsg, wParam, lParam)
{
  if ((uMsg == 256 /*WM_KEYDOWN*/) && (wParam >= 0x30 /*0 key*/) && (wParam <= 0x39 /*9 key*/) && Ctrl())
  {
    if ((bShift == Shift()) && (bAlt == Alt()))
      FrameActivate(wParam);
  }
  else if ((uMsg == 260 /*WM_SYSKEYDOWN*/) && (wParam >= 0x30 /*0 key*/) && (wParam <= 0x39 /*9 key*/))
  {
    if (bShift == Shift())
      FrameActivate(wParam);
  }

  return 0;
}

function FrameActivate(nKey)
{
  nTab = ((nKey == 0x30) ? 10 : nKey - 0x30) - 1;

  if (lpFrame = AkelPad.SendMessage(hMainWnd, 1290 /*AKD_FRAMEFINDW*/, 8 /*FWF_BYTABINDEX*/, nTab))
    AkelPad.SendMessage(hMainWnd, 1285 /*AKD_FRAMEACTIVATE*/, 0, lpFrame);
}

function Ctrl()
{
  return Boolean(oSys.Call("User32::GetKeyState", 0x11 /*VK_CONTROL*/) & 0x8000);
}

function Shift()
{
  return Boolean(oSys.Call("User32::GetKeyState", 0x10 /*VK_SHIFT*/) & 0x8000);
}

function Alt()
{
  return Boolean(oSys.Call("user32::GetKeyState", 0x12 /*VK_MENU*/) & 0x8000);
}
Back to top
View user's profile Send private message
Infocatcher



Joined: 06 Aug 2007
Posts: 1619

PostPosted: Sat Mar 01, 2014 6:54 pm    Post subject: Reply with quote

closeLeftOrRightTabs.js
Code:
// http://akelpad.sourceforge.net/forum/viewtopic.php?p=24138#24138
// http://infocatcher.ucoz.net/js/akelpad_scripts/closeLeftOrRightTabs.js
// https://github.com/Infocatcher/AkelPad_scripts/blob/master/closeLeftOrRightTabs.js

// (c) Infocatcher 2014
// version 0.1.1 - 2014-03-03

//===================
// Close tabs to the left or right (temporary check "Switch tabs: right-left" option)
// Based on Instructor's code: http://akelpad.sourceforge.net/forum/viewtopic.php?p=4222#4222

// Usage:
//   Call("Scripts::Main", 1, "closeLeftOrRightTabs.js")           - close tabs to the right
//   Call("Scripts::Main", 1, "closeLeftOrRightTabs.js", "-left")  - close tabs to the left
//===================

var toRight = WScript.Arguments.length ? WScript.Arguments(0) != "-left" : true;

var hMainWnd = AkelPad.GetMainWnd();
if(hMainWnd && AkelPad.IsMDI()) {
   var tabOpts = AkelPad.SendMessage(hMainWnd, 1222 /*AKD_GETMAININFO*/, 157 /*MI_TABOPTIONSMDI*/, 0);
   var forceRightLeft = !(tabOpts & 0x20000 /*TAB_SWITCH_RIGHTLEFT*/);
   if(forceRightLeft)
      AkelPad.Command(4311 /*IDM_WINDOW_TABSWITCH_RIGHTLEFT*/);

   closeTabs(toRight);

   if(forceRightLeft)
      AkelPad.SendMessage(hMainWnd, 1219 /*AKD_SETMAININFO*/, 157 /*MIS_TABOPTIONSMDI*/, tabOpts);
}
else {
   AkelPad.MessageBox(hMainWnd, "MDI or PMDI window mode required!", WScript.ScriptName, 48 /*MB_ICONEXCLAMATION*/);
}

function closeTabs(toRight) {
   var nextFrameCmd = toRight ? 4316 /*IDM_WINDOW_FRAMENEXT*/ : 4317 /*IDM_WINDOW_FRAMEPREV*/;
   var lpFrameInitial = AkelPad.SendMessage(hMainWnd, 1288 /*AKD_FRAMEFIND*/, 1 /*FWF_CURRENT*/, 0);
   var frameIndexInitial = AkelPad.SendMessage(hMainWnd, 1294 /*AKD_FRAMEINDEX*/, 0, lpFrameInitial);
   for(;;) {
      var restoreSelected = true;
      AkelPad.SendMessage(hMainWnd, 273 /*WM_COMMAND*/, nextFrameCmd, 0);
      var lpFrame = AkelPad.SendMessage(hMainWnd, 1288 /*AKD_FRAMEFIND*/, 1 /*FWF_CURRENT*/, 0);
      //if(lpFrame == lpFrameInitial)
      //   break;
      var frameIndex = AkelPad.SendMessage(hMainWnd, 1294 /*AKD_FRAMEINDEX*/, 0, lpFrame);
      if(toRight ? frameIndex <= frameIndexInitial : frameIndex >= frameIndexInitial--)
         break; // Overflow
      if(!AkelPad.SendMessage(hMainWnd, 273 /*WM_COMMAND*/, 4318 /*IDM_WINDOW_FRAMECLOSE*/, 0))
         return; // Cancel
      restoreSelected = false;
      AkelPad.SendMessage(hMainWnd, 1285 /*AKD_FRAMEACTIVATE*/, 0, lpFrameInitial);
   }
   restoreSelected && AkelPad.SendMessage(hMainWnd, 1285 /*AKD_FRAMEACTIVATE*/, 0, lpFrameInitial);
}
<download | mirror | development version>
Close tabs to the left or right (temporary check "Switch tabs: right-left" option).
Required MDI or PMDI window mode!
Back to top
View user's profile Send private message Visit poster's website
Infocatcher



Joined: 06 Aug 2007
Posts: 1619

PostPosted: Wed Apr 02, 2014 10:13 pm    Post subject: Reply with quote

fullWindow.js
Code:
// http://akelpad.sourceforge.net/forum/viewtopic.php?p=24434#24434
// http://infocatcher.ucoz.net/js/akelpad_scripts/fullWindow.js
// https://github.com/Infocatcher/AkelPad_scripts/blob/master/fullWindow.js

// (c) Infocatcher 2014
// version 0.1.0 - 2014-04-03

// Just like full screen mode, but preserve window size and position
// Required FullScreen plugin!

var hMainWnd = AkelPad.GetMainWnd();
var oSys = AkelPad.SystemFunction();

if(hMainWnd) {
   var lpRect = AkelPad.MemAlloc(16); //sizeof(RECT)
   if(lpRect) {
      oSys.Call("user32::GetWindowRect", hMainWnd, lpRect);
      var x = AkelPad.MemRead(lpRect,      3 /*DT_DWORD*/);
      var y = AkelPad.MemRead(lpRect +  4, 3 /*DT_DWORD*/);
      var w = AkelPad.MemRead(lpRect +  8, 3 /*DT_DWORD*/) - x;
      var h = AkelPad.MemRead(lpRect + 12, 3 /*DT_DWORD*/) - y;
      AkelPad.MemFree(lpRect);

      AkelPad.Call("FullScreen::Main");
      oSys.Call("user32::SetWindowPos", hMainWnd, 0, x, y, w, h, 0x14 /*SWP_NOZORDER|SWP_NOACTIVATE*/);
   }
}
<download | mirror | development version>
Just like full screen mode, but preserve window size and position.
Required FullScreen plugin!
Back to top
View user's profile Send private message Visit poster's website
Infocatcher



Joined: 06 Aug 2007
Posts: 1619

PostPosted: Sat Apr 12, 2014 7:50 pm    Post subject: Reply with quote

timer.js
Code:
// http://akelpad.sourceforge.net/forum/viewtopic.php?p=24559#24559
// http://infocatcher.ucoz.net/js/akelpad_scripts/Include/timer.js
// https://github.com/Infocatcher/AkelPad_scripts/blob/master/Include/timer.js

// (c) Infocatcher 2014
// version 0.1.1 - 2014-04-22

// Helper functions for user32::SetTimer()
// Usage example:
/*
var hMainWnd = AkelPad.GetMainWnd();
if(AkelPad.Include("timer.js")) {
   _log("Started");
   setTimeout(function() {
      _log("Finished");
      oSys.Call("user32::PostQuitMessage", 0);
   }, 2000);
   AkelPad.ScriptNoMutex();
   AkelPad.WindowGetMessage();
}
function _log(s) {
   oSys.Call("user32::SetWindowText" + _TCHAR, hMainWnd, WScript.ScriptName + ": " + s);
}
*/

// Be careful: 3rd argument is an ID of already created timer!
function setTimeout(fn, delay, id) {
   return timers.set(fn, delay, true, id);
}
function setInterval(fn, delay, id) {
   return timers.set(fn, delay, false, id);
}
function clearTimeout(id) {
   timers.clear(id);
}
function clearInterval(id) {
   timers.clear(id);
}

if(!hMainWnd)
   var hMainWnd = AkelPad.GetMainWnd();
if(!oSys)
   var oSys = AkelPad.SystemFunction();

var timers = {
   _id: 1000,
   getId: function() {
      return AkelPad.SendMessage(hMainWnd, 1319 /*AKD_UNIQUEID*/, 0, 0) // AkelPad 4.8.8+
         || ++this._id;
   },
   funcs: {}, // IDs of all timers
   timeouts: {}, // IDs of single-time timers
   lpTimerCallback: 0,
   init: function() {
      if(!this.lpTimerCallback) try { // AkelPad 4.8.8+
         this.lpTimerCallback = oSys.RegisterCallback(timerProc);
      }
      catch(e) {
         this.lpTimerCallback = oSys.RegisterCallback("", timerProc, timerProc.length);
      }
      this.hWndTimer = AkelPad.ScriptHandle(0, 17 /*SH_GETSERVICEWINDOW*/) || hMainWnd;
      return this.lpTimerCallback;
   },
   destroy: function() {
      if(!this.lpTimerCallback)
         return;
      for(var id in this.funcs)
         this._clear(id);
      oSys.UnregisterCallback(this.lpTimerCallback);
      this.lpTimerCallback = 0;
      this._log("destroy");
   },
   has: function() {
      for(var id in this.funcs)
         return true;
      return false;
   },
   set: function(fn, delay, isSingle, id) {
      if(!this.init()) {
         AkelPad.MessageBox(hMainWnd, "oSys.RegisterCallback() failed!", WScript.ScriptName, 16 /*MB_ICONERROR*/);
         return 0;
      }
      if(!id)
         id = this.getId();
      this.funcs[id] = fn;
      if(isSingle)
         this.timeouts[id] = true;
      this._log("set(" + isSingle + ") " + id);
      oSys.Call("user32::SetTimer", this.hWndTimer, id, delay, this.lpTimerCallback);
      return id;
   },
   clear: function(id, isSingle) {
      this._clear(id);
      if(!this.has())
         this.destroy();
   },
   _clear: function(id) {
      this._log("_clear(" + id + ")");
      oSys.Call("user32::KillTimer", this.hWndTimer, id);
      delete this.funcs[id];
      delete this.timeouts[id];
   },
   _prev: [],
   _log: function(s) {
      return; // disable logs
      var prev = this._prev;
      var last = prev[prev.length - 1];
      RegExp.$1 = 0;
      if(last && s == last.replace(/ #(\d+)$/, ""))
         prev[prev.length - 1] = s + " #" + ((+RegExp.$1 || 1) + 1);
      else {
         while(prev.length > 8)
            prev.shift();
         prev.push(s);
      }
      s = prev.join(" -> ");
      oSys.Call("user32::SetWindowText" + _TCHAR, hMainWnd, WScript.ScriptName + ": " + s);
   }
};

function timerProc(hWnd, uMsg, nIDEvent, dwTime) {
   var fn = timers.funcs[nIDEvent];
   if(timers.timeouts[nIDEvent])
      timers.clear(nIDEvent);
   fn();
}
<download | mirror | development version>
Helper functions for user32::SetTimer(), for AkelPad.Include().


Last edited by Infocatcher on Tue Apr 22, 2014 9:14 am; edited 2 times in total
Back to top
View user's profile Send private message Visit poster's website
Infocatcher



Joined: 06 Aug 2007
Posts: 1619

PostPosted: Sat Apr 12, 2014 8:29 pm    Post subject: Reply with quote

autoSaveSession.js
Code:
// http://akelpad.sourceforge.net/forum/viewtopic.php?p=24561#24561
// http://infocatcher.ucoz.net/js/akelpad_scripts/autoSaveSession.js
// https://github.com/Infocatcher/AkelPad_scripts/blob/master/autoSaveSession.js

// (c) Infocatcher 2012-2014
// version 0.2.1 - 2014-04-22

// Automatically saves current session after selection or scroll changes
// Required Sessions plugin!

// Arguments:
//   -startupDelay=1500    - (in ms) ignore all changes just after startup
//   -minDelay=8000        - (in ms) minimum interval between two saves
//   -smallDelay=500       - (in ms) minimum daley between change and save
//   -session="OnExit"     - name of session file
//   -debug=true           - show debug messages in window title

// Usage:
//   CmdLineBegin=/Call("Scripts::Main", 1, "autoSaveSession.js")
//   CmdLineBegin=/Call("Scripts::Main", 1, "autoSaveSession.js", '-startupDelay=2000 -minDelay=12000 -session="OnExit"')
// (see AkelHelp*.htm for manual settings)

var isMDI = AkelPad.IsMDI();
if(!isMDI) // We silently ignore SDI mode to allow use the same settings in any mode!
   WScript.Quit();

var startupDelay = AkelPad.GetArgValue("startupDelay", 1500);
var stopWait = new Date().getTime() + startupDelay;

var hMainWnd = AkelPad.GetMainWnd();
var oSys = AkelPad.SystemFunction();
var minDelay = AkelPad.GetArgValue("minDelay", 8e3);
var smallDelay = AkelPad.GetArgValue("smallDelay", 500);
var sessionName = AkelPad.GetArgValue("session", "OnExit");
var debug = AkelPad.GetArgValue("debug", false);

var timer = 0;
var lastSave = 0;

var lpTimerCallback = 0;
var nIDEvent;
var hWndTimer;
var error = "";

debug && _log("start");

var hScript = AkelPad.ScriptHandle(WScript.ScriptName, 3 /*SH_FINDSCRIPT*/);
if(hScript && AkelPad.ScriptHandle(hScript, 13 /*SH_GETMESSAGELOOP*/)) {
   // Script is running, second call close it
   debug && _log("quit");
   AkelPad.ScriptHandle(hScript, 33 /*SH_CLOSESCRIPT*/);
   WScript.Quit();
}

if(hMainWnd) {
   if(
      AkelPad.WindowSubClass(
         1 /*WSC_MAINPROC*/,
         mainCallback,
         0x4E /*WM_NOTIFY*/,
         0x416 /*AKDN_FRAME_ACTIVATE*/,
         0x418 /*AKDN_FRAME_DESTROY*/
         //0x436 /*AKDN_OPENDOCUMENT_FINISH*/
         //0x406 /*AKDN_MAIN_ONFINISH*/
      )
   ) {
      if(
         isMDI != 1 /*WMD_MDI*/
         || AkelPad.WindowSubClass(
            3 /*WSC_FRAMEPROC*/,
            mainCallback,
            0x4E /*WM_NOTIFY*/
         )
      ) {
         AkelPad.ScriptNoMutex(); // Allow other scripts running
         AkelPad.WindowGetMessage(); // Message loop

         AkelPad.WindowUnsubClass(1 /*WSC_MAINPROC*/);
         AkelPad.WindowUnsubClass(3 /*WSC_FRAMEPROC*/);
         destroyTimer();
         error && AkelPad.MessageBox(hMainWnd, error, WScript.ScriptName, 16 /*MB_ICONERROR*/);
      }
      else {
         AkelPad.WindowUnsubClass(1 /*WSC_MAINPROC*/);
         AkelPad.MessageBox(hMainWnd, "AkelPad.WindowSubClass(WSC_FRAMEPROC) failed!", WScript.ScriptName, 16 /*MB_ICONERROR*/);
      }
   }
   else {
      AkelPad.MessageBox(hMainWnd, "AkelPad.WindowSubClass(WSC_MAINPROC) failed!", WScript.ScriptName, 16 /*MB_ICONERROR*/);
   }
}

function mainCallback(hWnd, uMsg, wParam, lParam) {
   //if(uMsg == 0x406 /*AKDN_MAIN_ONFINISH*/) {
   //   oSys.Call("user32::PostQuitMessage", 0); // Exit message loop
   //   return;
   //}

   if(timer) // Already scheduled
      return;

   if(uMsg == 0x4E /*WM_NOTIFY*/) {
      var cmd = AkelPad.MemRead(lParam + 8, 3 /*DT_DWORD*/);
      switch(cmd) {
         case 0x804 /*AEN_HSCROLL*/:
         case 0x805 /*AEN_VSCROLL*/:
         case 0x81E /*AEN_SELCHANGED*/:
            uMsg = cmd;
         break;
         default: return;
      }
   }

   if(stopWait) {
      if(new Date().getTime() < stopWait)
         return;
      stopWait = 0;
   }
   if(!AkelPad.GetEditFile(0))
      return;

   var delay = new Date().getTime() - lastSave > minDelay ? smallDelay : minDelay;
   timer = saveSessionDelayed(delay);
}
function saveSession() {
   if(!oSys.Call("user32::IsWindowEnabled", hMainWnd)) {
      timer = saveSessionDelayed(minDelay);
      return;
   }
   timer = 0;
   lastSave = new Date().getTime();
   AkelPad.Call("Sessions::Main", 2, sessionName);
   debug && _log("saved at " + new Date().toLocaleString());
}
function saveSessionDelayed(delay) {
   try { // AkelPad 4.8.8+
      lpTimerCallback = oSys.RegisterCallback(saveSessionTimerProc);
   }
   catch(e) {
      lpTimerCallback = oSys.RegisterCallback("saveSessionTimerProc");
   }
   if(!lpTimerCallback) {
      error = "oSys.RegisterCallback() failed!\nScript was terminated.";
      oSys.Call("user32::PostQuitMessage", 0); // Exit message loop
      return 0;
   }
   nIDEvent = AkelPad.SendMessage(hMainWnd, 1319 /*AKD_UNIQUEID*/, 0, 0) || 10;
   hWndTimer = AkelPad.ScriptHandle(0, 17 /*SH_GETSERVICEWINDOW*/) || hMainWnd;
   saveSessionDelayed = function(delay) {
      return oSys.Call("user32::SetTimer", hWndTimer, nIDEvent, delay, lpTimerCallback);
   };
   return saveSessionDelayed(delay);
}
function saveSessionTimerProc(hWnd, uMsg, nIDEvent, dwTime) {
   oSys.Call("user32::KillTimer", hWndTimer, nIDEvent);
   saveSession();
}
function destroyTimer() {
   if(lpTimerCallback) {
      oSys.Call("user32::KillTimer", hWndTimer, nIDEvent);
      oSys.UnregisterCallback(lpTimerCallback);
      lpTimerCallback = 0;
   }
}
function _log(s) {
   oSys.Call("user32::SetWindowText" + _TCHAR, hMainWnd, WScript.ScriptName + ": " + s);
}
<download | mirror | development version>
Automatically saves current session after selection or scroll changes
Required Sessions plugin!
Beware: may cause bugs and crashes, use at your own risk!
Back to top
View user's profile Send private message Visit poster's website
KDJ



Joined: 06 Mar 2010
Posts: 1373
Location: Poland

PostPosted: Sun May 04, 2014 7:18 pm    Post subject: Reply with quote

Functions for creating dialog boxes.
This script should be saved in directory: ...\AkelPad\AkelFiles\Plugs\Scripts\Include\

CreateDialog_functions.js

Code:
/*
CreateDialog_functions.js - ver. 2014-05-26 (x86/x64)

Contains:
CreateDialogWindow() function
CreateDialogBox() function
Scale object

--------------------
CreateDialogWindow()
--------------------
Create dialog box by using WinAPI function CreateWindowEx
http://msdn.microsoft.com/en-us/library/windows/desktop/ms632680%28v=vs.85%29.aspx

Usage:
  if (! AkelPad.Include("CreateDialog_functions.js")) WScript.Quit();
  nWindows = CreateDialogWindow(aDlg[, nWhat[, hDlg[, nStartID[, nEndID]]]]);

Arguments:
  aDlg - an array containing the parameters of windows to be created
    Dialog box parameters are contained in aDlg object properties:
      aDlg.ExStyle  - CreateWindowEx dwExStyle (optional)
      aDlg.Class    - CreateWindowEx lpClassName
      aDlg.Title    - CreateWindowEx lpWindowName (optional)
      aDlg.Style    - CreateWindowEx dwStyle
      aDlg.X        - CreateWindowEx x (optional);
      aDlg.Y        - CreateWindowEx y (optional)
      aDlg.W        - CreateWindowEx nWidth (optional); if aDlg.W < 0, aDlg.X is horizontal position of right edge
      aDlg.H        - CreateWindowEx nHeight (optional); if aDlg.H < 0, aDlg.Y is vertical position of bottom edge
      aDlg.Parent   - CreateWindowEx hWndParent (optional)
      aDlg.Menu     - CreateWindowEx hMenu (optional)
      aDlg.Callback - CreateWindowEx lpParam = callback function
      aDlg.Icon     - handle to the icon (optional)
      aDlg.CtlFirst - indentifier of first control (child window) in dialog window, equal to index of first item in aDlg array (optional)
      aDlg.CtlClass - default class for controls (optional)
      aDlg.CtlStyle - additional style for each controls (optional)
      aDlg.CtlFont  - handle to default font in controls, used if no aDlg[ID].Font (optional)
      aDlg.PosPar   - element of screen, in relation of which will be set position of created window (optional):
                        0 - desktop window (default)
                        1 - work area
                        2 - parent window (aDlg.Parent)
                        3 - parent window client area (aDlg.Parent)
                        4 - any window (aDlg.PosRect)
                        5 - any window client area (aDlg.PosRect)
                        6 - pointer to RECT structure (aDlg.PosRect)
                        7 - four-element array (aDlg.PosRect)
                        8 - mouse cursor
      aDlg.PosRect  - if aDlg.PosPar == 4 or 5, it should be window handle,
                      if aDlg.PosPar == 6, it should be pointer to RECT structure containing coordinates of rectangle,
                      if aDlg.PosPar == 7, it should be four-element array containing coordinates of rectangle
      aDlg.PosEdge  - two-character string indicating from which edge of the parent object (aDlg.PosPar) will be set position of dialog window (default is "LT");
                      first character indicates the horizontal position:
                        "L" - from left edge, "R" - from right edge, "C" - center
                      second character indicates the vertical position:
                        "T" - from top edge, "B" - from bottom edge, "C" - center
      aDlg.SizeClt  - if true, aDlg.W and aDlg.H are treated as client area width and height, without frames and menu (optional)
    Parameters of the control with identifier ID are contained in aDlg[ID] object properties:
      aDlg[ID].ExStyle - CreateWindowEx dwExStyle (optional)
      aDlg[ID].Class   - CreateWindowEx lpClassName (optional, default is aDlg.CtlClass or "BUTTON")
      aDlg[ID].Title   - CreateWindowEx lpWindowName (optional)
      aDlg[ID].Style   - CreateWindowEx dwStyle (WS_CHILD can be omitted, will be added automatically), style = aDlg.CtlStyle | aDlg[ID].Style
      aDlg[ID].X       - CreateWindowEx x (optional)
      aDlg[ID].Y       - CreateWindowEx y (optional)
      aDlg[ID].W       - CreateWindowEx nWidth (optional); if aDlg[ID].W < 0, aDlg[ID].X is horizontal position of right edge
      aDlg[ID].H       - CreateWindowEx nHeight (optional); if aDlg[ID].H < 0, aDlg[ID].Y is vertical position of bottom edge
      aDlg[ID].Font    - handle to font (optional)
      aDlg[ID].PosEdge - two-character string specifying control position relative to the dialog client area (optional, default is "LT");
                         first character indicates the horizontal position:
                           "L" - from left edge, "R" - from right edge, "C" - center
                         second character indicates the vertical position:
                           "T" - from top edge, "B" - from bottom edge, "C" - center
  nWhat
     0 - create dialog box and controls (default)
     1 - create dialog box only
     2 - create controls only (dialog must be created earlier)
  hDlg
    Is used if nWhat = 2 and controls are created in callback function after call with WM_CREATE message,
    hDlg should be equal to hWnd parameter from callback function
  nStartID
    First control ID to create, default is aDlg.CtlFirst or 0
  nEndID
    Last control ID to create, default is index of last item in aDlg (aDlg.length - 1)

Return value:
  count of created windows (dialog + controls)

Remarks:
  After function returning, HWND properties contains window handle:
    aDlg.HWND - dialog box handle
    aDlg[ID].HWND - handle to the control with identifier ID
  Before first function call, should be register window class: AkelPad.WindowRegisterClass(aDlg.Class).
  After first function call, should be use AkelPad.WindowGetMessage() for message loop.
  To destroy dialog box: AkelPad.SystemFunction().Call("User32::DestroyWindow", aDlg.HWND).
  To exit message loop: AkelPad.SystemFunction().Call("User32::PostQuitMessage", 0).
  If window class is no longer needed, it should be unregister: AkelPad.WindowUnregisterClass(aDlg.Class).
----------------------------------------------------------------------------------------------------------

-----------------
CreateDialogBox()
-----------------
Create dialog box by using WinAPI functions DialogBoxIndirectParam (modal) or CreateDialogIndirectParam (modeless)
http://msdn.microsoft.com/en-us/library/windows/desktop/ms645461%28v=vs.85%29.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/ms645441%28v=vs.85%29.aspx

Usage:
  if (! AkelPad.Include("CreateDialog_functions.js")) WScript.Quit();
  nResult = CreateDialogBox(aDlg[, bTemplate[, nStartID[, nEndID]]]);

Arguments:
  aDlg - an array containing the parameters of windows to be created
    Dialog box parameters are contained in aDlg object properties:
      aDlg.ExStyle   - extended windows styles (optional)
      aDlg.Title     - title of the dialog box (optional)
      aDlg.Style     - style of the dialog box (combination of window styles and dialog box styles)
      aDlg.X         - x-coordinate of the left edge of the dialog (optional);
      aDlg.Y         - y-coordinate of the top edge of the dialog (optional)
      aDlg.W         - width of the dialog clent area (optional)
      aDlg.H         - height of the dialog clent area (optional)
      aDlg.Parent    - handle to the window that owns the dialog box (optional)
      aDlg.Menu      - handle to the menu (optional)
      aDlg.Callback  - dialog box procedure
      aDlg.Icon      - handle to the icon (optional)
      aDlg.Modeless  - if true, dialog box will be modeless (optional, default is false)
      aDlg.InitParam - value to pass to the dialog box procedure as lParam parameter of the WM_INITDIALOG message (optional)
      aDlg.CtlFirst  - indentifier of first control (child window) in dialog box, equal to index of first item in aDlg array (optional)
      aDlg.CtlClass  - default class for controls (optional)
      aDlg.CtlStyle  - additional style for each controls (optional)
      aDlg.CtlFontN  - font name for each controls eg. "MS Shell Dlg" (optional)
      aDlg.CtlFontS  - font size in pixels (optional, default is 8)
      aDlg.CtlFontI  - if true, font is italic (optional)
      aDlg.PosPix    - default is false - position and size of dialog/controls are set in dialog box units (standard behavior) and PosPar, PosWnd, PosEdge properties are ignored;
                       if true:
                         - position and size are in pixels
                         - DS_ABSALIGN, DS_CENTER, DS_CENTERMOUSE styles are ignored
                         - to determine the position, will be used parameters PosPar, PosWnd, PosEdge
                         - if W < 0, X is horizontal position of right edge
                         - if H < 0, Y is vertical position of bottom edge
      aDlg.PosPar    - element of screen, in relation of which will be set position of created dialog (optional):
                         0 - desktop window (default)
                         1 - work area
                         2 - parent window (aDlg.Parent)
                         3 - parent window client area (aDlg.Parent)
                         4 - any window (aDlg.PosRect)
                         5 - any window client area (aDlg.PosRect)
                         6 - pointer to RECT structure (aDlg.PosRect)
                         7 - four-element array (aDlg.PosRect)
                         8 - mouse cursor
      aDlg.PosRect   - if aDlg.PosPar == 4 or 5, it should be window handle,
                       if aDlg.PosPar == 6, it should be pointer to RECT structure containing coordinates of rectangle,
                       if aDlg.PosPar == 7, it should be four-element array containing coordinates of rectangle
      aDlg.PosEdge   - two-character string indicating from which edge of the parent object (aDlg.PosPar) will be set position of dialog box (default is "LT");
                       first character indicates the horizontal position:
                         "L" - from left edge, "R" - from right edge, "C" - center
                       second character indicates the vertical position:
                         "T" - from top edge, "B" - from bottom edge, "C" - center
    Parameters of the control with identifier ID are contained in aDlg[ID] object properties:
      aDlg[ID].ExStyle - extended window style (optional)
      aDlg[ID].Class   - window class of the control (optional, default is aDlg.CtlClass or "BUTTON")
      aDlg[ID].Title   - text in the control (optional)
      aDlg[ID].Style   - style of the control (WS_CHILD can be omitted, will be added automatically), style = aDlg.CtlStyle | aDlg[ID].Style
      aDlg[ID].X       - x-coordinate of the left edge of the control (optional)
      aDlg[ID].Y       - y-coordinate of the top edge of the control (optional)
      aDlg[ID].W       - width of the control (optional)
      aDlg[ID].H       - height of the control (optional)
      aDlg[ID].PosEdge - two-character string specifying control position relative to the dialog client area (optional, default is "LT");
                         first character indicates the horizontal position:
                           "L" - from left edge, "R" - from right edge, "C" - center
                         second character indicates the vertical position:
                           "T" - from top edge, "B" - from bottom edge, "C" - center
  bTemplate
    If true, function does not create a dialog box, only creates DLGTEMPLATEEX structure and returns a pointer to it.
    In this case following parameters are ignored: Parent, Menu, Callback, Icon, Modeless, InitParam, PosPix, PosPar, PosRect, PosEdge.
  nStartID
    First control ID to create, default is aDlg.CtlFirst or 0
  nEndID
    Last control ID to create, default is index of last item in aDlg (aDlg.length - 1)

Return value:
  if bTemplate
    pointer to DLGTEMPLATEEX structure
  if dialog is modeless
    window handle to the dialog box or 0 if function fails
  if dialog is modal
    nResult parameter specified in the call to the EndDialog function that was used to terminate the dialog box or -1 if function fails

Remarks:
  In the callback function (aDlg.Callback), the handles to windows are available:
    aDlg.HWND - dialog box handle
    aDlg[ID].HWND - handle to the control with identifier ID
  If dialog is modal:
    To destroy dialog box: AkelPad.SystemFunction().Call("User32::EndDialog", aDlg.HWND, nResult).
  If dialog is modeless:
    After first function call, should be use AkelPad.WindowGetMessage() for message loop.
    To destroy dialog box: AkelPad.SystemFunction().Call("User32::DestroyWindow", aDlg.HWND).
    To exit message loop: AkelPad.SystemFunction().Call("User32::PostQuitMessage", 0).
--------------------------------------------------------------------------------------

------------
Scale object
------------
Contains methods:
  Scale.X(nX)  - returns the horizontal coordinate aligned according to screen DPI
  Scale.Y(nY)  - returns the vertical coordinate aligned according to screen DPI
  Scale.UX(nX) - inverse operation to Scale.X
  Scale.UY(nY) - inverse operation to Scale.Y
*/

//Window styles http://msdn.microsoft.com/en-us/library/windows/desktop/ms632600%28v=vs.85%29.aspx
WS_BORDER       = 0x00800000;
WS_CAPTION      = 0x00C00000; //WS_BORDER|WS_DLGFRAME
WS_CHILD        = 0x40000000;
WS_CHILDWINDOW  = WS_CHILD;
WS_CLIPCHILDREN = 0x02000000;
WS_CLIPSIBLINGS = 0x04000000;
WS_DISABLED     = 0x08000000;
WS_DLGFRAME     = 0x00400000;
WS_GROUP        = 0x00020000;
WS_HSCROLL      = 0x00100000;
WS_ICONIC       = 0x20000000;
WS_MAXIMIZE     = 0x01000000;
WS_MAXIMIZEBOX  = 0x00010000;
WS_MINIMIZE     = WS_ICONIC;
WS_MINIMIZEBOX  = 0x00020000;
WS_OVERLAPPED   = 0x00000000;
WS_POPUP        = 0x80000000;
WS_SIZEBOX      = 0x00040000;
WS_SYSMENU      = 0x00080000;
WS_TABSTOP      = 0x00010000;
WS_THICKFRAME   = WS_SIZEBOX;
WS_TILED        = WS_OVERLAPPED;
WS_VISIBLE      = 0x10000000;
WS_VSCROLL      = 0x00200000;

WS_OVERLAPPEDWINDOW = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
WS_POPUPWINDOW      = WS_POPUP | WS_BORDER | WS_SYSMENU;
WS_TILEDWINDOW      = WS_OVERLAPPEDWINDOW;

//Window extended styles http://msdn.microsoft.com/en-us/library/windows/desktop/ff700543%28v=vs.85%29.aspx
WS_EX_ACCEPTFILES      = 0x00000010;
WS_EX_APPWINDOW        = 0x00040000;
WS_EX_CLIENTEDGE       = 0x00000200;
WS_EX_COMPOSITED       = 0x02000000;
WS_EX_CONTEXTHELP      = 0x00000400;
WS_EX_CONTROLPARENT    = 0x00010000;
WS_EX_DLGMODALFRAME    = 0x00000001;
WS_EX_LAYERED          = 0x00080000;
WS_EX_LAYOUTRTL        = 0x00400000;
WS_EX_LEFT             = 0x00000000;
WS_EX_LEFTSCROLLBAR    = 0x00004000;
WS_EX_LTRREADING       = 0x00000000;
WS_EX_MDICHILD         = 0x00000040;
WS_EX_NOACTIVATE       = 0x08000000;
WS_EX_NOINHERITLAYOUT  = 0x00100000;
WS_EX_NOPARENTNOTIFY   = 0x00000004;
WS_EX_RIGHT            = 0x00001000;
WS_EX_RIGHTSCROLLBAR   = 0x00000000;
WS_EX_RTLREADING       = 0x00002000;
WS_EX_STATICEDGE       = 0x00020000;
WS_EX_TOOLWINDOW       = 0x00000080;
WS_EX_TOPMOST          = 0x00000008;
WS_EX_TRANSPARENT      = 0x00000020;
WS_EX_WINDOWEDGE       = 0x00000100;
WS_EX_OVERLAPPEDWINDOW = WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE;
WS_EX_PALETTEWINDOW    = WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST;

//DialogBox styles http://msdn.microsoft.com/en-us/library/windows/desktop/ff729172%28v=vs.85%29.aspx
DS_3DLOOK        = 0x0004;
DS_ABSALIGN      = 0x0001;
DS_CENTER        = 0x0800;
DS_CENTERMOUSE   = 0x1000;
DS_CONTEXTHELP   = 0x2000;
DS_CONTROL       = 0x0400;
DS_FIXEDSYS      = 0x0008;
DS_LOCALEDIT     = 0x0020;
DS_MODALFRAME    = 0x0080;
DS_NOFAILCREATE  = 0x0010;
DS_NOIDLEMSG     = 0x0100;
DS_SETFONT       = 0x0040;
DS_SETFOREGROUND = 0x0200;
DS_SHELLFONT     = DS_SETFONT | DS_FIXEDSYS;
DS_SYSMODAL      = 0x0002;

//Class "BUTTON"
//Button styles http://msdn.microsoft.com/en-us/library/windows/desktop/bb775951%28v=vs.85%29.aspx
BS_3STATE          = 0x0005;
BS_AUTO3STATE      = 0x0006;
BS_AUTOCHECKBOX    = 0x0003;
BS_AUTORADIOBUTTON = 0x0009;
BS_BITMAP          = 0x0080;
BS_BOTTOM          = 0x0800;
BS_CENTER          = 0x0300;
BS_CHECKBOX        = 0x0002;
BS_DEFPUSHBUTTON   = 0x0001;
BS_FLAT            = 0x8000;
BS_GROUPBOX        = 0x0007;
BS_ICON            = 0x0040;
BS_LEFT            = 0x0100;
BS_LEFTTEXT        = 0x0020;
BS_MULTILINE       = 0x2000;
BS_NOTIFY          = 0x4000;
BS_OWNERDRAW       = 0x000B;
BS_PUSHBUTTON      = 0x0000;
BS_PUSHLIKE        = 0x1000;
BS_RADIOBUTTON     = 0x0004;
BS_RIGHT           = 0x0200;
BS_RIGHTBUTTON     = BS_LEFTTEXT;
BS_TEXT            = 0x0000;
BS_TOP             = 0x0400;
BS_VCENTER         = 0x0C00;
//Win Vista
BS_SPLITBUTTON     = 0x000C;
BS_DEFSPLITBUTTON  = 0x000D;
BS_COMMANDLINK     = 0x000E;
BS_DEFCOMMANDLINK  = 0x000F;

//Class "COMBOBOX"
//ComboBoxEx extended styles http://msdn.microsoft.com/en-us/library/windows/desktop/bb775742%28v=vs.85%29.aspx
//ComboBox styles            http://msdn.microsoft.com/en-us/library/windows/desktop/bb775796%28v=vs.85%29.aspx
CBS_AUTOHSCROLL       = 0x0040;
CBS_DISABLENOSCROLL   = 0x0800;
CBS_DROPDOWN          = 0x0002; //+ComboBoxEx
CBS_DROPDOWNLIST      = 0x0003; //+ComboBoxEx
CBS_HASSTRINGS        = 0x0200;
CBS_LOWERCASE         = 0x4000;
CBS_NOINTEGRALHEIGHT  = 0x0400;
CBS_OEMCONVERT        = 0x0080;
CBS_OWNERDRAWFIXED    = 0x0010;
CBS_OWNERDRAWVARIABLE = 0x0020;
CBS_SIMPLE            = 0x0001; //+ComboBoxEx
CBS_SORT              = 0x0100;
CBS_UPPERCASE         = 0x2000;

//Class "SysDateTimePick32"
//DateTimePicker control styles http://msdn.microsoft.com/en-us/library/windows/desktop/bb761728%28v=vs.85%29.aspx
DTS_APPCANPARSE            = 0x10;
DTS_LONGDATEFORMAT         = 0x04;
DTS_RIGHTALIGN             = 0x20;
DTS_SHOWNONE               = 0x02;
DTS_SHORTDATEFORMAT        = 0x00;
DTS_SHORTDATECENTURYFORMAT = 0x0C;
DTS_TIMEFORMAT             = 0x09;
DTS_UPDOWN                 = 0x01;

//Class "EDIT"
//Edit control styles http://msdn.microsoft.com/en-us/library/windows/desktop/bb775464%28v=vs.85%29.aspx
ES_AUTOHSCROLL = 0x0080; //+RichEdit
ES_AUTOVSCROLL = 0x0040; //+RichEdit
ES_CENTER      = 0x0001; //+RichEdit
ES_LEFT        = 0x0000; //+RichEdit
ES_LOWERCASE   = 0x0010;
ES_MULTILINE   = 0x0004; //+RichEdit
ES_NOHIDESEL   = 0x0100; //+RichEdit
ES_NUMBER      = 0x2000; //+RichEdit
ES_OEMCONVERT  = 0x0400;
ES_PASSWORD    = 0x0020; //+RichEdit
ES_READONLY    = 0x0800; //+RichEdit
ES_RIGHT       = 0x0002; //+RichEdit
ES_UPPERCASE   = 0x0008;
ES_WANTRETURN  = 0x1000; //+RichEdit

//Class "RichEdit50W";
//Library "Msftedit.dll";
//RichEdit control styles http://msdn.microsoft.com/en-us/library/windows/desktop/bb774367%28v=vs.85%29.aspx
ES_DISABLENOSCROLL = 0x00002000;
ES_NOIME           = 0x00080000;
ES_NOOLEDRAGDROP   = 0x00000008;
ES_SAVESEL         = 0x00008000;
ES_SELECTIONBAR    = 0x01000000;
ES_SELFIME         = 0x00040000;
ES_SUNKEN          = 0x00004000;
ES_VERTICAL        = 0x00400000;

//Class "SysHeader32"
//Header control styles http://msdn.microsoft.com/en-us/library/windows/desktop/bb775241%28v=vs.85%29.aspx
HDS_BUTTONS   = 0x0002;
HDS_DRAGDROP  = 0x0040;
HDS_FILTERBAR = 0x0100;
HDS_FLAT      = 0x0200;
HDS_FULLDRAG  = 0x0080;
HDS_HIDDEN    = 0x0008;
HDS_HORZ      = 0x0000;
HDS_HOTTRACK  = 0x0004;
//Win Vista
HDS_CHECKBOXES = 0x0400;
HDS_NOSIZING   = 0x0800;
HDS_OVERFLOW   = 0x1000;

//Class "LISTBOX"
//ListBox styles http://msdn.microsoft.com/en-us/library/windows/desktop/bb775149%28v=vs.85%29.aspx
LBS_COMBOBOX          = 0x8000;
LBS_DISABLENOSCROLL   = 0x1000;
LBS_EXTENDEDSEL       = 0x0800;
LBS_HASSTRINGS        = 0x0040;
LBS_MULTICOLUMN       = 0x0200;
LBS_MULTIPLESEL       = 0x0008;
LBS_NODATA            = 0x2000;
LBS_NOINTEGRALHEIGHT  = 0x0100;
LBS_NOREDRAW          = 0x0004;
LBS_NOSEL             = 0x4000;
LBS_NOTIFY            = 0x0001;
LBS_OWNERDRAWFIXED    = 0x0010;
LBS_OWNERDRAWVARIABLE = 0x0020;
LBS_SORT              = 0x0002;
LBS_STANDARD          = LBS_NOTIFY | LBS_SORT | WS_VSCROLL | WS_BORDER;
LBS_USETABSTOPS       = 0x0080;
LBS_WANTKEYBOARDINPUT = 0x0400;

//Class "SysListView32"
//ListView extended styles http://msdn.microsoft.com/en-us/library/windows/desktop/bb774732%28v=vs.85%29.aspx
//ListView styles          http://msdn.microsoft.com/en-us/library/windows/desktop/bb774739%28v=vs.85%29.aspx
LVS_ALIGNLEFT       = 0x0800;
LVS_ALIGNMASK       = 0x0C00;
LVS_ALIGNTOP        = 0x0000;
LVS_AUTOARRANGE     = 0x0100;
LVS_EDITLABELS      = 0x0200;
LVS_ICON            = 0x0000;
LVS_LIST            = 0x0003;
LVS_NOCOLUMNHEADER  = 0x4000;
LVS_NOLABELWRAP     = 0x0080;
LVS_NOSCROLL        = 0x2000;
LVS_NOSORTHEADER    = 0x8000;
LVS_OWNERDATA       = 0x1000;
LVS_OWNERDRAWFIXED  = 0x0400;
LVS_REPORT          = 0x0001;
LVS_SHAREIMAGELISTS = 0x0040;
LVS_SHOWSELALWAYS   = 0x0008;
LVS_SINGLESEL       = 0x0004;
LVS_SMALLICON       = 0x0002;
LVS_SORTASCENDING   = 0x0010;
LVS_SORTDESCENDING  = 0x0020;
LVS_TYPEMASK        = 0x0003;
LVS_TYPESTYLEMASK   = 0XFC00;

//Class "SysMonthCal32"
//MonthCalendar control styles http://msdn.microsoft.com/en-us/library/windows/desktop/bb760919%28v=vs.85%29.aspx
MCS_DAYSTATE      = 0x0001;
MCS_MULTISELECT   = 0x0002;
MCS_WEEKNUMBERS   = 0x0004;
MCS_NOTODAYCIRCLE = 0x0008;
MCS_NOTODAY       = 0x0010;
//Win Vista
MCS_NOTRAILINGDATES  = 0x0040;
MCS_SHORTDAYSOFWEEK  = 0x0080;
MCS_NOSELCHANGEONNAV = 0x0100;

//Class "msctls_progress32"
//ProgressBar control styles http://msdn.microsoft.com/en-us/library/windows/desktop/bb760820%28v=vs.85%29.aspx
PBS_MARQUEE  = 0x08;
PBS_SMOOTH   = 0x01;
PBS_VERTICAL = 0x04;
//Win Vista
PBS_SMOOTHREVERSE = 0x10;

//Class "SCROLLBAR"
//ScrollBar control styles http://msdn.microsoft.com/en-us/library/windows/desktop/bb787533%28v=vs.85%29.aspx
SBS_BOTTOMALIGN             = 0x0004;
SBS_HORZ                    = 0x0000;
SBS_LEFTALIGN               = 0x0002;
SBS_RIGHTALIGN              = 0x0004;
SBS_SIZEBOX                 = 0x0008;
SBS_SIZEBOXBOTTOMRIGHTALIGN = 0x0004;
SBS_SIZEBOXTOPLEFTALIGN     = 0x0002;
SBS_SIZEGRIP                = 0x0010;
SBS_TOPALIGN                = 0x0002;
SBS_VERT                    = 0x0001;

//Class "STATIC"
//Static control styles http://msdn.microsoft.com/en-us/library/windows/desktop/bb760773%28v=vs.85%29.aspx
SS_BITMAP         = 0x000E;
SS_BLACKFRAME     = 0x0007;
SS_BLACKRECT      = 0x0004;
SS_CENTER         = 0x0001;
SS_CENTERIMAGE    = 0x0200;
SS_EDITCONTROL    = 0x2000;
SS_ENDELLIPSIS    = 0x4000;
SS_ENHMETAFILE    = 0x000F;
SS_ETCHEDFRAME    = 0x0012;
SS_ETCHEDHORZ     = 0x0010;
SS_ETCHEDVERT     = 0x0011;
SS_GRAYFRAME      = 0x0008;
SS_GRAYRECT       = 0x0005;
SS_ICON           = 0x0003;
SS_LEFT           = 0x0000;
SS_LEFTNOWORDWRAP = 0x000C;
SS_NOPREFIX       = 0x0080;
SS_NOTIFY         = 0x0100;
SS_OWNERDRAW      = 0x000D;
SS_PATHELLIPSIS   = 0x8000;
SS_REALSIZEIMAGE  = 0x0800;
SS_RIGHT          = 0x0002;
SS_RIGHTJUST      = 0x0400;
SS_SIMPLE         = 0x000B;
SS_SUNKEN         = 0x1000;
SS_TYPEMASK       = 0x001F;
SS_WHITEFRAME     = 0x0009;
SS_WHITERECT      = 0x0006;
SS_WORDELLIPSIS   = 0xC000;

//Class "msctls_statusbar32"
//StatusBar styles http://msdn.microsoft.com/en-us/library/windows/desktop/bb760730%28v=vs.85%29.aspx
SBARS_SIZEGRIP = 0x0100;
SBARS_TOOLTIPS = 0x0800;

//Class "SysLink"
//SysLink control styles http://msdn.microsoft.com/en-us/library/windows/desktop/cc136543%28v=vs.85%29.aspx
LWS_TRANSPARENT  = 0x0001;
LWS_IGNORERETURN = 0x0002;
//Win Vista
LWS_NOPREFIX       = 0x0004;
LWS_USEVISUALSTYLE = 0x0008;
LWS_USECUSTOMTEXT  = 0x0010;
LWS_RIGHT          = 0x0020;

//Class "SysTabControl32"
//Tab control extended styles http://msdn.microsoft.com/en-us/library/windows/desktop/bb760546%28v=vs.85%29.aspx
//Tab control styles          http://msdn.microsoft.com/en-us/library/windows/desktop/bb760549%28v=vs.85%29.aspx
TCS_BOTTOM            = 0x0002;
TCS_BUTTONS           = 0x0100;
TCS_FIXEDWIDTH        = 0x0400;
TCS_FLATBUTTONS       = 0x0008;
TCS_FOCUSNEVER        = 0x8000;
TCS_FOCUSONBUTTONDOWN = 0x1000;
TCS_FORCEICONLEFT     = 0x0010;
TCS_FORCELABELLEFT    = 0x0020;
TCS_HOTTRACK          = 0x0040;
TCS_MULTILINE         = 0x0200;
TCS_MULTISELECT       = 0x0004;
TCS_OWNERDRAWFIXED    = 0x2000;
TCS_RAGGEDRIGHT       = 0x0800;
TCS_RIGHT             = 0x0002;
TCS_RIGHTJUSTIFY      = 0x0000;
TCS_SCROLLOPPOSITE    = 0x0001;
TCS_SINGLELINE        = 0x0000;
TCS_TABS              = 0x0000;
TCS_TOOLTIPS          = 0x4000;
TCS_VERTICAL          = 0x0080;

//Class "ToolbarWindow32"
//Toolbar control extended styles   http://msdn.microsoft.com/en-us/library/windows/desktop/bb760430%28v=vs.85%29.aspx
//Toolbar control and Button styles http://msdn.microsoft.com/en-us/library/windows/desktop/bb760439%28v=vs.85%29.aspx
TBSTYLE_ALTDRAG      = 0x0400;
TBSTYLE_CUSTOMERASE  = 0x2000;
TBSTYLE_FLAT         = 0x0800;
TBSTYLE_LIST         = 0x1000;
TBSTYLE_REGISTERDROP = 0x4000;
TBSTYLE_TOOLTIPS     = 0x0100;
TBSTYLE_TRANSPARENT  = 0x8000;
TBSTYLE_WRAPABLE     = 0x0200;

BTNS_AUTOSIZE      = 0x0010;
BTNS_BUTTON        = 0x0000;
BTNS_CHECK         = 0x0002;
BTNS_DROPDOWN      = 0x0008;
BTNS_GROUP         = 0x0004;
BTNS_NOPREFIX      = 0x0020;
BTNS_SEP           = 0x0001;
BTNS_SHOWTEXT      = 0x0040;
BTNS_WHOLEDROPDOWN = 0x0080;
BTNS_CHECKGROUP    = BTNS_CHECK | BTNS_GROUP;

//Class "tooltips_class32"
//Tooltip styles http://msdn.microsoft.com/en-us/library/windows/desktop/bb760248%28v=vs.85%29.aspx
TTS_ALWAYSTIP      = 0x0001;
TTS_BALLOON        = 0x0040;
TTS_CLOSE          = 0x0080;
TTS_NOANIMATE      = 0x0010;
TTS_NOFADE         = 0x0020;
TTS_NOPREFIX       = 0x0002;
TTS_USEVISUALSTYLE = 0x0100;

//Class "msctls_trackbar32"
//TrackBar control styles http://msdn.microsoft.com/en-us/library/windows/desktop/bb760147%28v=vs.85%29.aspx
TBS_AUTOTICKS      = 0x0001;
TBS_VERT           = 0x0002;
TBS_HORZ           = 0x0000;
TBS_TOP            = 0x0004;
TBS_BOTTOM         = 0x0000;
TBS_LEFT           = 0x0004;
TBS_RIGHT          = 0x0000;
TBS_BOTH           = 0x0008;
TBS_NOTICKS        = 0x0010;
TBS_ENABLESELRANGE = 0x0020;
TBS_FIXEDLENGTH    = 0x0040;
TBS_NOTHUMB        = 0x0080;
TBS_REVERSED       = 0x0200;
TBS_DOWNISLEFT     = 0x0400;
//Win Vista
TBS_NOTIFYBEFOREMOVE = 0x0800;
TBS_TRANSPARENTBKGND = 0x1000;

//Class "SysTreeView32"
//Tree-View control extended styles http://msdn.microsoft.com/en-us/library/windows/desktop/bb759981%28v=vs.85%29.aspx
//Tree-View control styles          http://msdn.microsoft.com/en-us/library/windows/desktop/bb760013%28v=vs.85%29.aspx
TVS_CHECKBOXES      = 0x0100;
TVS_DISABLEDRAGDROP = 0x0010;
TVS_EDITLABELS      = 0x0008;
TVS_FULLROWSELECT   = 0x1000;
TVS_HASBUTTONS      = 0x0001;
TVS_HASLINES        = 0x0002;
TVS_INFOTIP         = 0x0800;
TVS_LINESATROOT     = 0x0004;
TVS_NOHSCROLL       = 0x8000;
TVS_NONEVENHEIGHT   = 0x4000;
TVS_NOSCROLL        = 0x2000;
TVS_NOTOOLTIPS      = 0x0080;
TVS_RTLREADING      = 0x0040;
TVS_SHOWSELALWAYS   = 0x0020;
TVS_SINGLEEXPAND    = 0x0400;
TVS_TRACKSELECT     = 0x0200;

//Class "msctls_updown32"
//Up-Down control styles http://msdn.microsoft.com/en-us/library/windows/desktop/bb759885%28v=vs.85%29.aspx
UDS_ALIGNLEFT   = 0x0008;
UDS_ALIGNRIGHT  = 0x0004;
UDS_ARROWKEYS   = 0x0020;
UDS_AUTOBUDDY   = 0x0010;
UDS_HORZ        = 0x0040;
UDS_HOTTRACK    = 0x0100;
UDS_NOTHOUSANDS = 0x0080;
UDS_SETBUDDYINT = 0x0002;
UDS_WRAP        = 0x0001;

(Scale =
{
  Init: function()
  {
    var hWnd = AkelPad.GetMainWnd();
    var hDC  = AkelPad.SystemFunction().Call("User32::GetDC", hWnd);
    this.ScaleX = AkelPad.SystemFunction().Call("Gdi32::GetDeviceCaps", hDC, 88 /*LOGPIXELSX*/);
    this.ScaleY = AkelPad.SystemFunction().Call("Gdi32::GetDeviceCaps", hDC, 90 /*LOGPIXELSY*/);
    AkelPad.SystemFunction().Call("User32::ReleaseDC", hWnd, hDC);
    //Align to 16 pixel
    this.ScaleX += (16 - this.ScaleX % 16) % 16;
    this.ScaleY += (16 - this.ScaleY % 16) % 16;
  },
  X:  function(n) {return AkelPad.SystemFunction().Call("Kernel32::MulDiv", n, this.ScaleX, 96);},
  Y:  function(n) {return AkelPad.SystemFunction().Call("Kernel32::MulDiv", n, this.ScaleY, 96);},
  UX: function(n) {return AkelPad.SystemFunction().Call("Kernel32::MulDiv", n, 96, this.ScaleX);},
  UY: function(n) {return AkelPad.SystemFunction().Call("Kernel32::MulDiv", n, 96, this.ScaleY);}
}).Init();

function CreateDialogWindow(aDlg, nWhat, hDlg, nStartID, nEndID)
{
  var oSys      = AkelPad.SystemFunction();
  var hInstDLL  = AkelPad.GetInstanceDll();
  var lpRect    = AkelPad.MemAlloc(16 /*sizeof(RECT)*/);
  var nWndCount = 0;
  var nFX       = 0;
  var nFY       = 0;
  var nDlgX, nDlgY, nDlgW, nDlgH;
  var nParX, nParY, nParW, nParH;
  var nCtlX, nCtlY, nCtlW, nCtlH;
  var sCtlClass;
  var i;
 
  if ((nWhat !== 1) && (nWhat !== 2)) nWhat = 0;

  //create dialog
  if ((nWhat < 2) && (! aDlg.HWND))
  {
    if (aDlg.Style & WS_CHILD) aDlg.Style ^= WS_CHILD;

    if ((aDlg.Style & WS_SIZEBOX) && ((aDlg.Style & WS_BORDER) || (aDlg.Style & WS_DLGFRAME)))
    {
      nFX = oSys.Call("User32::GetSystemMetrics", 32 /*SM_CXSIZEFRAME*/) * 2;
      nFY = oSys.Call("User32::GetSystemMetrics", 33 /*SM_CYSIZEFRAME*/) * 2;
    }
    else if ((aDlg.Style & WS_SIZEBOX) || (aDlg.Style & WS_DLGFRAME))
    {
      nFX = oSys.Call("User32::GetSystemMetrics", 7 /*SM_CXDLGFRAME*/) * 2;
      nFY = oSys.Call("User32::GetSystemMetrics", 8 /*SM_CYDLGFRAME*/) * 2;
    }
    else if (aDlg.Style & WS_BORDER)
    {
      nFX = oSys.Call("User32::GetSystemMetrics", 5 /*SM_CXBORDER*/) * 2;
      nFY = oSys.Call("User32::GetSystemMetrics", 6 /*SM_CYBORDER*/) * 2;
    }

    if (aDlg.Style & WS_VSCROLL)
      nFX += oSys.Call("User32::GetSystemMetrics", 2 /*SM_CXVSCROLL*/);
    if (aDlg.Style & WS_HSCROLL)
      nFY += oSys.Call("User32::GetSystemMetrics", 3 /*SM_CYHSCROLL*/);
    if ((aDlg.Style & WS_BORDER) && (aDlg.Style & WS_DLGFRAME))
      nFY += oSys.Call("User32::GetSystemMetrics", 4 /*SM_CYCAPTION*/);
    if (oSys.Call("User32::IsMenu", aDlg.Menu))
      nFY += oSys.Call("User32::GetSystemMetrics", 15 /*SM_CYMENU*/);

    nDlgX = Scale.X(aDlg.X || 0);
    nDlgY = Scale.Y(aDlg.Y || 0);
    nDlgW = aDlg.W || 0;
    nDlgH = aDlg.H || 0;

    if (aDlg.SizeClt)
    {
      nDlgW = Scale.X(nDlgW) + ((nDlgW < 0) ? -nFX : nFX);
      nDlgH = Scale.Y(nDlgH) + ((nDlgH < 0) ? -nFY : nFY);
    }
    else
    {
      if (nDlgW > nFX)
        nDlgW = Scale.X(nDlgW - nFX) + nFX;
      else if (nDlgW < -nFX)
        nDlgW = Scale.X(nDlgW + nFX) - nFX;

      if (nDlgH > nFY)
        nDlgH = Scale.Y(nDlgH - nFY) + nFY;
      else if (nDlgH < -nFY)
        nDlgH = Scale.Y(nDlgH + nFY) - nFY;
    }

    if (aDlg.PosPar == 1)
      oSys.Call("User32::SystemParametersInfoW", 0x30 /*SPI_GETWORKAREA*/, 0, lpRect, 0);
    else if ((aDlg.PosPar == 2) && oSys.Call("User32::IsWindow", aDlg.Parent))
      oSys.Call("User32::GetWindowRect", aDlg.Parent, lpRect);
    else if ((aDlg.PosPar == 3) && oSys.Call("User32::IsWindow", aDlg.Parent))
    {
      oSys.Call("User32::GetClientRect", aDlg.Parent, lpRect);
      oSys.Call("User32::ClientToScreen", aDlg.Parent, lpRect);
      oSys.Call("User32::ClientToScreen", aDlg.Parent, lpRect + 8);
    }
    else if ((aDlg.PosPar == 4) && oSys.Call("User32::IsWindow", aDlg.PosRect))
      oSys.Call("User32::GetWindowRect", aDlg.PosRect, lpRect);
    else if ((aDlg.PosPar == 5) && oSys.Call("User32::IsWindow", aDlg.PosRect))
    {
      oSys.Call("User32::GetClientRect", aDlg.PosRect, lpRect);
      oSys.Call("User32::ClientToScreen", aDlg.PosRect, lpRect);
      oSys.Call("User32::ClientToScreen", aDlg.PosRect, lpRect + 8);
    }
    else if ((aDlg.PosPar == 6) && aDlg.PosRect)
    {
      for (i = 0; i < 16; i += 4)
        AkelPad.MemCopy(lpRect + i, AkelPad.MemRead(aDlg.PosRect + i, 3 /*DT_DWORD*/), 3 /*DT_DWORD*/);
    }
    else if ((aDlg.PosPar == 7) && aDlg.PosRect)
    {
      for (i = 0; i < 4; ++i)
        AkelPad.MemCopy(lpRect + i * 4, aDlg.PosRect[i], 3 /*DT_DWORD*/);
    }
    else if (aDlg.PosPar == 8)
    {
      oSys.Call("User32::GetCursorPos", lpRect);
      oSys.Call("User32::GetCursorPos", lpRect + 8);
    }
    else
      oSys.Call("User32::GetWindowRect", oSys.Call("User32::GetDesktopWindow"), lpRect);

    nParX = AkelPad.MemRead(lpRect,      3 /*DT_DWORD*/);
    nParY = AkelPad.MemRead(lpRect +  4, 3 /*DT_DWORD*/);
    nParW = AkelPad.MemRead(lpRect +  8, 3 /*DT_DWORD*/) - nParX;
    nParH = AkelPad.MemRead(lpRect + 12, 3 /*DT_DWORD*/) - nParY;
    nDlgX += nParX;
    nDlgY += nParY;

    if (aDlg.PosEdge)
    {
      aDlg.PosEdge = aDlg.PosEdge.toUpperCase();

      if (aDlg.PosEdge.charAt(0) == "R")
        nDlgX += nParW;
      else if (aDlg.PosEdge.charAt(0) == "C")
        nDlgX = nParX + (nParW - nDlgW) / 2;

      if (aDlg.PosEdge.charAt(1) == "B")
        nDlgY += nParH;
      else if (aDlg.PosEdge.charAt(1) == "C")
        nDlgY = nParY + (nParH - nDlgH) / 2;
    }

    if (nDlgW < 0)
    {
      nDlgW = -nDlgW;
      nDlgX -= nDlgW;
    }
    if (nDlgH < 0)
    {
      nDlgH = -nDlgH;
      nDlgY -= nDlgH;
    }

    aDlg.HWND = oSys.Call("User32::CreateWindowExW",
      aDlg.ExStyle,  //dwExStyle
      aDlg.Class,    //lpClassName
      aDlg.Title,    //lpWindowName
      aDlg.Style,    //dwStyle
      nDlgX,         //x
      nDlgY,         //y
      nDlgW,         //nWidth
      nDlgH,         //nHeight
      aDlg.Parent,   //hWndParent
      aDlg.Menu,     //hMenu
      hInstDLL,      //hInstance
      aDlg.Callback);//lpParam

    if (aDlg.HWND)
    {
      ++nWndCount;
      if (aDlg.Icon)
      {
        AkelPad.SendMessage(aDlg.HWND, 128 /*WM_SETICON*/, 0 /*ICON_SMALL*/, aDlg.Icon);
        AkelPad.SendMessage(aDlg.HWND, 128 /*WM_SETICON*/, 1 /*ICON_BIG*/,   aDlg.Icon);
      }
    }
  }

  //create controls
  if ((nWhat == 0) || (nWhat == 2))
  {
    hDlg = hDlg || aDlg.HWND;

    if (hDlg)
    {
      oSys.Call("User32::GetClientRect", hDlg, lpRect);
      nDlgW = AkelPad.MemRead(lpRect +  8, 3 /*DT_DWORD*/);
      nDlgH = AkelPad.MemRead(lpRect + 12, 3 /*DT_DWORD*/);

      if (arguments.length < 5)
      {
        if (arguments.length < 4) nStartID = aDlg.CtlFirst || 0;
        nEndID = aDlg.length - 1;
      }
      nEndID = Math.max(nStartID, nEndID);

      for (i = nStartID; i <= nEndID; ++i)
      {
        if (aDlg[i])
        {
          sCtlClass = aDlg[i].Class || aDlg.CtlClass || "BUTTON";

          aDlg[i].Style |= aDlg.CtlStyle | WS_CHILD;
          if (aDlg[i].Style & WS_POPUP) aDlg[i].Style ^= WS_POPUP;

          nCtlX = Scale.X(aDlg[i].X || 0);
          nCtlY = Scale.Y(aDlg[i].Y || 0);
          nCtlW = Scale.X(aDlg[i].W || 0);
          nCtlH = Scale.Y(aDlg[i].H || 0);

          if (aDlg[i].PosEdge)
          {
            aDlg[i].PosEdge = aDlg[i].PosEdge.toUpperCase();

            if (aDlg[i].PosEdge.charAt(0) == "R")
              nCtlX += nDlgW;
            else if (aDlg[i].PosEdge.charAt(0) == "C")
              nCtlX = (nDlgW - nCtlW) / 2;

            if (aDlg[i].PosEdge.charAt(1) == "B")
              nCtlY += nDlgH;
            else if (aDlg[i].PosEdge.charAt(1) == "C")
              nCtlY = (nDlgH - nCtlH) / 2;
          }

          if (nCtlW < 0)
          {
            nCtlW = -nCtlW;
            nCtlX -= nCtlW;
          }
          if (nCtlH < 0)
          {
            nCtlH = -nCtlH;
            nCtlY -= nCtlH;
          }

          aDlg[i].HWND = oSys.Call("User32::CreateWindowExW",
            aDlg[i].ExStyle,//dwExStyle
            sCtlClass,      //lpClassName
            aDlg[i].Title,  //lpWindowName
            aDlg[i].Style,  //dwStyle
            nCtlX,          //x
            nCtlY,          //y
            nCtlW,          //nWidth
            nCtlH,          //nHeight
            hDlg,           //hWndParent
            i,              //ID
            hInstDLL,       //hInstance
            0);             //lpParam

          if (aDlg[i].HWND)
          {
            ++nWndCount;
            AkelPad.SendMessage(aDlg[i].HWND, 48 /*WM_SETFONT*/, aDlg[i].Font || aDlg.CtlFont, true);
          }
        }
      }
    }
  }

  AkelPad.MemFree(lpRect);
  return nWndCount;
}

function CreateDialogBox(aDlg, bTemplate, nStartID, nEndID)
{
  var oSys      = AkelPad.SystemFunction();
  var nCtlCount = 0;
  var nResult   = aDlg.Modeless ? 0 : -1;
  var sTitle    = aDlg.Title || "";
  var nCtlFontS = aDlg.CtlFontS || 8;
  var nTempLen  = 30 + (sTitle.length + 1) * 2;
  var lpTemp;
  var lpItem;
  var sCtlClass;
  var sCtlTitle;
  var i;

  if (arguments.length < 4)
  {
    if (arguments.length < 3) nStartID = aDlg.CtlFirst || 0;
    nEndID = aDlg.length - 1;
  }
  nEndID = Math.max(nStartID, nEndID);

  if (aDlg.Style & WS_CHILD) aDlg.Style ^= WS_CHILD;

  if (aDlg.CtlFontN)
  {
    aDlg.Style |= DS_SETFONT;
    nTempLen   += 6 + (aDlg.CtlFontN.length + 1) * 2;
  }
  else if (aDlg.Style & DS_SETFONT)
    aDlg.Style ^= DS_SETFONT;

  nTempLen += (4 - nTempLen % 4) % 4; //align to DWORD

  for (i = nStartID; i <= nEndID; ++i)
  {
    if (aDlg[i])
    {
      sCtlClass = aDlg[i].Class || aDlg.CtlClass || "BUTTON";
      sCtlTitle = aDlg[i].Title || "";

      aDlg[i].Style |= aDlg.CtlStyle | WS_CHILD;
      if (aDlg[i].Style & WS_POPUP) aDlg[i].Style ^= WS_POPUP;

      nTempLen += 26 + (sCtlClass.length + 1) * 2 + (sCtlTitle.length + 1) * 2;
      nTempLen += (4 - nTempLen % 4) % 4; //align to DWORD
      ++nCtlCount;
    }
  }

  lpTemp = AkelPad.MemAlloc(nTempLen);
  lpItem = lpTemp;

  //fill DLGTEMPLATEEX
  AkelPad.MemCopy(lpItem,                     1, 4 /*DT_WORD*/);   //dlgVer
  AkelPad.MemCopy(lpItem +  2,           0xFFFF, 4 /*DT_WORD*/);   //signature
  AkelPad.MemCopy(lpItem +  8,     aDlg.ExStyle, 3 /*DT_DWORD*/);  //exStyle
  AkelPad.MemCopy(lpItem + 12,       aDlg.Style, 3 /*DT_DWORD*/);  //style
  AkelPad.MemCopy(lpItem + 16,        nCtlCount, 4 /*DT_WORD*/);   //cDlgItems
  AkelPad.MemCopy(lpItem + 18,           aDlg.X, 4 /*DT_WORD*/);   //x
  AkelPad.MemCopy(lpItem + 20,           aDlg.Y, 4 /*DT_WORD*/);   //y
  AkelPad.MemCopy(lpItem + 22, Math.abs(aDlg.W), 4 /*DT_WORD*/);   //cx
  AkelPad.MemCopy(lpItem + 24, Math.abs(aDlg.H), 4 /*DT_WORD*/);   //cy
  AkelPad.MemCopy(lpItem + 30,           sTitle, 1 /*DT_UNICODE*/);//title
  lpItem += 30 + (sTitle.length + 1) * 2;
  if (aDlg.CtlFontN)
  {
    AkelPad.MemCopy(lpItem,         nCtlFontS, 4 /*DT_WORD*/);   //pointsize
    AkelPad.MemCopy(lpItem + 4, aDlg.CtlFontI, 5 /*DT_BYTE*/);   //italic
    AkelPad.MemCopy(lpItem + 5,             1, 5 /*DT_BYTE*/);   //charset=DEFAULT_CHARSET
    AkelPad.MemCopy(lpItem + 6, aDlg.CtlFontN, 1 /*DT_UNICODE*/);//typeface
    lpItem += 6 + (aDlg.CtlFontN.length + 1) * 2;
  }
  lpItem += (4 - lpItem % 4) % 4; //align to DWORD

  //fill DLGITEMTEMPLATEEX
  for (i = nStartID; i <= nEndID; ++i)
  {
    if (aDlg[i])
    {
      sCtlClass = aDlg[i].Class || aDlg.CtlClass || "BUTTON";
      sCtlTitle = aDlg[i].Title || "";
      AkelPad.MemCopy(lpItem +  4,     aDlg[i].ExStyle, 3 /*DT_DWORD*/);  //exStyle
      AkelPad.MemCopy(lpItem +  8,       aDlg[i].Style, 3 /*DT_DWORD*/);  //style
      AkelPad.MemCopy(lpItem + 12,           aDlg[i].X, 4 /*DT_WORD*/);   //x
      AkelPad.MemCopy(lpItem + 14,           aDlg[i].Y, 4 /*DT_WORD*/);   //y
      AkelPad.MemCopy(lpItem + 16, Math.abs(aDlg[i].W), 4 /*DT_WORD*/);   //cx
      AkelPad.MemCopy(lpItem + 18, Math.abs(aDlg[i].H), 4 /*DT_WORD*/);   //cy
      AkelPad.MemCopy(lpItem + 20,                   i, 3 /*DT_DWORD*/);  //id
      AkelPad.MemCopy(lpItem + 24,           sCtlClass, 1 /*DT_UNICODE*/);//windowClass
      lpItem += 24 + (sCtlClass.length + 1) * 2;
      AkelPad.MemCopy(lpItem,                sCtlTitle, 1 /*DT_UNICODE*/);//title
      lpItem += (sCtlTitle.length + 1) * 2 + 2;
      lpItem += (4 - lpItem % 4) % 4; //align to DWORD
    }
  }

  if (bTemplate) return lpTemp;

  if (RegisterCallback())
  {
    nResult = oSys.Call(aDlg.Modeless ? "User32::CreateDialogIndirectParamW" : "User32::DialogBoxIndirectParamW",
      AkelPad.GetInstanceDll(),                                     //hInstance
      lpTemp,                                                       //lpTemplate
      aDlg.Parent,                                                  //hWndParent
      CreateDialogBox.Callback[CreateDialogBox.Callback.length - 1],//lpDialogFunc
      aDlg.InitParam);                                              //lParamInit

    if (aDlg.Modeless)
    {
      if (! nResult) UnregisterCallback();
    }
    else
    {
      if ((! nResult) && aDlg.Parent && (! oSys.Call("User32::IsWindow", aDlg.Parent))) nResult = -1;
      if (nResult == -1) UnregisterCallback();
    }
  }

  AkelPad.MemFree(lpTemp);
  return nResult;

  function CreateDialogBoxCallback(hWnd, uMsg, wParam, lParam)
  {
    if (uMsg == 272 /*WM_INITDIALOG*/)
    {
      var lpRectW, lpRectC;
      var nDlgX, nDlgY, nDlgW, nDlgH;
      var nParX, nParY, nParW, nParH;
      var nCtlX, nCtlY, nCtlW, nCtlH;
      var nFX, nFY;
      var i;

      aDlg.HWND = hWnd;

      for (i = nStartID; i <= nEndID; ++i)
      {
        if (aDlg[i]) aDlg[i].HWND = oSys.Call("User32::GetDlgItem", hWnd, i);
      }

      if (oSys.Call("User32::IsMenu", aDlg.Menu)) oSys.Call("User32::SetMenu", hWnd, aDlg.Menu);

      if (aDlg.Icon)
      {
        AkelPad.SendMessage(hWnd, 128 /*WM_SETICON*/, 0 /*ICON_SMALL*/, aDlg.Icon);
        AkelPad.SendMessage(hWnd, 128 /*WM_SETICON*/, 1 /*ICON_BIG*/,   aDlg.Icon);
      }

      if (aDlg.PosPix)
      {
        lpRectW = AkelPad.MemAlloc(16 /*sizeof(RECT)*/);
        lpRectC = AkelPad.MemAlloc(16);

        oSys.Call("User32::GetWindowRect", hWnd, lpRectW);
        oSys.Call("User32::GetClientRect", hWnd, lpRectC);
        nFX = AkelPad.MemRead(lpRectW +  8, 3 /*DT_DWORD*/) - AkelPad.MemRead(lpRectW,     3 /*DT_DWORD*/) - AkelPad.MemRead(lpRectC +  8, 3 /*DT_DWORD*/);
        nFY = AkelPad.MemRead(lpRectW + 12, 3 /*DT_DWORD*/) - AkelPad.MemRead(lpRectW + 4, 3 /*DT_DWORD*/) - AkelPad.MemRead(lpRectC + 12, 3 /*DT_DWORD*/);

        nDlgX = Scale.X(aDlg.X || 0);
        nDlgY = Scale.Y(aDlg.Y || 0);
        nDlgW = Scale.X(aDlg.W || 0);
        nDlgH = Scale.Y(aDlg.H || 0);
        nDlgW += (nDlgW < 0) ? -nFX : nFX;
        nDlgH += (nDlgH < 0) ? -nFY : nFY;

        if (aDlg.PosPar == 1)
          oSys.Call("User32::SystemParametersInfoW", 0x30 /*SPI_GETWORKAREA*/, 0, lpRectW, 0);
        else if ((aDlg.PosPar == 2) && oSys.Call("User32::IsWindow", aDlg.Parent))
          oSys.Call("User32::GetWindowRect", aDlg.Parent, lpRectW);
        else if ((aDlg.PosPar == 3) && oSys.Call("User32::IsWindow", aDlg.Parent))
        {
          oSys.Call("User32::GetClientRect", aDlg.Parent, lpRectW);
          oSys.Call("User32::ClientToScreen", aDlg.Parent, lpRectW);
          oSys.Call("User32::ClientToScreen", aDlg.Parent, lpRectW + 8);
        }
        else if ((aDlg.PosPar == 4) && oSys.Call("User32::IsWindow", aDlg.PosRect))
          oSys.Call("User32::GetWindowRect", aDlg.PosRect, lpRectW);
        else if ((aDlg.PosPar == 5) && oSys.Call("User32::IsWindow", aDlg.PosRect))
        {
          oSys.Call("User32::GetClientRect", aDlg.PosRect, lpRectW);
          oSys.Call("User32::ClientToScreen", aDlg.PosRect, lpRectW);
          oSys.Call("User32::ClientToScreen", aDlg.PosRect, lpRectW + 8);
        }
        else if ((aDlg.PosPar == 6) && aDlg.PosRect)
        {
          for (i = 0; i < 16; i += 4)
            AkelPad.MemCopy(lpRectW + i, AkelPad.MemRead(aDlg.PosRect + i, 3 /*DT_DWORD*/), 3 /*DT_DWORD*/);
        }
        else if ((aDlg.PosPar == 7) && aDlg.PosRect)
        {
          for (i = 0; i < 4; ++i)
            AkelPad.MemCopy(lpRectW + i * 4, aDlg.PosRect[i], 3 /*DT_DWORD*/);
        }
        else if (aDlg.PosPar == 8)
        {
          oSys.Call("User32::GetCursorPos", lpRectW);
          oSys.Call("User32::GetCursorPos", lpRectW + 8);
        }
        else
          oSys.Call("User32::GetWindowRect", oSys.Call("User32::GetDesktopWindow"), lpRectW);

        nParX = AkelPad.MemRead(lpRectW,      3 /*DT_DWORD*/);
        nParY = AkelPad.MemRead(lpRectW +  4, 3 /*DT_DWORD*/);
        nParW = AkelPad.MemRead(lpRectW +  8, 3 /*DT_DWORD*/) - nParX;
        nParH = AkelPad.MemRead(lpRectW + 12, 3 /*DT_DWORD*/) - nParY;
        nDlgX += nParX;
        nDlgY += nParY;

        if (aDlg.PosEdge)
        {
          aDlg.PosEdge = aDlg.PosEdge.toUpperCase();
   
          if (aDlg.PosEdge.charAt(0) == "R")
            nDlgX += nParW;
          else if (aDlg.PosEdge.charAt(0) == "C")
            nDlgX = nParX + (nParW - nDlgW) / 2;
   
          if (aDlg.PosEdge.charAt(1) == "B")
            nDlgY += nParH;
          else if (aDlg.PosEdge.charAt(1) == "C")
            nDlgY = nParY + (nParH - nDlgH) / 2;
        }

        if (nDlgW < 0)
        {
          nDlgW = -nDlgW;
          nDlgX -= nDlgW;
        }
        if (nDlgH < 0)
        {
          nDlgH = -nDlgH;
          nDlgY -= nDlgH;
        }

        oSys.Call("User32::MoveWindow", hWnd, nDlgX, nDlgY, nDlgW, nDlgH, 0);
        oSys.Call("User32::GetClientRect", hWnd, lpRectC);
        nDlgW = AkelPad.MemRead(lpRectC +  8, 3 /*DT_DWORD*/);
        nDlgH = AkelPad.MemRead(lpRectC + 12, 3 /*DT_DWORD*/);

        for (i = nStartID; i <= nEndID; ++i)
        {
          nCtlX = Scale.X(aDlg[i].X || 0);
          nCtlY = Scale.Y(aDlg[i].Y || 0);
          nCtlW = Scale.X(aDlg[i].W || 0);
          nCtlH = Scale.Y(aDlg[i].H || 0);

          if (aDlg[i].PosEdge)
          {
            aDlg[i].PosEdge = aDlg[i].PosEdge.toUpperCase();

            if (aDlg[i].PosEdge.charAt(0) == "R")
              nCtlX += nDlgW;
            else if (aDlg[i].PosEdge.charAt(0) == "C")
              nCtlX = (nDlgW - nCtlW) / 2;

            if (aDlg[i].PosEdge.charAt(1) == "B")
              nCtlY += nDlgH;
            else if (aDlg[i].PosEdge.charAt(1) == "C")
              nCtlY = (nDlgH - nCtlH) / 2;
          }

          if (nCtlW < 0)
          {
            nCtlW = -nCtlW;
            nCtlX -= nCtlW;
          }
          if (nCtlH < 0)
          {
            nCtlH = -nCtlH;
            nCtlY -= nCtlH;
          }

          oSys.Call("User32::MoveWindow", aDlg[i].HWND, nCtlX, nCtlY, nCtlW, nCtlH, 0);
        }

        AkelPad.MemFree(lpRectW);
        AkelPad.MemFree(lpRectC);
      }

      aDlg.Callback(hWnd, uMsg, wParam, lParam);
      if (aDlg.Modeless) AkelPad.WindowRegisterDialog(hWnd); //Register dialog for message loop (modeless dialog created without WindowRegisterClass).

      return 0;
    }

    aDlg.Callback(hWnd, uMsg, wParam, lParam);

    if (uMsg == 2 /*WM_DESTROY*/)
    {
      if (aDlg.Modeless) AkelPad.WindowUnregisterDialog(hWnd);
      UnregisterCallback();
    }

    return 0;
  }

  function RegisterCallback()
  {
    if (! CreateDialogBox.Callback) CreateDialogBox.Callback = [];
    try
    {
      CreateDialogBox.Callback[CreateDialogBox.Callback.length] = oSys.RegisterCallback(CreateDialogBoxCallback);
      return true;
    }
    catch (oError)
    {
      WScript.Echo("Unable to register callback function.");
      return false;
    }
  }

  function UnregisterCallback()
  {
    oSys.UnregisterCallback(CreateDialogBox.Callback[CreateDialogBox.Callback.length - 1]);
    --CreateDialogBox.Callback.length;
  }
}


Last edited by KDJ on Mon May 26, 2014 6:33 pm; edited 3 times in total
Back to top
View user's profile Send private message
KDJ



Joined: 06 Mar 2010
Posts: 1373
Location: Poland

PostPosted: Sun May 04, 2014 7:25 pm    Post subject: Reply with quote

Example of create dialog boxes by using CreateDialogWindow() and CreateDialogBox() functions.
Required to include: CreateDialog_functions.js (in previous post).

CreateDialog_example.js

Code:
// CreateDialog.js - ver. 2014-05-11 (x86/x64)
//
// Example of create dialog boxes by using CreateDialogWindow() and CreateDialogBox() functions
//
// Usage:
// Call("Scripts::Main", 1, "CreateDialog.js")
// Required to include: CreateDialog_functions.js

var oSys   = AkelPad.SystemFunction();
var sClass = "AkelPad::Scripts::" + WScript.ScriptName + "::" + AkelPad.GetInstanceDll();
var hDlg   = oSys.Call("User32::FindWindowW", sClass, 0);

if (hDlg)
{
  if (! oSys.Call("User32::IsWindowVisible", hDlg))
    oSys.Call("User32::ShowWindow", hDlg, 8 /*SW_SHOWNA*/);
  if (oSys.Call("User32::IsIconic", hDlg))
    oSys.Call("User32::ShowWindow", hDlg, 9 /*SW_RESTORE*/);

  oSys.Call("User32::SetForegroundWindow", hDlg);
}
else if (AkelPad.Include("CreateDialog_functions.js"))
{
  var hRichEdLib = oSys.Call("Kernel32::LoadLibraryW", "Msftedit.dll");
  var hIcon      = oSys.Call("User32::LoadImageW", AkelPad.GetInstanceDll(), 101, 1 /*uType=IMAGE_ICON*/, 0, 0, 0x40 /*LR_DEFAULTSIZE*/);
  var nCounter   = 0;
  var IDCANCEL   = 2;
  var IDMENU11   = 1011;
  var IDMENU12   = 1012;
  var IDMENU13   = 1013;
  var IDMENU14   = 1014;
  var IDMENU21   = 1021;
  var IDMENU22   = 1022;
  var IDMENU23   = 1023;
  var IDMENU24   = 1024;
  var IDGROUPB   = 2000;
  var IDCHECKB   = 2001;
  var IDRADIO1   = 2002;
  var IDRADIO2   = 2003;
  var IDBUTTON   = 2004;
  var IDGROUPCB  = 2005;
  var IDCBS1     = 2006;
  var IDCBS2     = 2007;
  var IDCBS3     = 2008;
  var IDCB1      = 2009;
  var IDCB2      = 2010;
  var IDCB3      = 2011;
  var IDGROUPDT  = 2012;
  var IDDT1      = 2013;
  var IDDT2      = 2014;
  var IDDT3      = 2015;
  var IDGROUPE   = 2016;
  var IDE        = 2017;
  var IDRE       = 2018;
  var IDAE       = 2019;
  var IDGROUPLB  = 2020;
  var IDLB       = 2021;
  var IDGROUPLV  = 2022;
  var IDLV       = 2023;
  var IDGROUPMC  = 2024;
  var IDMC       = 2025;
  var IDGROUPTV  = 2026;
  var IDTV       = 2027;
  var IDGROUPLW  = 2028;
  var IDLW       = 2029;
  var IDGROUPTB  = 2030;
  var IDTB       = 2031;
  var IDGROUPUD  = 2032;
  var IDBUDDYUD  = 2033;
  var IDUD       = 2034;
  var IDTC       = 2035;
  var IDGROUPPB  = 2036;
  var IDPB       = 2037;
  var IDSBAR     = 2038;

  if (AkelPad.WindowRegisterClass(sClass))
  {
    //Allow other scripts running
    AkelPad.ScriptNoMutex();

    CreateDialog(false, true, AkelPad.GetMainWnd());
    AkelPad.WindowUnregisterClass(sClass);
  }

  oSys.Call("Kernel32::FreeLibrary", hRichEdLib);
  oSys.Call("user32::DestroyIcon", hIcon);
}

function CreateDialog(bBox, bModeless, hParent)
{
  var nTimerID = ++nCounter;
  var aDlg     = [];
  var nResult;
  var hFocus;

  aDlg.Modeless = bModeless;
  aDlg.Title    = "[" + nTimerID + "] " + (bBox ? "Dialog box " : "Dialog window ") + (bModeless ? "modeless" : "modal");
  aDlg.Style    = WS_VISIBLE | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
  aDlg.Parent   = hParent;
  aDlg.Menu     = CreateMainMenu();
  aDlg.Callback = DialogCallback;
  aDlg.Icon     = hIcon;
  aDlg.X        = 20;
  aDlg.W        = 650;
  aDlg.H        = 432;
  aDlg.PosPar   = 3;
  aDlg.CtlFirst = IDGROUPB;
  aDlg.CtlStyle = WS_VISIBLE;

  if (bBox)
  {
    aDlg.PosPix   = true;
    aDlg.CtlFontN = "MS Shell Dlg";
  }
  else
  {
    aDlg.Class   = sClass;
    aDlg.SizeClt = true;
    aDlg.CtlFont = oSys.Call("Gdi32::GetStockObject", 17 /*DEFAULT_GUI_FONT*/);
  }

  aDlg[IDGROUPB]  = {X:  10, Y:  10, W: 100, H: 125, Title: "Button",     Style: BS_GROUPBOX | BS_CENTER};
  aDlg[IDCHECKB]  = {X:  20, Y:  30, W:  80, H:  16, Title: "CheckBox",   Style: WS_TABSTOP | BS_AUTOCHECKBOX};
  aDlg[IDRADIO1]  = {X:  20, Y:  57, W:  80, H:  16, Title: "Radio1",     Style: WS_TABSTOP | BS_AUTORADIOBUTTON};
  aDlg[IDRADIO2]  = {X:  20, Y:  73, W:  80, H:  16, Title: "Radio2",     Style: WS_TABSTOP | BS_AUTORADIOBUTTON};
  aDlg[IDBUTTON]  = {X:  20, Y: 102, W:  80, H:  23, Title: "PushButton", Style: WS_TABSTOP | BS_PUSHBUTTON};

  aDlg[IDGROUPCB] = {X: 120, Y:  10, W: 190, H: 125, Title: "ComboBox", Style: BS_GROUPBOX | BS_CENTER};
  aDlg[IDCBS1]    = {X: 130, Y:  30, W:  80, H:  13, Title: "Simple",         Class: "STATIC"};
  aDlg[IDCBS2]    = {X: 220, Y:  30, W:  80, H:  13, Title: "Drop-down",      Class: "STATIC"};
  aDlg[IDCBS3]    = {X: 220, Y:  87, W:  80, H:  13, Title: "Drop-down list", Class: "STATIC"};
  aDlg[IDCB1]     = {X: 130, Y:  45, W:  80, H:  82,                         Class: "COMBOBOX", Style: WS_TABSTOP | WS_VSCROLL | CBS_SIMPLE | CBS_NOINTEGRALHEIGHT};
  aDlg[IDCB2]     = {X: 220, Y:  45, W:  80, H: 120,                         Class: "COMBOBOX", Style: WS_TABSTOP | CBS_DROPDOWN};
  aDlg[IDCB3]     = {X: 220, Y: 102, W:  80, H: 120,                         Class: "COMBOBOX", Style: WS_TABSTOP | CBS_DROPDOWNLIST};

  aDlg[IDGROUPDT] = {X: 320, Y:  10, W: 100, H: 125, Title: "DateTimePicker", Style: BS_GROUPBOX | BS_CENTER};
  aDlg[IDDT1]     = {X: 330, Y:  30, W:  80, H:  23, Title: "Edit", Class: "SysDateTimePick32", Style: WS_TABSTOP};
  aDlg[IDDT2]     = {X: 330, Y:  66, W:  80, H:  23, Title: "Edit", Class: "SysDateTimePick32", Style: WS_TABSTOP | DTS_UPDOWN};
  aDlg[IDDT3]     = {X: 330, Y: 102, W:  80, H:  23, Title: "Edit", Class: "SysDateTimePick32", Style: WS_TABSTOP};

  aDlg[IDGROUPE]  = {X: 430, Y:  10, W: 100, H: 125, Title: "Edit", Style: BS_GROUPBOX | BS_CENTER};
  aDlg[IDE]       = {X: 440, Y:  30, W:  80, H:  20, Title: "Edit",     Class: "EDIT",        Style: WS_TABSTOP | WS_BORDER};
  aDlg[IDRE]      = {X: 440, Y:  60, W:  80, H:  20, Title: "RichEdit", Class: "RichEdit50W", Style: WS_TABSTOP | WS_BORDER};
  aDlg[IDAE]      = {X: 440, Y:  90, W:  80, H:  35,                   Class: "AkelEditW",   Style: WS_TABSTOP | WS_BORDER | ES_MULTILINE | ES_WANTRETURN};

  aDlg[IDGROUPLB] = {X: 540, Y:  10, W: 100, H: 125, Title: "ListBox", Style: BS_GROUPBOX | BS_CENTER};
  aDlg[IDLB]      = {X: 550, Y:  30, W:  80, H:  95, Class: "LISTBOX", Style: WS_TABSTOP | WS_VSCROLL | WS_BORDER | LBS_NOINTEGRALHEIGHT};

  aDlg[IDGROUPLV] = {X:  10, Y: 145, W: 130, H: 185, Title: "ListView", Style: BS_GROUPBOX | BS_CENTER};
  aDlg[IDLV]      = {X:  20, Y: 165, W: 110, H: 155, Class: "SysListView32", Style: WS_TABSTOP | WS_BORDER | LVS_REPORT | LVS_SHOWSELALWAYS};

  aDlg[IDGROUPMC] = {X: 150, Y: 145, W: 190, H: 185, Title: "MonthCalendar", Style: BS_GROUPBOX | BS_CENTER};
  aDlg[IDMC]      = {X: 160, Y: 165, W: 170, H: 155, Class: "SysMonthCal32", Style: WS_TABSTOP | WS_BORDER};

  aDlg[IDGROUPTV] = {X: 350, Y: 145, W: 150, H: 185, Title: "TreeView", Style: BS_GROUPBOX | BS_CENTER};
  aDlg[IDTV]      = {X: 360, Y: 165, W: 130, H: 155, Class: "SysTreeView32", Style: WS_TABSTOP | WS_BORDER | TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT};

  aDlg[IDGROUPLW] = {X: 510, Y: 145, W: 130, H:  45, Title: "SysLink", Style: BS_GROUPBOX | BS_CENTER};
  aDlg[IDLW]      = {X: 520, Y: 165, W: 110, H:  16, Title: "<a>Show/hide main menu</a>", Class: "SysLink"};

  aDlg[IDGROUPTB] = {X: 510, Y: 200, W: 130, H:  60, Title: "TrackBar", Style: BS_GROUPBOX | BS_CENTER};
  aDlg[IDTB]      = {X: 520, Y: 220, W: 110, H:  30, Class: "msctls_trackbar32", Style: WS_TABSTOP | TBS_AUTOTICKS};

  aDlg[IDGROUPUD] = {X: 510, Y: 270, W: 130, H:  60, Title: "Up-Down", Style: BS_GROUPBOX | BS_CENTER};
  aDlg[IDBUDDYUD] = {X: 550, Y: 295, W:  50, H:  20, Class: "EDIT", Style: WS_TABSTOP | ES_NUMBER, ExStyle: WS_EX_CLIENTEDGE};
  aDlg[IDUD]      = {                                Class: "msctls_updown32", Style: UDS_ALIGNRIGHT | UDS_ARROWKEYS | UDS_SETBUDDYINT};

  aDlg[IDTC]      = {X:  10, Y: 345, W: 490, H:  55, Class: "SysTabControl32", Style: WS_TABSTOP | TCS_FIXEDWIDTH | TCS_FOCUSONBUTTONDOWN};

  aDlg[IDGROUPPB] = {X: 510, Y: 340, W: 130, H:  60, Title: "ProgressBar", Style: BS_GROUPBOX | BS_CENTER};
  aDlg[IDPB]      = {X: 520, Y: 365, W: 110, H:  20, Class: "msctls_progress32"};

  aDlg[IDSBAR]    = {Class: "msctls_statusbar32"};

  if (bBox)
  {
    if (bModeless)
    {
      if (CreateDialogBox(aDlg))
      {
        if (nTimerID == 1)
          AkelPad.WindowGetMessage(0x2 /*WGM_NOKEYSEND*/);
      }
      else
        oSys.Call("User32::DestroyMenu", aDlg.Menu);
    }
    else
    {
      nResult = CreateDialogBox(aDlg);
      if (nResult == -1)
        oSys.Call("User32::DestroyMenu", aDlg.Menu);
    }
  }
  else
  {
    if (CreateDialogWindow(aDlg, 1))
    {
      if (! bModeless)
        oSys.Call("user32::EnableWindow", aDlg.Parent, 0);
      if (nTimerID == 1)
        AkelPad.WindowGetMessage(0x2 /*WGM_NOKEYSEND*/);
    }
    else
      oSys.Call("User32::DestroyMenu", aDlg.Menu);
  }

  function DialogCallback(hWnd, uMsg, wParam, lParam)
  {
    if (uMsg == 1 /*WM_CREATE*/)
    {
      aDlg.HWND = hWnd;
      CreateDialogWindow(aDlg, 2, hWnd);
      InitDialog();
      hFocus = aDlg[IDCHECKB].HWND;
    }

    else if (uMsg == 272 /*WM_INITDIALOG*/)
      InitDialog();

    else if ((uMsg == 6 /*WM_ACTIVATE*/) && (wParam == 0 /*WA_INACTIVE*/) && (! bBox))
      hFocus = oSys.Call("User32::GetFocus");
 
    else if ((uMsg == 7 /*WM_SETFOCUS*/) && (! bBox))
      oSys.Call("User32::SetFocus", hFocus);

    else if (uMsg == 5 /*WM_SIZE*/)
      AkelPad.SendMessage(aDlg[IDSBAR].HWND, 5 /*WM_SIZE*/, 0, 0);

    if (uMsg == 78 /*WM_NOTIFY*/)
    {
      if (AkelPad.MemRead(lParam + (_X64 ? 16 : 8), 3 /*DT_DWORD*/) == -2 /*NM_CLICK*/)
      {
        if (wParam == IDLW)
        {
          oSys.Call("User32::SetMenu", hWnd, oSys.Call("User32::GetMenu", hWnd) ? 0 : aDlg.Menu);
          AkelPad.SendMessage(aDlg[IDSBAR].HWND, 5 /*WM_SIZE*/, 0, 0);
        }
      }
    }

    else if (uMsg == 273 /*WM_COMMAND*/)
    {
      var nLowParam = LoWord(wParam);

      if (nLowParam == IDBUTTON)
        AkelPad.MessageBox(hWnd, '"PushButton" has been pressed.', aDlg.Title, 0x40 /*MB_ICONINFORMATION*/);
      else if (nLowParam == IDMENU11)
        CreateDialog(false, false, hWnd);
      else if (nLowParam == IDMENU12)
        CreateDialog(false, true, hWnd);
      else if (nLowParam == IDMENU13)
        CreateDialog(true, false, hWnd);
      else if (nLowParam == IDMENU14)
        CreateDialog(true, true, hWnd);
      else if ((nLowParam >= IDMENU21) && (nLowParam <= IDMENU24))
        AkelPad.MessageBox(hWnd, "Command: " + nLowParam, aDlg.Title, 0x40 /*MB_ICONINFORMATION*/);
      else if (nLowParam == IDCANCEL)
        oSys.Call("User32::PostMessageW", hWnd, 16 /*WM_CLOSE*/, nLowParam, 0);
    }

    else if (uMsg == 275 /*WM_TIMER*/)
    {
      AkelPad.SendMessage(aDlg[IDPB].HWND, 1029 /*PBM_STEPIT*/, 0, 0);
      SetTextSBAR(AkelPad.SendMessage(aDlg[IDPB].HWND, 1032 /*PBM_GETPOS*/, 0, 0));
    }

    else if (uMsg == 16 /*WM_CLOSE*/)
    {
      if ((! bBox) && (! bModeless))
      {
        oSys.Call("user32::EnableWindow", aDlg.Parent, 1);
        oSys.Call("User32::SetForegroundWindow", aDlg.Parent);
      }

      AkelPad.WindowUnsubClass(aDlg[IDRE].HWND);
      oSys.Call("User32::KillTimer", hWnd, nTimerID);

      if (bBox && (! bModeless))
        oSys.Call("User32::EndDialog", hWnd, wParam);
      else
        oSys.Call("User32::DestroyWindow", hWnd);
    }

    else if (uMsg == 2 /*WM_DESTROY*/)
    {
      oSys.Call("User32::DestroyMenu", aDlg.Menu);
      if (nTimerID == 1)
        oSys.Call("User32::PostQuitMessage", 0);
    }

    return 0;
  }

  function InitDialog()
  {
    var i;

    //Button
    AkelPad.SendMessage(aDlg[IDCHECKB].HWND, 241 /*BM_SETCHECK*/, 1 /*BST_CHECKED*/, 0);
    AkelPad.SendMessage(aDlg[IDRADIO1].HWND, 241 /*BM_SETCHECK*/, 0 /*BST_UNCHECKED*/, 0);
    AkelPad.SendMessage(aDlg[IDRADIO2].HWND, 241 /*BM_SETCHECK*/, 1 /*BST_CHECKED*/, 0);

    //ComboBox
    for (i = 0; i < 15; ++i) AkelPad.SendMessage(aDlg[IDCB1].HWND, 323 /*CB_ADDSTRING*/, 0, "Item " + i);
    for (i = 0; i < 15; ++i) AkelPad.SendMessage(aDlg[IDCB2].HWND, 323 /*CB_ADDSTRING*/, 0, "Item " + i);
    for (i = 0; i < 15; ++i) AkelPad.SendMessage(aDlg[IDCB3].HWND, 323 /*CB_ADDSTRING*/, 0, "Item " + i);
    AkelPad.SendMessage(aDlg[IDCB1].HWND, 334 /*CB_SETCURSEL*/, 4, 0);
    AkelPad.SendMessage(aDlg[IDCB2].HWND, 334 /*CB_SETCURSEL*/, 2, 0);
    AkelPad.SendMessage(aDlg[IDCB3].HWND, 334 /*CB_SETCURSEL*/, 6, 0);

    //DateTimePicker
    AkelPad.SendMessage(aDlg[IDDT3].HWND, 4146 /*DTM_SETFORMATW*/, 0, "ddd HH:mm");

    //Edit
    AkelPad.WindowSubClass(aDlg[IDRE].HWND, RichEditCallback, 258 /*WM_CHAR*/);
    oSys.Call("User32::SetWindowTextW", aDlg[IDAE].HWND, "AkelEdit\nmultiline");

    //ListBox
    for (i = 0; i < 20; ++i) AkelPad.SendMessage(aDlg[IDLB].HWND, 384 /*LB_ADDSTRING*/, 0, "Item " + i);
    AkelPad.SendMessage(aDlg[IDLB].HWND, 390 /*LB_SETCURSEL*/, 9, 0);

    //ListView
    FillLV();

    //TreeView
    FillTV();

    //TrackBar
    AkelPad.SendMessage(aDlg[IDTB].HWND, 1044 /*TBM_SETTICFREQE*/, 10, 0);

    //Up-Down
    AkelPad.SendMessage(aDlg[IDUD].HWND, 1129 /*UDM_SETBUDDY*/, aDlg[IDBUDDYUD].HWND, 0);
    AkelPad.SendMessage(aDlg[IDUD].HWND, 1135 /*UDM_SETRANGE32*/, 1, 100);
    AkelPad.SendMessage(aDlg[IDUD].HWND, 1137 /*UDM_SETPOS32*/, 0, 50);

    //Tab
    FillTC();

    //ProgressBar
    AkelPad.SendMessage(aDlg[IDPB].HWND, 1028 /*PBM_SETSTEP*/, 1, 0);
    oSys.Call("User32::SetTimer", aDlg.HWND, nTimerID, 200, 0);

    //StatusBar
    SetPartsSBAR();
    SetTextSBAR(0);
  }

  function RichEditCallback(hWnd, uMsg, wParam, lParam)
  {
    if (uMsg == 258) //WM_CHAR
    {
      if (wParam == 0x09 /*VK_TAB*/)
        oSys.Call("User32::SetFocus", oSys.Call("User32::GetNextDlgTabItem", aDlg.HWND, hWnd, Shift()));
    }

    return 0;
  }

  function FillLV()
  {
    var nBufSize   = 64;
    var lpText     = AkelPad.MemAlloc(nBufSize);
    var lpLVITEM   = AkelPad.MemAlloc(_X64 ? 72 : 60 /*sizeof(LVITEM)*/);
    var lpLVCOLUMN = AkelPad.MemAlloc(_X64 ? 56 : 44 /*sizeof(LVCOLUMN)*/);
    var i;

    AkelPad.MemCopy(lpText, "Name", 1 /*DT_UNICODE*/);
    AkelPad.MemCopy(lpLVCOLUMN, 5 /*LVCF_FMT|LVCF_TEXT*/, 3 /*DT_DWORD*/);  //mask
    AkelPad.MemCopy(lpLVCOLUMN + (_X64 ? 16 : 12), lpText, 2 /*DT_QWORD*/); //pszText
    AkelPad.SendMessage(aDlg[IDLV].HWND, 4193 /*LVM_INSERTCOLUMNW*/, 0, lpLVCOLUMN);

    AkelPad.MemCopy(lpText, "Value", 1 /*DT_UNICODE*/);
    AkelPad.MemCopy(lpLVCOLUMN + 4, 1 /*LVCFMT_RIGHT*/, 3 /*DT_DWORD*/); //fmt
    AkelPad.SendMessage(aDlg[IDLV].HWND, 4193 /*LVM_INSERTCOLUMNW*/, 1, lpLVCOLUMN);

    AkelPad.MemCopy(lpLVITEM, 1 /*LVIF_TEXT*/, 3 /*DT_DWORD*/);             //mask
    AkelPad.MemCopy(lpLVITEM + (_X64 ? 24 : 20), lpText, 2 /*DT_QWORD*/);   //pszText
    AkelPad.MemCopy(lpLVITEM + (_X64 ? 32 : 24), nBufSize, 3 /*DT_DWORD*/); //cchTextMax

    for (i = 0; i < 25; ++i)
    {
      AkelPad.MemCopy(lpText, "Item " + i, 1 /*DT_UNICODE*/);
      AkelPad.MemCopy(lpLVITEM + 4, i, 3 /*DT_DWORD*/); //iItem
      AkelPad.MemCopy(lpLVITEM + 8, 0, 3 /*DT_DWORD*/); //iSubItem
      AkelPad.SendMessage(aDlg[IDLV].HWND, 4173 /*LVM_INSERTITEMW*/, 0, lpLVITEM);

      AkelPad.MemCopy(lpText, (i * i + 99).toString(), 1 /*DT_UNICODE*/);
      AkelPad.MemCopy(lpLVITEM + 8, 1, 3 /*DT_DWORD*/); //iSubItem
      AkelPad.SendMessage(aDlg[IDLV].HWND, 4212 /*LVM_SETITEMTEXTW*/, i, lpLVITEM);
    }

    AkelPad.SendMessage(aDlg[IDLV].HWND, 4126 /*LVM_SETCOLUMNWIDTH*/, 0, -2 /*LVSCW_AUTOSIZE_USEHEADER*/);
    AkelPad.SendMessage(aDlg[IDLV].HWND, 4126 /*LVM_SETCOLUMNWIDTH*/, 1, -2 /*LVSCW_AUTOSIZE_USEHEADER*/);
    AkelPad.SendMessage(aDlg[IDLV].HWND, 4150 /*LVM_SETEXTENDEDLISTVIEWSTYLE*/, 0x20 /*LVS_EX_FULLROWSELECT*/, 0x20);

    AkelPad.MemCopy(lpLVITEM + 12, 3 /*LVIS_SELECTED|LVIS_FOCUSED*/, 3 /*DT_DWORD*/); //state
    AkelPad.MemCopy(lpLVITEM + 16, 3 /*LVIS_SELECTED|LVIS_FOCUSED*/, 3 /*DT_DWORD*/); //stateMask
    AkelPad.SendMessage(aDlg[IDLV].HWND, 4139 /*LVM_SETITEMSTATE*/, 7, lpLVITEM);
    AkelPad.SendMessage(aDlg[IDLV].HWND, 4115 /*LVM_ENSUREVISIBLE*/, 7, false);

    AkelPad.MemFree(lpText);
    AkelPad.MemFree(lpLVITEM);
    AkelPad.MemFree(lpLVCOLUMN);
  }

  function FillTV()
  {
    var nBufSize   = 64;
    var lpText     = AkelPad.MemAlloc(nBufSize);
    var lpTVINSERT = AkelPad.MemAlloc(_X64 ? 72 : 48 /*sizeof(TVINSERTSTRUCT)*/);
    var hRoot;
    var hChild;
    var i, n;

    AkelPad.MemCopy(lpText, "Root", 1 /*DT_UNICODE*/);
    AkelPad.MemCopy(lpTVINSERT + (_X64 ? 16 :  8), 0x41 /*TVIF_CHILDREN|TVIF_TEXT*/, 3 /*DT_DWORD*/); //mask
    AkelPad.MemCopy(lpTVINSERT + (_X64 ? 40 : 24), lpText, 2 /*DT_QWORD*/);                           //pszText
    AkelPad.MemCopy(lpTVINSERT + (_X64 ? 48 : 28), nBufSize, 3 /*DT_DWORD*/);                         //cchTextMax
    AkelPad.MemCopy(lpTVINSERT + (_X64 ? 60 : 40), 1, 3 /*DT_DWORD*/);                                //cChildren
    hRoot = AkelPad.SendMessage(aDlg[IDTV].HWND, 4402 /*TVM_INSERTITEMW*/, 0, lpTVINSERT);

    for (i = 1; i < 10; ++i)
    {
      AkelPad.MemCopy(lpText, "Child-" + i, 1 /*DT_UNICODE*/);
      AkelPad.MemCopy(lpTVINSERT, hRoot, 2 /*DT_QWORD*/);                                    //hParent
      AkelPad.MemCopy(lpTVINSERT + (_X64 ? 8 : 4), 0xFFFF0002 /*TVI_LAST*/, 2 /*DT_QWORD*/); //hInsertAfter
      AkelPad.MemCopy(lpTVINSERT + (_X64 ? 60 : 40), 1, 3 /*DT_DWORD*/);                     //cChildren
      hChild = AkelPad.SendMessage(aDlg[IDTV].HWND, 4402 /*TVM_INSERTITEMW*/, 0, lpTVINSERT);

      for (n = 1; n < 4; ++n)
      {
        AkelPad.MemCopy(lpText, "Child-" + i + "-" + n, 1 /*DT_UNICODE*/);
        AkelPad.MemCopy(lpTVINSERT, hChild, 2 /*DT_QWORD*/);                                   //hParent
        AkelPad.MemCopy(lpTVINSERT + (_X64 ? 8 : 4), 0xFFFF0002 /*TVI_LAST*/, 2 /*DT_QWORD*/); //hInsertAfter
        AkelPad.MemCopy(lpTVINSERT + (_X64 ? 60 : 40), 0, 3 /*DT_DWORD*/);                     //cChildren
        AkelPad.SendMessage(aDlg[IDTV].HWND, 4402 /*TVM_INSERTITEMW*/, 0, lpTVINSERT);
      }
    }

    AkelPad.SendMessage(aDlg[IDTV].HWND, 4354 /*TVM_EXPAND*/, 2 /*TVE_EXPAND*/, hRoot);

    AkelPad.MemFree(lpText);
    AkelPad.MemFree(lpTVINSERT);
  }

  function FillTC()
  {
    var lpText   = AkelPad.MemAlloc(64);
    var lpTCITEM = AkelPad.MemAlloc(_X64 ? 40 : 28 /*sizeof(TCITEM)*/);
    var i;

    AkelPad.MemCopy(lpTCITEM, 1 /*TCIF_TEXT*/, 3 /*DT_DWORD*/); //mask
    AkelPad.MemCopy(lpTCITEM + (_X64 ? 16 : 12), lpText, 2 /*DT_QWORD*/); //pszText

    for (i = 0; i <= 7; ++i)
    {
      AkelPad.MemCopy(lpText, "Tab " + i, 1 /*DT_UNICODE*/);
      AkelPad.SendMessage(aDlg[IDTC].HWND, 4926 /*TCM_INSERTITEMW*/, i, lpTCITEM);
    }

    AkelPad.SendMessage(aDlg[IDTC].HWND, 4905 /*TCM_SETITEMSIZE*/, 0, MkLong(60, 20));
    AkelPad.SendMessage(aDlg[IDTC].HWND, 4876 /*TCM_SETCURSEL*/, 1, 0);

    AkelPad.MemFree(lpText);
    AkelPad.MemFree(lpTCITEM);
  }

  function SetPartsSBAR()
  {
    var lpParts = AkelPad.MemAlloc(3 * 4 /*sizeof(int)*/);

    AkelPad.MemCopy(lpParts,      Scale.X(80), 3 /*DT_DWORD*/);
    AkelPad.MemCopy(lpParts + 4, Scale.X(160), 3 /*DT_DWORD*/);
    AkelPad.MemCopy(lpParts + 8,           -1, 3 /*DT_DWORD*/);

    AkelPad.SendMessage(aDlg[IDSBAR].HWND, 1028 /*SB_SETPARTS*/, 3, lpParts);
    AkelPad.SendMessage(aDlg[IDSBAR].HWND, 5 /*WM_SIZE*/, 0, 0);

    AkelPad.MemFree(lpParts);
  }

  function SetTextSBAR(nProgress)
  {
    AkelPad.SendMessage(aDlg[IDSBAR].HWND, 1035 /*SB_SETTEXTW*/, 0, "\tStatusBar");
    AkelPad.SendMessage(aDlg[IDSBAR].HWND, 1035 /*SB_SETTEXTW*/, 1, "Progress: " + nProgress + "%");
    AkelPad.SendMessage(aDlg[IDSBAR].HWND, 1035 /*SB_SETTEXTW*/, 2, "\t\t" + (new Date()).toLocaleString());
  }
}

function LoWord(nDwNum)
{
  return nDwNum & 0xFFFF;
}

function MkLong(nLoWord, nHiWord)
{
  return (nLoWord & 0xFFFF) | (nHiWord << 16);
}

function Shift()
{
  return Boolean(oSys.Call("User32::GetKeyState", 0x10 /*VK_SHIFT*/) & 0x8000);
}

function CreateMainMenu()
{
  var MF_STRING = 0x0000;
  var MF_POPUP  = 0x0010;
  var hMenu  = oSys.Call("User32::CreateMenu");
  var hMenu1 = oSys.Call("User32::CreatePopupMenu");
  var hMenu2 = oSys.Call("User32::CreatePopupMenu");
  var i;

  oSys.Call("User32::AppendMenuW", hMenu, MF_POPUP, hMenu1, "&New");
  oSys.Call("User32::AppendMenuW", hMenu, MF_POPUP, hMenu2, "&Other");
  oSys.Call("User32::AppendMenuW", hMenu, MF_STRING, IDCANCEL, "E&xit");

  oSys.Call("User32::AppendMenuW", hMenu1, MF_STRING, IDMENU11, "&1 - Dialog window modal");
  oSys.Call("User32::AppendMenuW", hMenu1, MF_STRING, IDMENU12, "&2 - Dialog window modeless");
  oSys.Call("User32::AppendMenuW", hMenu1, MF_STRING, IDMENU13, "&3 - Dialog box modal");
  oSys.Call("User32::AppendMenuW", hMenu1, MF_STRING, IDMENU14, "&4 - Dialog box modeless");

  for (i = IDMENU21; i <= IDMENU24; ++i)
    oSys.Call("User32::AppendMenuW", hMenu2, MF_STRING, i, "Command " + i);

  return hMenu;
}
Back to top
View user's profile Send private message
KDJ



Joined: 06 Mar 2010
Posts: 1373
Location: Poland

PostPosted: Sat May 17, 2014 3:05 pm    Post subject: Reply with quote

Restart AkelPad without using additional tools.
The similar script: restart.js written by Infocatcher.

AkelPadRestart.js

Code:
// AkelPadRestart.js - ver. 2014-05-24 (x86/x64)
//
// Restart AkelPad without using additional tools.
//
// Usage:
// Call("Scripts::Main", 1, "AkelPadRestart.js")

if (typeof AkelPad == "object")
{
  if (WScript.Arguments.length != 2)
    CloseAkelPad();
  else
    OpenFiles(WScript.Arguments(0), parseInt(WScript.Arguments(1)));
}
else if (WScript.Arguments.length == 4)
  RunAkelPad(WScript.Arguments(0), WScript.Arguments(1), parseInt(WScript.Arguments(2)), parseInt(WScript.Arguments(3)));

function CloseAkelPad()
{
  var oFSO        = new ActiveXObject("Scripting.FileSystemObject");
  var sWinDir     = new ActiveXObject("WScript.Shell").ExpandEnvironmentStrings("%WinDir%");
  var sWscriptExe = sWinDir + "\\Sysnative\\wscript.exe";
  var hMainWnd    = AkelPad.GetMainWnd();
  var nMDI        = AkelPad.IsMDI();
  var nPID        = AkelPad.SystemFunction().Call("Kernel32::GetCurrentProcessId");
  var MAX_PATH    = 260;
  var lpBuffer    = AkelPad.MemAlloc(MAX_PATH * _TSIZE);
  var sAkelExe;
  var nTabs;
  var i;

  GetLangStrings();

  //on Win7 x64 no file %WinDir%\SysWOW64\qprocess.exe, therefore if AkelPd is 32bit, we run wscript.exe x64
  if (! oFSO.FileExists(sWscriptExe))
    sWscriptExe = sWinDir + "\\System32\\wscript.exe";

  AkelPad.SystemFunction().Call("Kernel32::GetModuleFileName" + _TCHAR, 0, lpBuffer, MAX_PATH);
  sAkelExe = AkelPad.MemRead(lpBuffer, _TSTR)
  AkelPad.MemFree(lpBuffer);

  if (AkelPad.GetEditModified(0) || AkelPad.SendMessage(hMainWnd, 1291 /*AKD_FRAMESTATS*/, 1 /*FWS_COUNTMODIFIED*/, 0))
  {
    switch (AkelPad.MessageBox(hMainWnd, sTxtSaveAll, WScript.ScriptBaseName, 0x23 /*MB_ICONQUESTION|MB_YESNOCANCEL*/))
    {
      case 6 /*IDYES*/:
        if (! AkelPad.Command(nMDI ? 4110 /*IDM_FILE_SAVEALL*/ : 4105 /*IDM_FILE_SAVE*/)) return;
        break;
      case 7 /*IDNO*/:
        if (nMDI)
        {
          nTabs = AkelPad.SendMessage(hMainWnd, 1291 /*AKD_FRAMESTATS*/, 0 /*FWS_COUNTALL*/, 0);
          for (i = 0; i < nTabs; ++i)
            AkelPad.SendMessage(hMainWnd, 1229 /*AKD_SETMODIFY*/, AkelPad.SendMessage(hMainWnd, 1223 /*AKD_GETFRAMEINFO*/, 2 /*FI_WNDEDIT*/, AkelPad.SendMessage(hMainWnd, 1288 /*AKD_FRAMEFIND*/, 8 /*FWF_BYTABINDEX*/, i)), 0);
        }
        else
          AkelPad.SendMessage(hMainWnd, 1229 /*AKD_SETMODIFY*/, 0, 0);
        break;
      case 2 /*IDCANCEL*/:
        return;
    }
  }

  if (nMDI)
  {
    if (oFSO.FileExists(AkelPad.GetAkelDir(4 /*ADTYPE_PLUGS*/) + "\\Sessions.dll"))
    {
      AkelPad.Call("Sessions::Main", 2, "OnExit");
      if (AkelPad.IsPluginRunning("Sessions::Main"))
        AkelPad.Call("Sessions::Main", 10); //stop plugin
    }
    else if (AkelPad.SendMessage(hMainWnd, 1291 /*AKD_FRAMESTATS*/, 0 /*FWS_COUNTALL*/, 0) > 1)
      AkelPad.MessageBox(hMainWnd, sTxtToRestore, WScript.ScriptBaseName, 0x30 /*MB_ICONWARNING*/);
  }

  if (AkelPad.IsPluginRunning("Exit::Main"))
    AkelPad.Call("Exit::Main"); //stop plugin

  AkelPad.Exec('"' + sWscriptExe + '" "' + WScript.ScriptFullName + '" "' + sAkelExe + '" "' + AkelPad.GetEditFile(0) + '" ' + nMDI + ' ' + nPID);
  AkelPad.Command(4109 /*IDM_FILE_EXIT*/);
}

function RunAkelPad(sAkelExe, sEditFile, nMDI, nPID)
{
  var oWshShell = new ActiveXObject("WScript.Shell");

  while (! oWshShell.Run('qprocess.exe ' + nPID, 0 /*hide cmd window*/, 1 /*return errorlevel*/))
    WScript.Sleep(20);

  oWshShell.Run('"' + sAkelExe + '" /Call("Scripts::Main",1,"' + WScript.ScriptName + '",`"' + sEditFile + '" ' + nMDI + '`)');
}

function OpenFiles(sEditFile, nMDI)
{
  if (nMDI && AkelPad.IsMDI() && (new ActiveXObject("Scripting.FileSystemObject").FileExists(AkelPad.GetAkelDir(4 /*ADTYPE_PLUGS*/) + "\\Sessions.dll")))
    AkelPad.Call("Sessions::Main", 1, "OnExit");
  else if (sEditFile)
    AkelPad.OpenFile(sEditFile, 0x002 /*OD_ADT_REG_CODEPAGE*/);
}

function GetLangStrings()
{
  if (AkelPad.GetLangId(0 /*LANGID_FULL*/) == 1045 /*Polish*/)
  {
    sTxtSaveAll   = "Czy zapisać wszystkie zmienione dokumenty przed restartem?";
    sTxtToRestore = "Żeby przywrócić wszystkie karty po restarcie, pownieneś zainstalować wtyczkę Sessions.";
  }
//  else if (AkelPad.GetLangId(0 /*LANGID_FULL*/) == 1049 /*Russian*/)
//  {
//  }
  else
  {
    sTxtSaveAll   = "Save all modified documents before restart?";
    sTxtToRestore = "To restore all tabs after restart, you should install Sessions plugin.";
  }
}
Back to top
View user's profile Send private message
KDJ



Joined: 06 Mar 2010
Posts: 1373
Location: Poland

PostPosted: Mon Jul 28, 2014 12:25 am    Post subject: Reply with quote

TextMarker.js was moved to: http://akelpad.sourceforge.net/forum/viewtopic.php?p=25700&highlight=#25700

Last edited by KDJ on Mon Sep 01, 2014 8:27 pm; edited 7 times in total
Back to top
View user's profile Send private message
DV



Joined: 16 Nov 2006
Posts: 847
Location: Kyiv, Ukraine

PostPosted: Mon Jul 28, 2014 2:40 pm    Post subject: Reply with quote

Немного обновлённый скрипт для гурманов Smile
ZipCurrentFile.js
Code:
// Usage:
//   Call("Scripts::Main", 1, "ZipCurrentFile.js")
//   Call("Scripts::Main", 1, "ZipCurrentFile.js", "-OutDir=%TEMP%")
//   Call("Scripts::Main", 1, "ZipCurrentFile.js", '-OutDir="C:\\Program Files"');

var sOutDir = AkelPad.GetArgValue("OutDir", "");
var isFileSaved = false;
var sCurrentFilePath = AkelPad.GetEditFile(0);
if (sCurrentFilePath)
{
  if (!AkelPad.GetEditModified(0))
    isFileSaved = true;
}
if (!isFileSaved)
{
  WScript.Echo("File is not saved. Please save the file first!");
  WScript.Quit();
}

var sZipFilePath = getZipFilePath(sCurrentFilePath);
if (!zip_create(sZipFilePath))
{
  WScript.Echo("Failed to create the archive :(");
  WScript.Quit();
}
if (!zip_add_file(sZipFilePath, sCurrentFilePath))
{
  WScript.Echo("Failed to add the file to the archive :(");
  WScript.Quit();
}
WScript.Echo("Archive created!\n" + sZipFilePath);

function getZipFilePath(sCurrentFilePath)
{
  var sZipFileDir;

  if (sOutDir != "")
  {
    var oWScript = new ActiveXObject("WScript.Shell");
    var oFileSystem = new ActiveXObject("Scripting.FileSystemObject");
    sZipFileDir = oWScript.ExpandEnvironmentStrings(sOutDir);
    if (!oFileSystem.FolderExists(sZipFileDir))
    {
      WScript.Echo("Directory does not exist: " + sZipFileDir);
      WScript.Quit();
    }
  }
  else
  {
    sZipFileDir = getFileDir(sCurrentFilePath);
  }

  var sZipFileName = getFileName(sCurrentFilePath);
  var s = sZipFileDir + "\\" + sZipFileName + ".zip";
  return s;
}

function zip_create(sZipFilePath)
{
  var isOK = false;

  // Creating an empty .zip archive
  try
  {
    var oFileSystem = new ActiveXObject("Scripting.FileSystemObject");
    var oZipFile = oFileSystem.OpenTextFile(sZipFilePath, 2, true);
    var data = String.fromCharCode(80,75,5,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
    oZipFile.Write(data);
    oZipFile.Close();
    isOK = true;
  }
  catch (err)
  {
    // ...
  }

  return isOK;
}

function zip_add_file(sZipFilePath, sFilePath)
{
  var isOK = false;

  // Packing the data
  try
  {
    var oShell = new ActiveXObject("Shell.Application");
    var oDstFolder = oShell.NameSpace(sZipFilePath);
    oDstFolder.CopyHere(sFilePath, 16);
    //WScript.Sleep(1000);
    isOK = true;
  }
  catch (err)
  {
    // ...
  }

  return isOK;
}

function zip_add_folder(sZipFilePath, sFolderPath)
{
  var isOK = false;

  // Packing the data
  try
  {
    var oShell = new ActiveXObject("Shell.Application");
    var oDstFolder = oShell.NameSpace(sZipFilePath);
    var oSrcFolder = oShell.NameSpace(sFolderPath);
    var oFolderItems = oSrcFolder.Items();
    oDstFolder.CopyHere(oFolderItems.Item(), 16);
    //WScript.Sleep(1000);
    isOK = true;
  }
  catch (err)
  {
    // ...
  }

  return isOK;
}

function getFileExt(filePathName) // file extension w/o leading '.'
{
  var n = filePathName.lastIndexOf(".");
  return (n >= 0) ? filePathName.substr(n + 1) : "";
}

function getFileName(filePathName) // file name w/o extension
{
  var n2 = filePathName.lastIndexOf(".");
  var n1 = filePathName.lastIndexOf("\\");
  var nn = filePathName.lastIndexOf("/");
  if (nn > n1)  n1 = nn;
  var s = "";
  if (n1 < 0 && n2 < 0)
    s = filePathName;
  else if (n1 < 0)
    s = filePathName.substr(0, n2);
  else if (n2 < 0)
    s = filePathName.substr(n1 + 1);
  else if (n2 > n1)
    s = filePathName.substr(n1 + 1, n2 - n1 - 1);
  return s;
}

function getFileDir(filePathName) // file directory w/o trailing '\'
{
  var n = filePathName.lastIndexOf("\\");
  var nn = filePathName.lastIndexOf("/");
  if (nn > n)  n = nn;
  return (n >= 0) ? filePathName.substr(0, n) : filePathName;
}
Back to top
View user's profile Send private message
KDJ



Joined: 06 Mar 2010
Posts: 1373
Location: Poland

PostPosted: Sun Aug 10, 2014 6:36 pm    Post subject: Reply with quote

Set font in AkelPad tabs (MDI/PMDI).

Required to include: ChooseFont_function.js
Download all: KDJ.zip

TabFont.js

Code:
// TabFont.js - ver. 2014-08-13 (x86/x64)
//
// Set font in AkelPad tabs (MDI/PMDI).
//
// Usage:
//   Call("Scripts::Main", 1, "TabFont.js", `"sFont" nStyle nSize`)
// Required to include: ChooseFont_function.js
//
// Arguments:
//   "sFont":
//     Font face name, for example "Courier New", if "" - unchanged
//     Or it may be (in this case, arguments nStyle and nSize are ignored):
//       "0" - default GUI font
//       "1" - system font
//       "2" - AkelPad edit font
//       "8" - font that was previously set by this script (saved in TabFont.ini)
//       "9" - Choose Font dialog box
//       "+" - increase font size
//       "-" - decrease font size
//   nStyle:
//     0 - unchanged
//     1 - normal
//     2 - bold
//     3 - italic
//     4 - bold italic
//   nSize:
//     Font size in points, if 0 - unchanged
//
// Examples:
//   Call("Scripts::Main", 1, "TabFont.js")                       - without arguments, switching between three fonts: default GUI font, system font, AkelPad font
//   Call("Scripts::Main", 1, "TabFont.js", `"2"`)                - AkelPad font
//   Call("Scripts::Main", 1, "TabFont.js", `"Courier New" 3 12`) - Courier New, italic, 12 pt
//
// For autostart, in AkelPad.ini or registry CmdLineBegin/CmdLineEnd key, need to add eg:
//   /Call("Scripts::Main", 1, "TabFont.js", `"8"`)

if ((! AkelPad.IsMDI()) || (! (AkelPad.Include("ChooseFont_function.js"))))
  WScript.Quit();

var oSys        = AkelPad.SystemFunction();
var hMainWnd    = AkelPad.GetMainWnd();
var hWndTab     = AkelPad.SendMessage(hMainWnd, 1222 /*AKD_GETMAININFO*/, 13 /*MI_WNDTAB*/, 0);
var hFontGUI    = oSys.Call("Gdi32::GetStockObject", 17 /*DEFAULT_GUI_FONT*/);
var hFontSYS    = oSys.Call("Gdi32::GetStockObject", 13 /*SYSTEM_FONT*/);
var hFontAP     = AkelPad.SendMessage(hMainWnd, 1231 /*AKD_GETFONT*/, 0, 0);
var hFontTabCur = AkelPad.SendMessage(hWndTab, 49 /*WM_GETFONT*/, 0, 0);
var hFontTabNew;

if (WScript.Arguments.length)
{
  if (WScript.Arguments(0) == "0")
    hFontTabNew = hFontGUI;

  else if (WScript.Arguments(0) == "1")
    hFontTabNew = hFontSYS;

  else if (WScript.Arguments(0) == "2")
    hFontTabNew = ConvertFontFormat(hFontAP, 2, 2);

  else if (WScript.Arguments(0) == "8")
    hFontTabNew = GetPrevFont();

  else if (WScript.Arguments(0) == "9")
    hFontTabNew = ChooseFont(hMainWnd, 2, hFontTabCur, 0, 0, 2, WScript.ScriptBaseName);

  else if (WScript.Arguments(0) == "+")
    hFontTabNew = ResizeFont(hFontTabCur, 1);

  else if (WScript.Arguments(0) == "-")
    hFontTabNew = ResizeFont(hFontTabCur, -1);

  else if (WScript.Arguments.length > 2)
    hFontTabNew = GetFontFromArgumets(WScript.Arguments(0), parseInt(WScript.Arguments(1), 10), parseInt(WScript.Arguments(2), 10), hFontTabCur);
}
else
{
  if (hFontTabCur == hFontGUI)
    hFontTabNew = hFontSYS;
  else if (hFontTabCur == hFontSYS)
    hFontTabNew = ConvertFontFormat(hFontAP, 2, 2);
  else
    hFontTabNew = hFontGUI;
}

if (hFontTabNew)
{
  oSys.Call("Gdi32::DeleteObject", hFontTabCur);
  AkelPad.SendMessage(hWndTab, 48 /*WM_SETFONT*/, hFontTabNew, true);
  WriteIni();
}

function ResizeFont(hFont, nIncrease)
{
  var aFont = ConvertFontFormat(hFont, 2, 3);

  aFont[2] = Math.abs(aFont[2]) + nIncrease;

  if (((nIncrease > 0) && (aFont[2] < 37)) || ((nIncrease < 0) && (aFont[2] > 0)))
    return ConvertFontFormat(aFont, 3, 2);
}

function GetFontFromArgumets(sFont, nStyle, nSize, hFontCur)
{
  var aFontCur = ConvertFontFormat(hFontCur, 2, 3);

  if (! sFont)
    sFont = aFontCur[0];

  if ((! nStyle) || (nStyle < 1) || (nStyle > 4))
    nStyle = aFontCur[1];

  if (! nSize)
    nSize = aFontCur[2];

  return ConvertFontFormat([sFont, nStyle, nSize], 3, 2);
}

function GetPrevFont()
{
  var aFontTab;

  try
  {
    eval(AkelPad.ReadFile(WScript.ScriptFullName.replace(/\.js$/i, ".ini"), 0x10 /*OD_ADT_NOMESSAGES*/, 1200 /*UTF-16LE*/, true));
  }
  catch (oError)
  {}

  if (! aFontTab)
    aFontTab = ["0", 0, 0];

  if (aFontTab[0] == "0")
    return hFontGUI;
  else if (aFontTab[0] == "1")
    return hFontSYS;
  else
    return ConvertFontFormat(aFontTab, 3, 2);
}

function WriteIni()
{
  var aFontTab;
  var sIniTxt;

  if (hFontTabNew == hFontGUI)
    aFontTab = ["0", 0, 0];
  else if (hFontTabNew == hFontSYS)
    aFontTab = ["1", 0, 0];
  else
    aFontTab = ConvertFontFormat(hFontTabNew, 2, 3);

  sIniTxt = 'aFontTab=["' + aFontTab[0] + '",' + aFontTab[1] + ',' + aFontTab[2] + '];';

  AkelPad.WriteFile(WScript.ScriptFullName.replace(/\.js$/i, ".ini"), sIniTxt, sIniTxt.length, 1200 /*UTF-16LE*/, true);
}
Back to top
View user's profile Send private message
Instructor
Site Admin


Joined: 06 Jul 2006
Posts: 5381

PostPosted: Fri Aug 29, 2014 2:18 pm    Post subject: Reply with quote

Change printing paper orientation. Required AkelPad 4.9.0 or higher.

PrintOrientation.js

Code:
// Change printing paper orientation. Required AkelPad 4.9.0 or higher.
// http://akelpad.sourceforge.net/forum/viewtopic.php?p=25685#25685
// Version v1.0
//
// Arguments:
// -Orientation=1  -Paper orientation (one of the following):
//                    1  portrait.
//                    2  landscape.
// -Print=1        -Print current document (one of the following):
//                    0  don't print (default).
//                    1  print with dialog.
//                    2  silent print.
// Examples:
// -"Print landscape" Call("Scripts::Main", 1, "PrintOrientation.js", `-Orientation=2 -Print=2`)

//Arguments
var nOrientation=AkelPad.GetArgValue("Orientation", 0);
var nPrint=AkelPad.GetArgValue("Print", 0);

if (SetPaperOrientation(nOrientation))
{
  //Print with dialog
  if (nPrint == 1)
    AkelPad.Command(4108 /*IDM_FILE_PRINT*/);
  //Silent print
  else if (nPrint == 2)
    AkelPad.Command(4113 /*IDM_FILE_SILENTPRINT*/);
}

function SetPaperOrientation(nOrientation)
{
  var hMainWnd=AkelPad.GetMainWnd();
  var oSys=AkelPad.SystemFunction();
  var lpPrintInfo;
  var lpDevMode;
  var hDevMode;
  var hDC;
  var bResult=false;

  if (nOrientation == 1 /*DMORIENT_PORTRAIT*/ ||
      nOrientation == 2 /*DMORIENT_LANDSCAPE*/)
  {
    if (lpPrintInfo=AkelPad.MemAlloc(_X64?56:44 /*sizeof(PRINTINFO)*/))
    {
      if (AkelPad.SendMessage(hMainWnd, 1215 /*AKD_GETPRINTINFO*/, lpPrintInfo, true))
      {
        if (hDevMode=AkelPad.MemRead(lpPrintInfo + 0 /*offsetof(PRINTINFO, hDevMode)*/, 2 /*DT_QWORD*/))
        {
          //Set orientation
          if (lpDevMode=oSys.Call("kernel32::GlobalLock", hDevMode))
          {
            AkelPad.MemCopy(lpDevMode + (_TSTR?76:44) /*offsetof(DEVMODE, dmOrientation)*/, nOrientation, 4 /*DT_WORD*/);
            bResult=true;
            oSys.Call("kernel32::GlobalUnlock", hDevMode);
          }

          //Free printer DC
          if (hDC=AkelPad.MemRead(lpPrintInfo + (_X64?16:8) /*offsetof(PRINTINFO, hDC)*/, 2 /*DT_QWORD*/))
          {
            oSys.Call("gdi32::DeleteDC", hDC);
            AkelPad.MemCopy(lpPrintInfo + (_X64?16:8) /*offsetof(PRINTINFO, hDC)*/, 0, 2 /*DT_QWORD*/);
          }

          //Copy information
          AkelPad.SendMessage(hMainWnd, 1216 /*AKD_SETPRINTINFO*/, lpPrintInfo, 0);
        }
      }
      AkelPad.MemFree(lpPrintInfo);
    }
  }
  return bResult;
}
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    AkelPad Forum Index -> Plugins All times are GMT
Goto page Previous  1, 2, 3 ... , 17, 18, 19  Next
Page 18 of 19

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


SourceForge.net Logo Powered by phpBB © 2001, 2005 phpBB Group