*****************************************************************
***                 Scripts AkelPad plugin v19.7              ***
*****************************************************************

2007-2026 Shengalts Aleksander aka Instructor (Shengalts@mail.ru)


*** Description ***

Scripts plugin is based on the Windows Scripting Host (WSH) engine,
so you can use various Windows Component Object Model (COM)
objects. For example, you can perform regular expression searches
using the RegExp object, manipulate files using the FileSystemObject
object, create a short-cut, manipulate the Windows Registry using
the WshShell object, or work with networking functions using the
WshNetwork object. Additionally, you can create and execute a
script that utilizes an external application that supports Automation
(such as Word and Excel). Plugin code is based on Jeff Glatt's "COM in C".


*** Included scripts ***

SearchReplace.js      -search/replace using regular expressions.
SpellCheck.js         -spell check using Microsoft Word.
LinesFilter.js        -filter lines using regular expressions.
Calculator.js         -text calculator.
EvalCmd.js            -evaluates an expression passed through command line.
InsertDate.js         -insert time and date in specified format.
InsertFile.js         -insert contents of a file.
RenameFile.js         -rename current editing file.
Keyboard.js           -convert keyboard layout or transliterate text.
ColumnCounter.js      -column selection counter.
Test.js               -test script on JScript.
Test.vbs              -test script on VBScript.


*** Functions ***

Scripts::Main
Main dialog.


*** External call ***

Call("Scripts::Main", 1, "SCRIPT", "ARGUMENTS")
  Parameters:
    1
      Execute script.
    "SCRIPT"
      Script file. If "", then last processed script used.
    "ARGUMENTS"
      Arguments (default is "").
  Examples:
    Call("Scripts::Main", 1, "InsertDate.js")
    Call("Scripts::Main", 1, "InsertDate.js", `"dd MMMM yyyy"`)

Call("Scripts::Main", 2, "SCRIPT", "ARGUMENTS")
  Same as 1, but wait for script completion.

Call("Scripts::Main", 3, "SCRIPT")
  Parameters:
    3
      Open script for editing.
    "SCRIPT"
      Script file. If "", then last processed script used.

Call("Scripts::Main", 4, "SCRIPT", "ARGUMENTS")
  Same as 2, but execute script in main thread without creating the new one.
  Not recommended for scripts contained AkelPad.WindowGetMessage().

Call("Scripts::Main", 5, "SCRIPT", OPERATION, *RESULT)
  Parameters:
    5
      Interact with running scripts.
    "SCRIPT"
      Script file. If "", then last processed script used.
    OPERATION
      See description of nOperation parameter in method AkelPad.ScriptHandle. Except SH_FINDSCRIPT flag.
    *RESULT
      Depend on operation.

  Example (get script handle):
    WScript.Echo(ScriptGetHandle("SearchReplace.js"));

    function ScriptGetHandle(pScript)
    {
      var oSys=AkelPad.SystemFunction();
      var nHandle=0;

      if (lpResult=AkelPad.MemAlloc(_X64?8:4 /*sizeof(INT_PTR)*/))
      {
        AkelPad.Call("Scripts::Main", 5, pScript, 2 /*SH_THISSCRIPT*/, lpResult);
        nHandle=AkelPad.MemRead(lpResult, 2 /*DT_QWORD*/);
        AkelPad.MemFree(lpResult);
      }
      return nHandle;
    }

  Example (get script file):
    WScript.Echo(ScriptGetFile("SearchReplace.js"));

    function ScriptGetFile(pScript)
    {
      var oSys=AkelPad.SystemFunction();
      var lpFile;
      var pFile="";

      if (lpResult=AkelPad.MemAlloc(_X64?8:4 /*sizeof(INT_PTR)*/))
      {
        AkelPad.Call("Scripts::Main", 5, pScript, 22 /*SH_GETFILE*/, lpResult);
        lpFile=AkelPad.MemRead(lpResult, 2 /*DT_QWORD*/);
        pFile=AkelPad.MemRead(lpFile, 1 /*DT_UNICODE*/);
        oSys.Call("oleaut32::SysFreeString", lpFile);
        AkelPad.MemFree(lpResult);
      }
      return pFile;
    }

Call("Scripts::Main", 6, SCRIPTHANDLE, OPERATION, *RESULT)
  Same as 5, but use script handle, instead of script file.

Call("Scripts::Main", 7, "METHOD", *RESULT)
  Parameters:
    7
      Call Scripts plugin method directly. Intended for ContextMenu, Hotkeys, Toolbar plugins.
    "METHOD"
      Script plugin method with arguments.
    *RESULT
      Call result.
  Example:
    "Find next paragraph" Call("Scripts::Main", 7, `AkelPad.TextFind(0, "(?<=\n\n)(?!\n)", 0x80001 /*FRF_DOWN|FRF_REGEXP*/)`)


*** Service information in script ***

At the script beginning in the comments possible to set service information, which
appear in the scripts list (appropriate columns must be enabled by mouse right click
on the list header) and also used when updating with AkelUpdater.

Site:
// http://akelpad.sourceforge.net/...

Version:
// Version: ...

Author:
// Author: ...

Description (variant 1):
//// Search and replace using regular expressions.

Description (variant 2):
// *** Search and replace using regular expressions. ***

Description on specified language (variant 3):
// Description(1033): Search and replace using regular expressions.
// Description(1049): Поиск/замена с использованием регулярных выражений.

Language identifiers list (Locale IDs Assigned by Microsoft):
http://msdn.microsoft.com/en-us/goglobal/bb964664.aspx


*** Methods list (methods that not attached to the AkelPad window, marked as +ActiveX) ***

AkelPad.GetMainWnd
AkelPad.GetAkelDir
AkelPad.GetInstanceExe
AkelPad.GetInstanceDll                       +ActiveX
AkelPad.GetLangId
AkelPad.IsOldWindows                         +ActiveX
AkelPad.IsAkelEdit
AkelPad.IsMDI
AkelPad.IsJScript9Legacy                     +ActiveX
AkelPad.GetEditWnd
AkelPad.SetEditWnd
AkelPad.GetEditDoc
AkelPad.GetEditFile
AkelPad.GetFilePath                          +ActiveX
AkelPad.GetEditCodePage
AkelPad.GetEditBOM
AkelPad.GetEditNewLine
AkelPad.GetEditModified
AkelPad.GetEditReadOnly
AkelPad.SetFrameInfo
AkelPad.SendMessage                          +ActiveX
AkelPad.MessageBox                           +ActiveX
AkelPad.InputBox                             +ActiveX
AkelPad.GetSelStart
AkelPad.GetSelEnd
AkelPad.SetSel
AkelPad.GetSelText
AkelPad.GetTextRange
AkelPad.ReplaceSel
AkelPad.TextFind
AkelPad.TextReplace
AkelPad.GetClipboardText                     +ActiveX
AkelPad.SetClipboardText                     +ActiveX
AkelPad.IsPluginRunning
AkelPad.Call
AkelPad.CallA
AkelPad.CallW
AkelPad.CallEx
AkelPad.CallExA
AkelPad.CallExW
AkelPad.Exec                                 +ActiveX
AkelPad.Command
AkelPad.Font
AkelPad.Recode
AkelPad.Include
AkelPad.IsInclude
AkelPad.OpenFile
AkelPad.ReadFile
AkelPad.WriteFile
AkelPad.SaveFile
AkelPad.SystemFunction                       +ActiveX
AkelPad.SystemFunction().AddParameter        +ActiveX
AkelPad.SystemFunction().Call                +ActiveX
AkelPad.SystemFunction().GetLastError        +ActiveX
AkelPad.SystemFunction().RegisterCallback    +ActiveX
AkelPad.SystemFunction().UnregisterCallback  +ActiveX
AkelPad.MemAlloc                             +ActiveX
AkelPad.MemCopy                              +ActiveX
AkelPad.MemRead                              +ActiveX
AkelPad.MemStrPtr                            +ActiveX
AkelPad.MemPtrStr                            +ActiveX
AkelPad.MemFree                              +ActiveX
AkelPad.DebugJIT                             +ActiveX
AkelPad.Debug                                +ActiveX
AkelPad.VarType                              +ActiveX
AkelPad.VarDispatch                          +ActiveX
AkelPad.GetArgLine
AkelPad.GetArgValue
AkelPad.ScriptSettings
AkelPad.ScriptSettings().Begin
AkelPad.ScriptSettings().Read
AkelPad.ScriptSettings().Write
AkelPad.ScriptSettings().Delete
AkelPad.ScriptSettings().End
AkelPad.WindowRegisterClass                  +ActiveX
AkelPad.WindowUnregisterClass                +ActiveX
AkelPad.WindowRegisterDialog                 +ActiveX
AkelPad.WindowUnregisterDialog               +ActiveX
AkelPad.CreateDialog                         +ActiveX
AkelPad.WindowGetMessage                     +ActiveX
AkelPad.WindowSubClass                       +ActiveX
AkelPad.WindowNextProc                       +ActiveX
AkelPad.WindowNoNextProc                     +ActiveX
AkelPad.WindowUnsubClass                     +ActiveX
AkelPad.ThreadHook                           +ActiveX
AkelPad.ThreadUnhook                         +ActiveX
AkelPad.ScriptNoMutex
AkelPad.ScriptExitCode
AkelPad.ScriptHandle                         +ActiveX
AkelPad.ConnectObject                        +ActiveX
AkelPad.DisconnectObject                     +ActiveX
AkelPad.ActiveXThis                          +ActiveX
WScript.ScriptBaseName
_TCHAR                                       +ActiveX uses as AkelPad.Constants._TCHAR
vbTCHAR                                      +ActiveX uses as AkelPad.Constants.vbTCHAR
_TSTR                                        +ActiveX uses as AkelPad.Constants._TSTR
vbTSTR                                       +ActiveX uses as AkelPad.Constants.vbTSTR
_TSIZE                                       +ActiveX uses as AkelPad.Constants._TSIZE
vbTSIZE                                      +ActiveX uses as AkelPad.Constants.vbTSIZE
_X64                                         +ActiveX uses as AkelPad.Constants._X64
vbX64                                        +ActiveX uses as AkelPad.Constants.vbX64
_PtrAdd                                      +ActiveX uses as AkelPad.Global._PtrAdd
vbPtrAdd                                     +ActiveX uses as AkelPad.Global.vbPtrAdd
_PtrMath                                     +ActiveX uses as AkelPad.Global._PtrMath
vbPtrMath                                    +ActiveX uses as AkelPad.Global.vbPtrMath


*** Methods description ***

AkelPad.GetMainWnd
__________________

Get main window handle.

  GetMainWnd();

Return Value
  Number. Main window handle.

Example:
  var hMainWnd=AkelPad.GetMainWnd();


AkelPad.GetAkelDir
__________________

Get AkelPad directory or its subdirectory.

  GetAkelDir([nSubDir]);

Arguments
  nSubDir
    0  //ADTYPE_ROOT       root AkelPad's folder (by default).
    1  //ADTYPE_AKELFILES  "[AkelPad]\AkelFiles".
    2  //ADTYPE_DOCS       "[AkelPad]\AkelFiles\Docs".
    3  //ADTYPE_LANGS      "[AkelPad]\AkelFiles\Langs".
    4  //ADTYPE_PLUGS      "[AkelPad]\AkelFiles\Plugs".
    5  //ADTYPE_SCRIPTS    "[AkelPad]\AkelFiles\Plugs\Scripts".
    6  //ADTYPE_INCLUDE    "[AkelPad]\AkelFiles\Plugs\Scripts\Include".

Return Value
  String. AkelPad directory or its subdirectory.

Example:
  var pAkelDir=AkelPad.GetAkelDir();


AkelPad.GetInstanceExe
______________________

Get EXE instance handle.

  GetInstanceExe();

Return Value
  Number. EXE instance handle.

Example:
  var hInstance=AkelPad.GetInstanceExe();


AkelPad.GetInstanceDll (+ActiveX)
_________________________________

Get DLL instance handle.

  GetInstanceDll();

Return Value
  Number. DLL instance handle.

Example:
  var hInstance=AkelPad.GetInstanceDll();


AkelPad.GetLangId
_________________

Get AkelPad language ID.

  GetLangId([nType]);

Arguments
  nType
    0  //LANGID_FULL     full language identifier. This value is a combination of a primary language identifier and a sublanguage identifier (by default).
    1  //LANGID_PRIMARY  primary language identifier.
    2  //LANGID_SUB      sublanguage identifier.

Return Value
  Number. AkelPad language ID.

Example:
  var nLangID=AkelPad.GetLangId(1 /*LANGID_PRIMARY*/);

  if (nLangID == 0x19) //LANG_RUSSIAN
    WScript.Echo("Russian");
  else
    WScript.Echo("Other");


AkelPad.IsOldWindows (+ActiveX)
_______________________________

Is non-Unicode Windows.

  IsOldWindows();

Return Value
  true   non-Unicode (Windows 95/98/Me).
  false  Unicode (Windows NT/2000/XP).

Example:
  var bOldWindows=AkelPad.IsOldWindows();


AkelPad.IsAkelEdit
__________________

Check AkelEdit control usage in program or in specified window.

  IsAkelEdit([hWnd]);

Arguments
  hWnd
    Edit window handle. If zero or not specified, then returned AkelEdit usage in program.

Return Value
  0  //ISAEW_NONE     RichEdit control used (AkelPad v3.x.x).
  1  //ISAEW_PROGRAM  AkelEdit control used (AkelPad v4.x.x or higher)
     //               or, if handle specified, then this handle is the program AkelEdit window.
  2  //ISAEW_PLUGIN   if handle specified, then this handle is the plugin AkelEdit window (AkelPad v4.x.x or higher).

Example:
  var nAkelEdit=AkelPad.IsAkelEdit();


AkelPad.IsMDI
_____________

Is AkelPad in MDI mode.

  IsMDI();

Return Value
  0  //WMD_SDI   Single document interface (SDI).
  1  //WMD_MDI   Multiple document interface (MDI).
  2  //WMD_PMDI  Pseudo-Multiple document interface (PMDI).

Example:
  var nMDI=AkelPad.IsMDI();


AkelPad.IsJScript9Legacy
________________________

Is AkelPad use jscript9Legacy.dll engine.

  IsJScript9Legacy();

Return Value
  true   jscript9Legacy.dll used (Windows 11 24H2 and higher).
  false  jscript9Legacy.dll not used.

Example:
  var nJScript9Legacy=AkelPad.IsJScript9Legacy();


AkelPad.GetEditWnd
__________________

Get active edit window handle.

  GetEditWnd();

Return Value
  Number. Active edit window handle.

Example:
  var hWndEdit=AkelPad.GetEditWnd();


AkelPad.SetEditWnd
__________________

Set active edit window handle manually. After setting methods GetEditWnd, GetEditDoc,
GetSelStart, GetSelEnd, SetSel, GetSelText, GetTextRange, ReplaceSel will use this handle.

  SetEditWnd(hHandle);

Arguments
  hHandle
    Edit window handle or the following value:
      1   //SEW_FOCUS  Use window handle that has focus.
    If zero or hHandle is not AkelEdit/RichEdit20 window,
    then handles management is taken by program and zero is returned.

Return Value
  Number. Active edit window handle.

Example:
  var hWndOutput;

  if (hWndOutput=GetOutputWindow())
  {
    if (AkelPad.SetEditWnd(hWndOutput))
      AkelPad.SetSel(0, -1);
  }

  function GetOutputWindow()
  {
    var lpWnd;
    var hWnd=0;

    if (lpWnd=AkelPad.MemAlloc(_X64?8:4 /*sizeof(HWND)*/))
    {
      AkelPad.Call("Log::Output", 2, lpWnd);
      hWnd=AkelPad.MemRead(lpWnd, 2 /*DT_QWORD*/);
      AkelPad.MemFree(lpWnd);
    }
    return hWnd;
  }


AkelPad.GetEditDoc
__________________

Get active document handle.

  GetEditDoc();

Return Value
  Number. Active document handle.

Example:
  var hDocEdit=AkelPad.GetEditDoc();


AkelPad.GetEditFile
___________________

Get file name.

  GetEditFile(hHandle);

Arguments
  hHandle
    Edit window handle. If zero then active edit window handle is used.

Return Value
  String. File name.

Example:
  var pEditFile=AkelPad.GetEditFile(0);


AkelPad.GetFilePath (+ActiveX)
______________________________

Get file path part.

  GetFilePath(pFile, nPart);

Arguments
  pFile
    File path.
  nPart
    1  //CPF_DIR           Directory.
    2  //CPF_FILENAME      File name.
    3  //CPF_FILEBASENAME  File base name.
    4  //CPF_FILEEXT       File extension.

Return Value
  String. File path part.

Example:
  var pFileName=AkelPad.GetFilePath("c:\\WINDOWS\\notepad.exe", 2 /*CPF_FILENAME*/);


AkelPad.GetEditCodePage
_______________________

Get file code page.

  GetEditCodePage(hHandle);

Arguments
  hHandle
    Edit window handle. If zero then active edit window handle is used.

Return Value
  Number. Code page.

Example:
  var nCodePage=AkelPad.GetEditCodePage(0);


AkelPad.GetEditBOM
__________________

Get file BOM.

  GetEditBOM(hHandle);

Arguments
  hHandle
    Edit window handle. If zero then active edit window handle is used.

Return Value
  true   file has BOM.
  false  file hasn't BOM.

Example:
  var bBOM=AkelPad.GetEditBOM(0);


AkelPad.GetEditNewLine
______________________

Get file new line format.

  GetEditNewLine(hHandle);

Arguments
  hHandle
    Edit window handle. If zero then active edit window handle is used.

Return Value
  1  DOS/Windows (0Dh, 0Ah)
  2  Unix (0Ah)
  3  Mac (0Dh)

Example:
  var nNewLine=AkelPad.GetEditNewLine(0);


AkelPad.GetEditModified
_______________________

Get file modified flag.

  GetEditModified(hHandle);

Arguments
  hHandle
    Edit window handle. If zero then active edit window handle is used.

Return Value
  true   contents of edit control have been modified.
  false  contents of edit control haven't been modified.

Example:
  var bModified=AkelPad.GetEditModified(0);


AkelPad.GetEditReadOnly
_______________________

Get edit control's read only mode.

  GetEditReadOnly(hHandle);

Arguments
  hHandle
    Edit window handle. If zero then active edit window handle is used.

Return Value
  true   read only mode.
  false  edit mode.

Example:
  var bReadOnly=AkelPad.GetEditReadOnly(0);


AkelPad.SetFrameInfo
____________________

Set frame information.

  SetFrameInfo(lpFrame, nType, dwData);

Arguments
  lpFrame
    Frame data handle. If zero then data handle of the active frame is used.
  nType
    Setting type for change. See description of FIS_* flags in AkelDLL.h.
  dwData
    Setting data.

Return Value
  true   information is changed.
  false  information isn't changed.

Remarks
  Method works on all window modes SDI/MDI/PMDI.

Example:
  AkelPad.SetFrameInfo(0, 1 /*FIS_TABSTOPSIZE*/, 4);


AkelPad.SendMessage (+ActiveX)
______________________________

Send message.

  SendMessage(hHandle, nMessage, wParam, lParam);

Arguments
  hHandle
    Handle to the window whose window procedure will receive the message.
  nMessage
    Specifies the message to be sent.
  wParam
    Specifies additional message-specific information.
  lParam
    Specifies additional message-specific information.

Return Value
  Number. Result of the message processing; it depends on the message sent.

Example:
  var hMainWnd=AkelPad.GetMainWnd();
  AkelPad.SendMessage(hMainWnd, 273 /*WM_COMMAND*/, 4101 /*IDM_FILE_NEW*/, 0);


AkelPad.MessageBox (+ActiveX)
_____________________________

Show message.

  MessageBox(hHandle, pText, pCaption, nType[, hIcon][, ...]);

Arguments
  hHandle
    Handle to the owner window of the message box to be created. If this parameter is zero, the message box has no owner window.
  pText
    Message to be displayed.
  pCaption
    Dialog box title.
  nType
    Specifies the contents and behavior of the dialog box. See MSDN.
  hIcon
    Icon handle. If zero, icon specified in nType is used.
  ...
    Enumeration of dialog buttons. Each button consists of three elements - nButtonID, pButtonStr, nFlags.
      nButtonID
        Button identifier.
      pButtonStr
        Button text.
      nFlags
        0x1  //BMB_DEFAULT   Default button.
        0x2  //BMB_DISABLED  Button is disabled.

Remarks
  If only first 4 arguments are used, then system message box is called.
  If all arguments are used, then AkelPad extended message box is called.
  If all arguments are used, then nType argument specified only icon type MB_ICON*.

Return Value
  Number. Return value is the button's ID pressed.

Example (standard dialog):
  var hMainWnd=AkelPad.GetMainWnd();
  AkelPad.MessageBox(hMainWnd, "MyText", "MyCaption", 64 /*MB_ICONINFORMATION*/);

Example (extended dialog):
  var hMainWnd=AkelPad.GetMainWnd();
  var nChoice=AkelPad.MessageBox(hMainWnd, "MyText", "MyCaption", 32 /*MB_ICONQUESTION*/, 0,
              1 /*IDOK*/,     "&OK",     0x1 /*BMB_DEFAULT*/,
              2 /*IDCANCEL*/, "&Cancel", 0);
  WScript.Echo("Button ID=" + nChoice);


AkelPad.InputBox (+ActiveX)
___________________________

Input dialog box.

  InputBox(hHandle, pCaption, pLabel, pEdit);

Arguments
  hHandle
    Handle to the owner window of the message box to be created.
  pCaption
    Dialog box title.
  pLabel
    Edit box label. It is possible to use \n symbol to create multiline label.
  pEdit
    Edit box text.

Return Value
  String. Edit box text. Cancel button returns undefined.

Example:
  var hMainWnd=AkelPad.GetMainWnd();
  var pText=AkelPad.InputBox(hMainWnd, "MyCaption", "MyLabel", "MyText");


AkelPad.GetSelStart
___________________

Get selection first char index.

  GetSelStart();

Return Value
  Number. Selection first char index.

Example:
  var nSelStart=AkelPad.GetSelStart();


AkelPad.GetSelEnd
_________________

Get selection last char index.

  GetSelEnd();

Return Value
  Number. Selection last char index.

Example:
  var nSelEnd=AkelPad.GetSelEnd();


AkelPad.SetSel
______________

Set selection.

  SetSel(nSelStart, nSelEnd[, nFlags]);

Arguments
  nSelStart
    Selection first char index.
  nSelEnd
    Selection last char index. If -1, uses document last char index.
  nFlags
    0x001  //AESELT_COLUMNON              Make column selection ON.
    0x002  //AESELT_COLUMNASIS            Leave column selection as is.
    0x004  //AESELT_LOCKNOTIFY            Disable AEN_SELCHANGING and AEN_SELCHANGED notifications.
    0x008  //AESELT_LOCKSCROLL            Lock edit window scroll.
    0x010  //AESELT_LOCKUPDATE            Lock edit window update.
    0x020  //AESELT_LOCKCARET             Lock caret reposition.
    0x080  //AESELT_NOCARETHORZINDENT     Caret horizontal indent isn't changed.
    0x100  //AESELT_NOVERTSCROLLCORRECT   On some conditions scroll can be increased to a height of one line.

Return Value
  Zero.

Example:
  AkelPad.SetSel(0, 10);


AkelPad.GetSelText
__________________

Get selected text.

  GetSelText([nNewLine]);

Arguments
  nNewLine (only for AkelPad 4.x.x)
    0    //New line without changing.
    1    //"\r" new line (default).
    2    //"\n" new line.
    3    //"\r\n" new line.

Return Value
  String. Selected text.

Example:
  var pSelText=AkelPad.GetSelText();


AkelPad.GetTextRange
____________________

Get text range.

  GetTextRange(nRangeStart, nRangeEnd[, nNewLine]);

Arguments
  nRangeStart
    Range first char index.
  nRangeEnd
    Range last char index. If -1, uses document last char index.
  nNewLine (only for AkelPad 4.x.x)
    0    //New line without changing.
    1    //"\r" new line (default).
    2    //"\n" new line.
    3    //"\r\n" new line.

Return Value
  String. Text range.

Example:
  var pTextRange=AkelPad.GetTextRange(0, 10);


AkelPad.ReplaceSel
__________________

Replace selection.

  ReplaceSel(pText[, nSelect]);

Arguments
  pText
    Text to replace with.
  nSelect
     0  //RST_NONE                 don't select inserted text (default).
    -1  //RST_SELECT               select inserted text.
    -2  //RST_SELECTRESTORESCROLL  select inserted text and restore scroll position.

Return Value
  Zero.

Example:
  AkelPad.ReplaceSel("MyText");


AkelPad.TextFind
________________

Find text.

  TextFind(hHandle, pFindIt, nFlags);

Arguments
  hHandle
    Edit window handle. If zero then active edit window handle is used.
  pFindIt
    Text to find.
  nFlags
    0x00000001  //FRF_DOWN                Find down.
    0x00000002  //FRF_WHOLEWORD           Find whole word.
    0x00000004  //FRF_MATCHCASE           Search is case-sensitive.
    0x00020000  //FRF_REGEXPMINMATCH      Allow zero length match at string edges. For example: "^" at the string beginning or "$" at the string ending (usage: FRF_REGEXP|FRF_REGEXPMINMATCH).
    0x00040000  //FRF_REGEXPNONEWLINEDOT  Symbol . in regular expressions specifies any character except new line (usage: FRF_REGEXP|FRF_REGEXPNONEWLINEDOT).
    0x00080000  //FRF_REGEXP              Search with regular expressions.
    0x00100000  //FRF_UP                  Find up.
    0x00200000  //FRF_BEGINNING           Search from beginning (usage: FRF_DOWN|FRF_BEGINNING).
    0x00400000  //FRF_SELECTION           Search in selection (usage: FRF_DOWN|FRF_SELECTION).
    0x00800000  //FRF_ESCAPESEQ           Search with escape sequences.
    0x01000000  //FRF_ALLFILES            Search in all opened MDI documents (usage: FRF_DOWN|FRF_ALLFILES or FRF_DOWN|FRF_BEGINNING|FRF_ALLFILES).
    0x08000000  //FRF_CYCLESEARCH         Cycle search.
    0x10000000  //FRF_CYCLESEARCHPROMPT   Prompt during cycle search.
    0x80000000  //FRF_TEST                Test only. Without text selection.

Return Value
  Number. Character position of the next match.
  If there are no more matches, the return value is -1.
  If there is syntax error in regular expression (with FRF_REGEXP flag), the return value is (-100 - PatternOffset).
  For example, pFindIt equal to "ab[c", syntax error in third symbol, return value is -102.

Example:
  AkelPad.TextFind(0, "MySearchString", 0x00200001 /*FRF_DOWN|FRF_BEGINNING*/);


AkelPad.TextReplace
___________________

Find and replace text.

  TextReplace(hHandle, pFindIt, pReplaceWith, nFindFlags, nReplaceFlags);

Arguments
  hHandle
    Edit window handle. If zero then active edit window handle is used.
  pFindIt
    Text to find.
  pReplaceWith
    Text to replace with.
  nFindFlags
    0x00000001  //FRF_DOWN                Find down.
    0x00000002  //FRF_WHOLEWORD           Find whole word.
    0x00000004  //FRF_MATCHCASE           Search is case-sensitive.
    0x00040000  //FRF_REGEXPNONEWLINEDOT  Symbol . in regular expressions specifies any character except new line (usage: FRF_REGEXP|FRF_REGEXPNONEWLINEDOT).
    0x00080000  //FRF_REGEXP              Search with regular expressions.
    0x00100000  //FRF_UP                  Find up.
    0x00200000  //FRF_BEGINNING           Search from beginning (usage: FRF_DOWN|FRF_BEGINNING).
    0x00400000  //FRF_SELECTION           Search in selection (usage: FRF_DOWN|FRF_SELECTION).
    0x00800000  //FRF_ESCAPESEQ           Search with escape sequences.
    0x01000000  //FRF_ALLFILES            Search in all opened MDI documents (usage: FRF_DOWN|FRF_ALLFILES or FRF_DOWN|FRF_BEGINNING|FRF_ALLFILES).
    0x08000000  //FRF_CYCLESEARCH         Cycle search (don't use with RRF_ALL).
    0x10000000  //FRF_CYCLESEARCHPROMPT   Prompt during cycle search.
    0x80000000  //FRF_TEST                Test only. Without text replacement and selection.
  nReplaceFlags
    0x1         //RRF_ALL                 Replace all. Default is replace single.

Return Value
  Number. Character position of the next match.
  If there are no more matches, the return value is -1.
  If RRF_ALL flag specified, the return value is count of changes.
  If there is syntax error in regular expression (with FRF_REGEXP flag), the return value is (-100 - PatternOffset).
  For example, pFindIt equal to "ab[c", syntax error in third symbol, return value is -102.

Example:
  AkelPad.TextReplace(0, "MySearchString", "MyReplaceText", 0x00200001 /*FRF_DOWN|FRF_BEGINNING*/, 0x1 /*RRF_ALL*/);


AkelPad.GetClipboardText (+ActiveX)
___________________________________

Get clipboard text.

  GetClipboardText([bAnsi]);

Arguments
  bAnsi
    true   retrieve ansi text.
    false  retrieve unicode text (default).

Return Value
  String. Clipboard text.

Example:
  var pClipboardText=AkelPad.GetClipboardText();


AkelPad.SetClipboardText (+ActiveX)
___________________________________

Set clipboard text.

  SetClipboardText(pText);

Arguments
  pText
    Text to set.

Return Value
  Zero.

Example:
  AkelPad.SetClipboardText("MyText");


AkelPad.IsPluginRunning
_______________________

Is AkelPad plugin running.

  IsPluginRunning(pFunction);

Arguments
  pFunction
    Function to check.

Return Value
  true   plugin is running.
  false  plugin isn't running.

Example:
  var bRunning=AkelPad.IsPluginRunning("Coder::HighLight");


AkelPad.Call
____________

Call AkelPad plugin.

  Call(pFunction[, ...]);

Arguments
  pFunction
    Function to call.
  ...
    Function parameters.

Remarks
  During plugin call string type determines automatically.

Return Value
  If script was called, then result of AkelPad.ScriptExitCode returns.
   -1  //UD_FAILED               Operation failed.
    0  //UD_UNLOAD               Plugin unloaded.
  0x1  //UD_NONUNLOAD_ACTIVE     Plugin in memory and active.
  0x2  //UD_NONUNLOAD_NONACTIVE  Plugin in memory, but non-active.
  0x4  //UD_NONUNLOAD_UNCHANGE   Plugin in memory.
  0x8  //UD_HOTKEY_DODEFAULT     Hotkey default processing will done.

Example:
  var nResult=AkelPad.Call("Coder::HighLight", 2, "#000000", "#9BFF9B");


AkelPad.CallA
_____________

Same as AkelPad.Call, but force to use Ansi stings during plugin call.


AkelPad.CallW
_____________

Same as AkelPad.Call, but force to use Unicode stings during plugin call.


AkelPad.CallEx
______________

Call AkelPad plugin with flags.

  CallEx(nFlags, pFunction[, ...]);

Arguments
  nFlags
    0x04  //DLLCF_SWITCHAUTOLOAD  If function running after call then turn on autoload, if not then turn off autoload.
    0x08  //DLLCF_SAVENOW         Using with DLLCF_SWITCHAUTOLOAD. Call AKD_DLLSAVE with DLLSF_NOW after switching autoload flag.
    0x10  //DLLCF_SAVEONEXIT      Using with DLLCF_SWITCHAUTOLOAD. Call AKD_DLLSAVE with DLLSF_ONEXIT after switching autoload flag.
  pFunction
    Function to call.
  ...
    Function parameters.

Remarks
  During plugin call string type determines automatically.

Return Value
  If script was called, then result of AkelPad.ScriptExitCode returns.
   -1  //UD_FAILED               Operation failed.
    0  //UD_UNLOAD               Plugin unloaded.
  0x1  //UD_NONUNLOAD_ACTIVE     Plugin in memory and active.
  0x2  //UD_NONUNLOAD_NONACTIVE  Plugin in memory, but non-active.
  0x4  //UD_NONUNLOAD_UNCHANGE   Plugin in memory.
  0x8  //UD_HOTKEY_DODEFAULT     Hotkey default processing will done.

Example:
  var nResult=AkelPad.CallEx(0x14 /*DLLCF_SWITCHAUTOLOAD|DLLCF_SAVEONEXIT*/, "Coder::HighLight");


AkelPad.CallExA
_______________

Same as AkelPad.CallEx, but force to use Ansi stings during plugin call.


AkelPad.CallExW
_______________

Same as AkelPad.CallEx, but force to use Unicode stings during plugin call.


AkelPad.Exec (+ActiveX)
_______________________

Execute program.

  Exec(pCommandLine[, pWorkDirectory][, nWait][, nWindowStyle]);

Arguments
  pCommandLine
    Command line. Can contain %a - AkelPad directory and environment variables, for example, %WinDir% - Windows directory.
  pWorkDirectory
    Working directory. Default is "". Can contain %a - AkelPad directory and environment variables, for example, %WinDir% - Windows directory.
  nWait
    0  returns immediately after starting the program, automatically returning 0 (default).
    1  waits until the program finishes and returns any error code returned by the program.
    2  waits until the specified process is waiting for user input, automatically returning 0.
  nWindowStyle
   -1 don't change (by default).
    0 hidden window.
    1 window as is.
    2 minimized window.
    3 maximized window.
    6 minimized, inactive window.
    9 non-maximized window.
    Note: programs could ignore this parameter.

Return Value
  Number. Exit code.

Example:
  AkelPad.Exec("notepad.exe");


AkelPad.Command
_______________

Call AkelPad internal command.

  Command(nCmd[, nParam]);

Arguments
  nCmd
    Internal command number.
  nParam
    Parameter passed to internal command. Only some commands support additional parameter, for example, 4113 /*IDM_FILE_SILENTPRINT*/. See description of commands in AkelDLL.h.

Return Value
  Number. Depend on command.

Example:
  AkelPad.Command(4101 /*IDM_FILE_NEW*/);


AkelPad.Font
____________

Set font.

  Font(pFont, nStyle, nSize);

Arguments
  pFont
    Font face, for example, "Courier". Unchanged, if "".
  nStyle
    0 ignored.
    1 normal.
    2 bold.
    3 italic.
    4 bold italic.
  nSize
    Font size. Unchanged, if 0.

Return Value
  Zero.

Example:
  AkelPad.Font("Courier", 4, 10)


AkelPad.Recode
______________

Recode selection.

  Recode(nCodePageFrom, nCodePageTo);

Arguments
  nCodePageFrom
    Recode codepage source. If -1, it will be autodetected.
  nCodePageTo
    Recode codepage target. If -1, it will be autodetected.

Return Value
  Zero.

Example:
  AkelPad.Recode(1252, 437);


AkelPad.Include
_______________

Add code from file.

  Include(pFileName[, nFlags][, nCodePage][, bBOM]);

Arguments
  pFileName
    File name, that located in "[AkelPad]\AkelFiles\Plugs\Scripts\Include" directory.
  nFlags
    See nFlags description of AkelPad.ReadFile method.
  nCodePage
    See nCodePage description of AkelPad.ReadFile method.
  bBOM
    See bBOM description of AkelPad.ReadFile method.

Remarks
  Method Include is the same as code eval(AkelPad.ReadFile("...")), but allow to detect error placement in include file, if error appear.

Return Value
  true   success.
  false  failed.

Example:
   var lpItems;
   var nItem;

   if (!AkelPad.Include("ShowMenu.js")) WScript.Quit();

   lpItems=[["ItemA", MF_NORMAL, 101],
            ["ItemB", MF_SUBMENU],
              ["ItemB-1", MF_NORMAL, 102],
              ["ItemB-2", MF_NORMAL, 103],
              ["ItemB-3", MF_NORMAL|MF_LAST, 104],
            ["ItemC", MF_NORMAL, 105]];
   nItem=ShowMenu(lpItems, POS_CARET, POS_CARET);
   WScript.Echo("" + nItem);


AkelPad.IsInclude
_________________

Detect is script executed with AkelPad.Include() method.

  IsInclude();

Return Value
  String. Include file name, if script executed with AkelPad.Include() method or "" otherwise.

Example:
  WScript.Echo("" + AkelPad.IsInclude());


AkelPad.OpenFile
________________

Open file.

  OpenFile(pFile[, nFlags][, nCodePage][, bBOM]);

Arguments
  pFile
    File to open.
  nFlags
    0x001  //OD_ADT_BINARYERROR     Check if file is binary.
    0x002  //OD_ADT_REGCODEPAGE     If last open code page found in registry, then it will be
           //                        used with OD_ADT_DETECTBOM flag, if not found, then next flags
           //                        will be used OD_ADT_DETECTCODEPAGE|OD_ADT_DETECTBOM.
    0x004  //OD_ADT_DETECTCODEPAGE  Detect code page.
    0x008  //OD_ADT_DETECTBOM       Detect BOM mark.
    0x010  //OD_ADT_NOMESSAGES      No messages, if errors in autodetect.
    0x020  //OD_ADT_ONLYBOM         Detect code page only if BOM mark is present, otherwise default codepage is used.
    0x100  //OD_REOPEN              Don't create new MDI window, use the exited one.
    0x200  //OD_NOSCROLL            Don't restore scroll position.
    0x400  //OD_MULTIFILE           More documents is on queue. Use MB_YESNOCANCEL instead of MB_OKCANCEL.
    0x800  //OD_NOUPDATE            Don't update file info.
           //Default is 0xD         (OD_ADT_BINARYERROR|OD_ADT_DETECTCODEPAGE|OD_ADT_DETECTBOM).
  nCodePage
    File code page, ignored if (nFlags & OD_ADT_DETECTCODEPAGE)
  bBOM
    File BOM, ignored if (nFlags & OD_ADT_DETECTBOM)

Return Value
   0  //EOD_SUCCESS          Success.
  -1  //EOD_ADT_OPEN         Autodetect codepage, can't open file.
  -2  //EOD_ADT_ALLOC        Autodetect codepage, can't allocate buffer.
  -3  //EOD_ADT_READ         Autodetect codepage, read file error.
 -11  //EOD_OPEN             Can't open file.
 -13  //EOD_WINDOWEXIST      File already opened.
 -14  //EOD_CODEPAGEERROR    Code page isn't implemented.
 -15  //EOD_STOP             Stopped from AKDN_OPENDOCUMENT_START.
 -16  //EOD_STREAMIN         Error in EM_STREAMIN.
 -17  //EOD_DOCUMENTSLIMIT   Documents limit reached in MDI mode.
 -21  //EOD_MSGCANCELCREATE  User press Cancel in message "Create new file?".
 -22  //EOD_MSGCANCELBINARY  User press Cancel in message "Binary file. Continue?".
 -23  //EOD_MSGNOCREATE      User press No in message "Create new file?".
 -24  //EOD_MSGNOBINARY      User press No in message "Binary file. Continue?".

Example:
  var bResult=AkelPad.OpenFile("C:\\MyFile.txt");


AkelPad.ReadFile
________________

Read contents of a file.

  ReadFile(pFile[, nFlags][, nCodePage][, bBOM][, nBytesMax]);

Arguments
  pFile
    File to read.
  nFlags
    0x01  //ADT_BINARYERROR     Check if file is binary.
    0x02  //ADT_REGCODEPAGE     If last open code page found in registry, then it will be
          //                     used with ADT_DETECTBOM flag, if not found, then next flags
          //                     will be used ADT_DETECTCODEPAGE|ADT_DETECTBOM.
    0x04  //ADT_DETECTCODEPAGE  Detect code page.
    0x08  //ADT_DETECTBOM       Detect BOM mark.
    0x10  //ADT_NOMESSAGES      No messages, if errors in autodetect.
    0x20  //ADT_ONLYBOM         Detect code page only if BOM mark is present, otherwise default codepage is used.
          //Default is 0xD      (ADT_BINARYERROR|ADT_DETECTCODEPAGE|ADT_DETECTBOM).
  nCodePage
    File code page, ignored if (nFlags & ADT_DETECTCODEPAGE).
  bBOM
    File BOM, ignored if (nFlags & ADT_DETECTBOM).
  nBytesMax
    Read specified number of first bytes in file. If -1, entire file will be read (default).

Return Value
  String. Contents of a file.

Example:
  var pText=AkelPad.ReadFile("C:\\MyFile.txt");


AkelPad.WriteFile
_________________

Write file content.

  WriteFile(vFile, pContent, nContentLen, nCodePage, bBOM[, nFlags]);

Arguments
  vFile
    File to write as string or as file handle.
  pContent
    Content to write.
  nContentLen
    Content length. If -1, length is calculated automatically.
  nCodePage
    Write codepage.
  bBOM
    File byte order mark.
  nFlags
    0x1  //WFF_WRITEREADONLY  Ignore read-only attribute. Only if vFile specified as string.
    0x2  //WFF_APPENDFILE     Write content to the end of the file. Only if vFile specified as string.
         //Default is 0x0.

Return Value
   0  //ESD_SUCCESS         Success.
  -1  //ESD_OPEN            Can't open file for write.
  -2  //ESD_WRITE           Can't write to file.
  -3  //ESD_READONLY        File has read-only attribute.

Example:
  AkelPad.WriteFile("C:\\MyFile.txt", "Text", -1, 65001, true);


AkelPad.SaveFile
________________

Save document.

  SaveFile(hHandle, pFile[, nCodePage][, bBOM][, nFlags][, hDoc]);

Arguments
  hHandle
    Edit window handle. If zero then active edit window handle is used.
  pFile
    File name to save to.
  nCodePage
    Save codepage. If -1 or not specified, current codepage will be used.
  bBOM
    File byte order mark. 1 - exist, 0 - doesn't exist, -1 or not specified - current BOM will be used.
  nFlags
    0x1  //SD_UPDATE       Update file info in program.
    0x2  //SD_SELECTION    Save only selection.
         //Default is 0x1  (SD_UPDATE).
  hDoc
    Document handle. If zero (default), detected automatically.

Return Value
   0  //ESD_SUCCESS        Success.
  -1  //ESD_OPEN           Can't open file.
  -2  //ESD_WRITE          Can't write to file.
  -3  //ESD_READONLY       File has read-only attribute.
  -4  //ESD_CODEPAGEERROR  Code page isn't implemented.
  -5  //ESD_STOP           Stopped from AKDN_SAVEDOCUMENT_START.
  -6  //ESD_STREAMOUT      Error in EM_STREAMOUT.

Example:
  var hWndEdit=AkelPad.GetEditWnd();
  var nResult=AkelPad.SaveFile(hWndEdit, "C:\\MyFile.txt");


AkelPad.SystemFunction (+ActiveX)
_________________________________

Create system function object.

  SystemFunction();

Return Value
  Object. System function object.

Example:
  var oSys=AkelPad.SystemFunction();


AkelPad.SystemFunction().AddParameter (+ActiveX)
________________________________________________

Add function parameter.

  AddParameter(vParameter);

Arguments
  vParameter
    Function parameter.

Return Value
  Zero.

Example:
  See AkelPad.SystemFunction().Call old syntax example.


AkelPad.SystemFunction().Call (+ActiveX)
________________________________________

Call system function.

  Call(vDllFunction[, ...]);

Arguments
  vDllFunction
    Function name in string format "Dll::Function" or function address in number format.
  ...
    Function parameters, must be integer, pointer or string.
    String parameter: in Windows 95/98/Me - Ansi string,
                      in Windows NT/2000/XP - Unicode string.

Return Value
  Number. Call result.

Example (new syntax):
  var hMainWnd=AkelPad.GetMainWnd();
  var oSys=AkelPad.SystemFunction();
  oSys.Call("user32::ShowWindow", hMainWnd, 6 /*SW_MINIMIZE*/);

Example (old syntax):
  var hMainWnd=AkelPad.GetMainWnd();
  var oSys=AkelPad.SystemFunction();
  oSys.AddParameter(hMainWnd);
  oSys.AddParameter(6 /*SW_MINIMIZE*/);
  oSys.Call("user32::ShowWindow");


AkelPad.SystemFunction().GetLastError (+ActiveX)
________________________________________________

Get call function last error.

  GetLastError();

Return Value
  Number. Call function last error.

Example:
  var hMainWnd=AkelPad.GetMainWnd();
  var oSys=AkelPad.SystemFunction();
  var nError;
  oSys.Call("user32::ShowWindow", hMainWnd, 6 /*SW_MINIMIZE*/);
  nError=oSys.GetLastError();


AkelPad.SystemFunction().RegisterCallback (+ActiveX)
____________________________________________________

Register callback function.

  RegisterCallback(lpCallback[, nArgCount]);

Arguments
  lpCallback
    Callback function.
  nArgCount
    Argument count in callback function. Can be omitted in JScript, but must be specified in VBScript.

Remarks
  The maximum number of working callback functions at the same time is 30.

Return Value
  Object. Pointer on function.

Example (callback under JScript):
  var oSys=AkelPad.SystemFunction();
  var lpEnumWindowsCallback;
  var nStopAfter=3;

  if (lpEnumWindowsCallback=oSys.RegisterCallback(EnumWindowsProc))
  {
    oSys.Call("user32::EnumWindows", lpEnumWindowsCallback, 0);
    oSys.UnregisterCallback(lpEnumWindowsCallback);
  }

  function EnumWindowsProc(hWnd, lParam)
  {
    //Convert hWnd to hex
    if (hWnd < 0) hWnd=(0xFFFFFFFF + 1) + hWnd;
    hWnd="0x" + hWnd.toString(16).toUpperCase();

    //Show parameters
    WScript.Echo("hWnd=" + hWnd + "; lParam=" + lParam);

    if (--nStopAfter <= 0)
      return false;
    else
      return true;
  }

Example (callback under VBScript):
  set oSys=AkelPad.SystemFunction()
  nStopAfter=3

  set lpEnumWindowsCallback = oSys.RegisterCallback (GetRef("EnumWindowsProc"), 2)
  oSys.Call "user32::EnumWindows", lpEnumWindowsCallback, 0
  oSys.UnregisterCallback lpEnumWindowsCallback

  Function EnumWindowsProc(hWnd, lParam)
    'Convert hWnd to hex
    hWnd="0x" & Hex(hWnd)

    'Show parameters
    WScript.Echo "hWnd=" & hWnd & "; lParam=" & lParam

    nStopAfter = nStopAfter - 1
    if nStopAfter <= 0 Then
      EnumWindowsProc = 0
    else
      EnumWindowsProc = 1
    end if
  End Function


AkelPad.SystemFunction().UnregisterCallback (+ActiveX)
______________________________________________________

Remove callback function registration.

  UnregisterCallback(oFunction);

Arguments
  oFunction
    Pointer on function.

Return Value
  Zero.

Example:
  See RegisterCallback example.


AkelPad.MemAlloc (+ActiveX)
___________________________

Allocate memory.

  MemAlloc(nSize);

Arguments
  nSize
    Size in bytes to allocate.

Return Value
  Number. Pointer to a buffer.

Example:
  var hMainWnd=AkelPad.GetMainWnd();
  var oSys=AkelPad.SystemFunction();
  var pMessage="MyMessage";
  var pCaption="MyCaption";
  var lpMessageBuffer;
  var lpCaptionBuffer;

  if (lpMessageBuffer=AkelPad.MemAlloc(256))
  {
    AkelPad.MemCopy(lpMessageBuffer, pMessage.substr(0, 255), 0 /*DT_ANSI*/);

    if (lpCaptionBuffer=AkelPad.MemAlloc(256))
    {
      AkelPad.MemCopy(lpCaptionBuffer, pCaption.substr(0, 255), 0 /*DT_ANSI*/);

      oSys.Call("user32::MessageBoxA", hMainWnd, lpMessageBuffer, lpCaptionBuffer, 64 /*MB_ICONINFORMATION*/);

      AkelPad.MemFree(lpCaptionBuffer);
    }
    AkelPad.MemFree(lpMessageBuffer);
  }


AkelPad.MemCopy (+ActiveX)
__________________________

Copy memory.

  MemCopy(lpPointer, vData, nType[, nLength]);

Arguments
  lpPointer
    Pointer to a buffer.
  vData
    Data to copy.
  nType
    Type of the vData parameter:
    0  //DT_ANSI        Copy Ansi string to memory.
    1  //DT_UNICODE     Copy Unicode string to memory.
    2  //DT_QWORD       Copy QWORD number to memory on x64 or DWORD number on x86.
    3  //DT_DWORD       Copy DWORD number to memory.
    4  //DT_WORD        Copy WORD number to memory.
    5  //DT_BYTE        Copy BYTE number to memory.
  nLength
    String length. If -1, all string is copied (default is -1). For DT_ANSI and DT_UNICODE.

Return Value
  Number. Bytes copied.

Example:
  See MemAlloc example.


AkelPad.MemRead (+ActiveX)
__________________________

Read memory.

  MemRead(lpPointer, nType[, nLength]);

Arguments
  lpPointer
    Pointer to a buffer.
  nType
    0  //DT_ANSI        Read Ansi string from memory.
    1  //DT_UNICODE     Read Unicode string from memory.
    2  //DT_QWORD       Read QWORD number from memory on x64 or DWORD number on x86.
    3  //DT_DWORD       Read DWORD number from memory.
    4  //DT_WORD        Read WORD number from memory.
    5  //DT_BYTE        Read BYTE number from memory.
  nLength
    String length. If -1, string is terminated with NULL symbol (default is -1). For DT_ANSI and DT_UNICODE.

Return Value
  String or number.

Example:
  var oSys=AkelPad.SystemFunction();
  var lpDirBuffer;
  var pWinDir;

  if (lpDirBuffer=AkelPad.MemAlloc(256))
  {
    oSys.Call("kernel32::GetWindowsDirectoryA", lpDirBuffer, 256);
    pWinDir=AkelPad.MemRead(lpDirBuffer, 0 /*DT_ANSI*/);

    AkelPad.MemFree(lpDirBuffer);
  }


AkelPad.MemStrPtr (+ActiveX)
____________________________

Get pointer from a string or to a string.

  MemStrPtr(pString[, bConvert]);

Arguments
  pString
    Constant string or string object.
  bConvert
    true  get pointer from the pString, ie convert pString contents in number.
    false get pointer to the pString (by default).

Return Value
  Number. Pointer.

Example:
  var hMainWnd=AkelPad.GetMainWnd();
  AkelPad.SendMessage(hMainWnd, 1206 /*AKD_GOTOW*/, 0x1 /*GT_LINE*/, AkelPad.MemStrPtr("10:3"));


AkelPad.MemPtrStr (+ActiveX)
____________________________

Get string representation of a pointer.

  MemPtrStr(lpPointer);

Arguments
  lpPointer
    Any pointer.

Return Value
  String. String representation of a pointer.

Example:
  var hMainWnd=AkelPad.GetMainWnd();
  WScript.Echo(AkelPad.MemPtrStr(hMainWnd));


AkelPad.MemFree (+ActiveX)
__________________________

Free memory.

  MemFree(lpPointer);

Arguments
  lpPointer
    Pointer to a buffer.

Return Value
  Zero.

Example:
  See MemAlloc example.


AkelPad.DebugJIT (+ActiveX)
___________________________

Breakpoint. Causes break into the debugger.

  DebugJIT();

Return Value
  Zero.


AkelPad.Debug (+ActiveX)
________________________

Debug memory usage.

  Debug([dwType]);

Arguments
  dwType
    0x01  //DBG_MEMREAD    Debug memory read.
    0x02  //DBG_MEMWRITE   Debug memory write.
    0x04  //DBG_MEMFREE    Debug memory free.
    0x08  //DBG_MEMLEAK    Debug memory leak.
    0x10  //DBG_SYSCALL    Debug system function call.
          //Default is 0x1f  (DBG_MEMREAD|DBG_MEMWRITE|DBG_MEMFREE|DBG_MEMLEAK|DBG_SYSCALL).

Return Value
  Previous dwType value.

Example:
  var lpBuffer;

  AkelPad.Debug();

  if (lpBuffer=AkelPad.MemAlloc(2))
  {
    AkelPad.MemCopy(lpBuffer, 123, 3 /*DT_DWORD*/);

    AkelPad.MemFree(lpBuffer);
  }


AkelPad.VarType (+ActiveX)
__________________________

Retrieve variable type.

  VarType(vData);

Arguments
  vData
    Variable.

Return Value
  Number. Type (VARTYPE) of variable (VARIANT).
       0 //VT_EMPTY
       1 //VT_NULL
       2 //VT_I2
       3 //VT_I4
       4 //VT_R4
       5 //VT_R8
       6 //VT_CY
       7 //VT_DATE
       8 //VT_BSTR
       9 //VT_DISPATCH
      10 //VT_ERROR
      11 //VT_BOOL
      12 //VT_VARIANT
      13 //VT_UNKNOWN
      14 //VT_DECIMAL
      16 //VT_I1
      17 //VT_UI1
      18 //VT_UI2
      19 //VT_UI4
      20 //VT_I8
      21 //VT_UI8
      22 //VT_INT
      23 //VT_UINT
      24 //VT_VOID
      25 //VT_HRESULT
      26 //VT_PTR
      27 //VT_SAFEARRAY
      28 //VT_CARRAY
      29 //VT_USERDEFINED
      30 //VT_LPSTR
      31 //VT_LPWSTR
      36 //VT_RECORD
      37 //VT_INT_PTR
      38 //VT_UINT_PTR
      64 //VT_FILETIME
      65 //VT_BLOB
      66 //VT_STREAM
      67 //VT_STORAGE
      68 //VT_STREAMED_OBJECT
      69 //VT_STORED_OBJECT
      70 //VT_BLOB_OBJECT
      71 //VT_CF
      72 //VT_CLSID
      73 //VT_VERSIONED_STREAM
  0x0fff //VT_BSTR_BLOB
  0x1000 //VT_VECTOR
  0x2000 //VT_ARRAY
  0x4000 //VT_BYREF
  0x8000 //VT_RESERVED
  0xffff //VT_ILLEGAL
  0x0fff //VT_ILLEGALMASKED
  0x0fff //VT_TYPEMASK

Example:
  var pString="123";
  WScript.Echo("" + AkelPad.VarType(pString));


AkelPad.VarDispatch (+ActiveX)
______________________________

Get IDispatch object of a pointer.

  VarDispatch(lpPointer);

Arguments
  lpPointer
    Pointer to IDispatch object.

Return Value
  Object. IDispatch object.

Example:
  var oIE=new ActiveXObject("InternetExplorer.Application");
  //IDispatch -> pointer
  var nIE=_PtrAdd(oIE, 0);
  //Pointer -> IDispatch
  var oReturnIE=AkelPad.VarDispatch(nIE);


AkelPad.GetArgLine
__________________

Retrieve argument line.

  GetArgLine([bNoEncloseQuotes]);

Arguments
  bNoEncloseQuotes
    true   Exclude enclose quotes (by default).
    false  Leave enclose quotes.

Return Value
  String. Argument line.

Example:
  var pArgLine;

  if (pArgLine=AkelPad.GetArgLine(0))
    WScript.Echo(pArgLine);


AkelPad.GetArgValue
___________________

Retrieve argument value by name.

  GetArgValue(pArgName, vDefault);

Arguments
  pArgName
    Argument name.
  vDefault
    Default value. Set if specified argument name not found.

Return Value
  Argument value. Type inherited from default value.

Example:
  //Script was invoked as follows:
  //Call("Scripts::Main", 1, "MyScript.js", `-ArgName1=0.01 -ArgName2="Value2" /ArgName3=0x10`)

  //Get values 0.01, Value2, 0x10 by names ArgName1, ArgName2, ArgName3.
  var nArg1=AkelPad.GetArgValue("ArgName1", 0);
  var pArg2=AkelPad.GetArgValue("ArgName2", "");
  var nArg3=AkelPad.GetArgValue("ArgName3", 0);

  WScript.Echo("VarType=" + AkelPad.VarType(nArg1) + "; ArgValue=" + nArg1 + "\r" +
               "VarType=" + AkelPad.VarType(pArg2) + "; ArgValue=" + pArg2 + "\r" +
               "VarType=" + AkelPad.VarType(nArg3) + "; ArgValue=" + nArg3 + "\r");


AkelPad.ScriptSettings
______________________

Create script settings object.

  ScriptSettings();

Return Value
  Object. Script settings object.

Example:
  var oSet=AkelPad.ScriptSettings();


AkelPad.ScriptSettings().Begin
______________________________

Begin settings operations.

  Begin(pScriptBaseName, nFlags);

Arguments
  pScriptBaseName
    Script name without extension. If "", use current script name.
  nFlags
    0x01 //POB_READ     Begins read options.
    0x02 //POB_SAVE     Begins save options.
    0x04 //POB_CLEAR    Begins new save options (POB_SAVE|POB_CLEAR).
    0x20 //POB_PLUGS    Plugin settings, pScriptBaseName - plugin name without extension.
    0x40 //POB_PROGRAM  Program settings, pScriptBaseName - ignored.

Return Value
  Number. Settings handle.

Example:
  See Read, Write and Delete examples.


AkelPad.ScriptSettings().Read
_____________________________

Read option.

  Read(vOptionName, nType[, vDefault]);

Arguments
  vOptionName
    Option name as string or index as number.
  nType
    1   //PO_DWORD         Read 32-bit number (DWORD).
    2   //PO_BINARY        Read binary data. Returned pointer to the binary data, which must be released with AkelPad.MemFree.
    3   //PO_STRING        Read string.
    11  //PO_ENUM          Retrieve option name by index. Index passed in vOptionName.
    20  //PO_BINARYSTRING  Read string (usually multiline), which was saved as binary data.
    21  //PO_BINARYSIZE    Retrieve binary data size in bytes.
  vDefault
    Default data.

Return Value
  String or number.

Example (read script options):
  var oSet=AkelPad.ScriptSettings();

  if (oSet.Begin("", 0x1 /*POB_READ*/))
  {
    pString=oSet.Read("String", 3 /*PO_STRING*/);
    bMultiline=oSet.Read("Multiline", 1 /*PO_DWORD*/);
    oSet.End();
  }

Example (read plugin options):
  var oSet=AkelPad.ScriptSettings();
  var pText="";

  if (oSet.Begin("Toolbar", 0x21 /*POB_READ|POB_PLUGS*/))
  {
    pText=oSet.Read("ToolBarText", 10 /*PO_BINARYSTRING*/);
    oSet.End();
  }
  WScript.Echo(pText.substr(0,500));

Example (enumerate plugin option names):
  var hMainWnd=AkelPad.GetMainWnd();
  var oSet=AkelPad.ScriptSettings();
  var pOption;
  var nIndex;

  if (oSet.Begin("Scripts", 0x21 /*POB_READ|POB_PLUGS*/))
  {
    for (nIndex=0; ; ++nIndex)
    {
      if ((pOption=oSet.Read(nIndex, 11 /*PO_ENUM*/)) == undefined)
        break;
      if (AkelPad.MessageBox(hMainWnd, pOption + "\n\nFind next?", WScript.ScriptName, 4 /*MB_YESNO*/) == 7 /*IDNO*/)
        break;
    }
    oSet.End();
  }


AkelPad.ScriptSettings().Write
______________________________

Write option.

  Write(pOptionName, nType, vData[, nDataSize]);

Arguments
  pOptionName
    Option name.
  nType
    1   //PO_DWORD   Write 32-bit number (DWORD).
    2   //PO_BINARY  Write binary data in any form.
    3   //PO_STRING  Write string.
  vData
    Data to write.
  nDataSize
    Data size in bytes (default is -1).

Return Value
  Number. Written data size in bytes.

Example:
  var oSet=AkelPad.ScriptSettings();

  if (oSet.Begin("", 0x2 /*POB_SAVE*/))
  {
    oSet.Write("String", 3 /*PO_STRING*/, "Str1");
    oSet.Write("Sensitive", 1 /*PO_DWORD*/, true);
    oSet.End();
  }


AkelPad.ScriptSettings().Delete
_______________________________

Delete option.

  Delete(pOptionName);

Arguments
  pOptionName
    Option name.

Return Value
  true   success.
  false  failed.

Example:
  var oSet=AkelPad.ScriptSettings();

  if (oSet.Begin("", 0x2 /*POB_SAVE*/))
  {
    oSet.Delete("String");
    oSet.Delete("Sensitive");
    oSet.End();
  }


AkelPad.ScriptSettings().End
____________________________

End settings operations.

  End();

Return Value
  true   success.
  false  failed.

Example:
  See Read, Write and Delete examples.


AkelPad.WindowRegisterClass (+ActiveX)
______________________________________

Register window class.

  WindowRegisterClass(pClassName[, ...]);

Arguments
  pClassName
    Class name to register.
  ...
    Message filter. Will come only specified messages. If not specified, all messages will come.

Return Value
  Number. Class atom that uniquely identifies the class being registered.

Example (JScript):
  var hMainWnd=AkelPad.GetMainWnd();
  var oSys=AkelPad.SystemFunction();
  var hInstanceDLL=AkelPad.GetInstanceDll();
  var hWndDialog;

  if (hMainWnd)
  {
    if (AkelPad.WindowRegisterClass("NewClass"))
    {
      //Create dialog
      hWndDialog=oSys.Call("user32::CreateWindowEx" + _TCHAR,
                           0,                //dwExStyle
                           "NewClass",       //lpClassName
                           0,                //lpWindowName
                           0x90CA0000,       //WS_VISIBLE|WS_POPUP|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX
                           0,                //x
                           0,                //y
                           351,              //nWidth
                           179,              //nHeight
                           hMainWnd,         //hWndParent
                           0,                //ID
                           hInstanceDLL,     //hInstance
                           DialogCallback);  //Script function callback. To use it class must be registered by WindowRegisterClass.

      if (hWndDialog)
      {
        //Disable main window, to make dialog modal
        oSys.Call("user32::EnableWindow", hMainWnd, false);

        //Message loop
        AkelPad.WindowGetMessage();
      }
      AkelPad.WindowUnregisterClass("NewClass");
    }
  }

  function DialogCallback(hWnd, uMsg, wParam, lParam)
  {
    if (uMsg == 1 /*WM_CREATE*/)
    {
    }
    else if (uMsg == 256 /*WM_KEYDOWN*/)
    {
      if (wParam == 27 /*VK_ESCAPE*/)
      {
        //Escape key pushes Cancel button
        oSys.Call("user32::PostMessage" + _TCHAR, hWndDialog, 273 /*WM_COMMAND*/, 2 /*IDCANCEL*/, 0);
      }
    }
    else if (uMsg == 273 /*WM_COMMAND*/)
    {
      if ((wParam & 0xffff) == 2 /*IDCANCEL*/)
      {
        oSys.Call("user32::PostMessage" + _TCHAR, hWndDialog, 16 /*WM_CLOSE*/, 0, 0);
      }
    }
    else if (uMsg == 16 /*WM_CLOSE*/)
    {
      //Enable main window
      oSys.Call("user32::EnableWindow", hMainWnd, true);

      //Destroy dialog
      oSys.Call("user32::DestroyWindow", hWnd);
    }
    else if (uMsg == 2 /*WM_DESTROY*/)
    {
      //Exit message loop
      oSys.Call("user32::PostQuitMessage", 0);
    }
    return 0;
  }


Example (VBScript):
  'Variables
  hMainWnd=AkelPad.GetMainWnd()
  hInstanceDLL=AkelPad.GetInstanceDll()
  set oSys=AkelPad.SystemFunction()
  set lpCallbackPtr=GetRef("DialogCallback")
  hWndDialog=0

  'Constants
  Const WM_CREATE=1
  Const WM_KEYDOWN=256
  Const WM_COMMAND=273
  Const WM_CLOSE=16
  Const WM_DESTROY=2
  Const VK_ESCAPE=27
  Const IDCANCEL=2

  if vbPtrMath(hMainWnd, "!=", 0) then
    if AkelPad.WindowRegisterClass("NewClass") then

      'Create dialog WS_VISIBLE|WS_POPUP|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX
      hWndDialog=oSys.Call("user32::CreateWindowEx" & vbTCHAR, 0, "NewClass", 0, &H90CA0000, 0, 0, 351, 179, hMainWnd, 0, hInstanceDLL, lpCallbackPtr)

      if vbPtrMath(hWndDialog, "!=", 0) then
        'Disable main window, to make dialog modal
        oSys.Call "user32::EnableWindow", hMainWnd, false

        'Message loop
        AkelPad.WindowGetMessage()
      end if

      AkelPad.WindowUnregisterClass "NewClass"
    end if
  end if

  Function DialogCallback(hWnd, uMsg, wParam, lParam)
    if uMsg = WM_CREATE then
    elseif uMsg = WM_KEYDOWN then
      if wParam = VK_ESCAPE then
        'Escape key pushes Cancel button
        oSys.Call "user32::PostMessage" & vbTCHAR, hWndDialog, WM_COMMAND, IDCANCEL, 0
      end if
    elseif uMsg = WM_COMMAND then
      if (wParam And &Hffff) = IDCANCEL then
        oSys.Call "user32::PostMessage" & vbTCHAR, hWndDialog, WM_CLOSE, 0, 0
      end if
    elseif uMsg = WM_CLOSE then
      'Enable main window
      oSys.Call "user32::EnableWindow", hMainWnd, true

      'Destroy dialog
      oSys.Call "user32::DestroyWindow", hWnd
    elseif uMsg = WM_DESTROY then
      'Exit message loop
      oSys.Call "user32::PostQuitMessage", 0
    end if
    DialogCallback=0
  End Function


AkelPad.WindowUnregisterClass (+ActiveX)
________________________________________

Unregister window class.

  WindowUnregisterClass(pClassName);

Arguments
  pClassName
    Class name to unregister.

Return Value
  true   success.
  false  failed.

Example:
  See WindowRegisterClass example.


AkelPad.WindowRegisterDialog (+ActiveX)
_______________________________________

Register dialog for message loop. Used if dialog created without WindowRegisterClass.

  WindowRegisterDialog(hWnd);

Arguments
  hWnd
    Dialog handle.

Return Value
  true   success.
  false  dialog already registered.

Example:
  var hMainWnd=AkelPad.GetMainWnd();
  var oSys=AkelPad.SystemFunction();
  var hInstanceDLL=AkelPad.GetInstanceDll();
  var hGuiFont=oSys.Call("gdi32::GetStockObject", 17 /*DEFAULT_GUI_FONT*/);
  var hWndModeless;
  var hWndTestButton;
  var IDC_TEST_BUTTON=10001;

  //Open "Find" dialog
  if (hWndModeless=AkelPad.SendMessage(hMainWnd, 1275 /*AKD_GETMODELESS*/, 0, 0))
    AkelPad.SendMessage(hWndModeless, 273 /*WM_COMMAND*/, 2 /*IDCANCEL*/, 0);
  AkelPad.Command(4158 /*IDM_EDIT_FIND*/);
  hWndModeless=AkelPad.SendMessage(hMainWnd, 1275 /*AKD_GETMODELESS*/, 0, 0);

  //Create test button
  hWndTestButton=oSys.Call("user32::CreateWindowEx" + _TCHAR,
                         0,               //dwExStyle
                         "BUTTON",        //lpClassName
                         0,               //lpWindowName
                         0x50010000,      //WS_VISIBLE|WS_CHILD|WS_TABSTOP
                         294,             //x
                         80,              //y
                         81,              //nWidth
                         23,              //nHeight
                         hWndModeless,    //hWndParent
                         IDC_TEST_BUTTON, //ID
                         hInstanceDLL,    //hInstance
                         0);              //lpParam
  //Set font and text
  SetWindowFontAndText(hWndTestButton, hGuiFont, "Test");

  //Subclass dialog
  if (AkelPad.WindowSubClass(hWndModeless, DialogCallback, 273 /*WM_COMMAND*/, 2 /*WM_DESTROY*/))
  {
    //Register dialog for message loop
    AkelPad.WindowRegisterDialog(hWndModeless);

    //Message loop
    AkelPad.WindowGetMessage();

    //Unregister and unsubclass
    AkelPad.WindowUnregisterDialog(hWndModeless);
    AkelPad.WindowUnsubClass(hWndModeless);
  }

  function DialogCallback(hWnd, uMsg, wParam, lParam)
  {
    if (uMsg == 273) //WM_COMMAND
    {
      if (LOWORD(wParam) == IDC_TEST_BUTTON)
      {
        oSys.Call("user32::SetWindowText" + _TCHAR, hWnd, "Test " + oSys.Call("kernel32::GetTickCount"));
      }
    }
    else if (uMsg == 2) //WM_DESTROY
    {
      //Exit message loop
      oSys.Call("user32::PostQuitMessage", 0);
    }
    return 0;
  }

  function SetWindowFontAndText(hWnd, hFont, pText)
  {
    AkelPad.SendMessage(hWnd, 48 /*WM_SETFONT*/, hFont, 1);
    oSys.Call("user32::SetWindowText" + _TCHAR, hWnd, pText);
  }

  function LOWORD(dwNumber)
  {
    return (dwNumber & 0xffff);
  }


AkelPad.WindowUnregisterDialog (+ActiveX)
_________________________________________

Unregister dialog.

  WindowUnregisterDialog(hWnd);

Arguments
  hWnd
    Dialog handle.

Return Value
  true   success.
  false  dialog not registered.

Example:
  See WindowRegisterDialog example.


AkelPad.CreateDialog (+ActiveX)
_______________________________

Create dialog.

  CreateDialog(nExStyle, pClassName, pTitle, nStyle, x, y, nWidth, nHeight, hWndParent, lParam[, nFlags][, hMenu][, hInstance][, pFaceName][, nFontStyle][, nPointSize], "|",
               nExStyle1, pClassName1, pTitle1, nStyle1, x1, y1, nWidth1, nHeight1, nId1[, lParam1], "|",
               nExStyle2, pClassName2, pTitle2, nStyle2, x2, y2, nWidth2, nHeight2, nId2[, lParam2], "|",
               [...]);

Arguments
  nExStyle
    Extended window style. See description of CreateWindowEx in MSDN.
  pClassName
    Class name registered with AkelPad.WindowRegisterClass.
  pTitle
    Dialog title.
  nStyle
    Window style. See description of CreateWindowEx in MSDN.
  x
    Horizontal dialog position in screen coordinates.
  y
    Vertical dialog position in screen coordinates.
  nWidth
    Dialog width.
  nHeight
    Dialog height.
  hWndParent
    Parent window of the dialog being created.
  lParam
    Pointer to the dialog procedure.
  nFlags
    0x1  //CDF_MODAL   Create modal dialog. If not specified, created modeless dialog, which require AkelPad.WindowGetMessage.
    0x2  //CDF_PIXELS  Coordinates specified in pixels for 96 DPI. If not specified, coordinates specified in dialog units,
         //            which depend on dialog font sizes.
         //Default is 0x0.
  hMenu
    Specifies the ordinal value of a menu resource in an executable file or string that specifies the name of a menu resource in an executable file. If zero, not used (default).
  hInstance
    Instance handle of the module to be associated with the window. If zero, AkelPad.GetInstanceDll handle will be used (default).
  pFaceName
    Font face, for example, "Courier". If "", system font for dialogs is used (default).
    Processed only, when nStyle has 0x40 /*DS_SETFONT*/ flag.
  nFontStyle
    0 ignored (default).
    1 normal.
    2 bold.
    3 italic.
    4 bold italic.
    Processed only, when nStyle has 0x40 /*DS_SETFONT*/ flag.
  nPointSize
    Font size. Unchanged, if 0 (default).
    Processed only, when nStyle has 0x40 /*DS_SETFONT*/ flag.
  "|"
    Indicates the end of the dialog parameters and the start of controls parameters.
  nExStyle1
    Extended window style. See description of CreateWindowEx in MSDN.
  pClassName1
    Class name, example, "BUTTON". See description of CreateWindowEx in MSDN.
  pTitle1
    Control text.
  nStyle1
    Control style. See description of CreateWindowEx in MSDN.
  x1
    Horizontal control position in client coordinates.
  y1
    Vertical control position in client coordinates.
  nWidth1
    Control width.
  nHeight1
    Control height
  nId1
    Control identifier.
  lParam1
    The creation data. First word indicates the size, in bytes, of the creation data (including the size word).
    Control receives a pointer to this data in the lParam parameter of the WM_CREATE message. If zero, not used (default).
  "|"
    Indicates the end of the control parameters.
  ...
    Arguments for the next control.

Return Value
  If nFlags not contain CDF_MODAL, then return value is dialog handle.
  If nFlags contain CDF_MODAL, then return value is value passed to "user32::EndDialog".

Example:
  var hMainWnd=AkelPad.GetMainWnd();
  var oSys=AkelPad.SystemFunction();
  var hWndDialog=0;
  var wCommand;
  var dwFlags=0x2 /*CDF_PIXELS*/;

  //Control IDs
  var IDC_BUTTON1=1001;
  var IDC_BUTTON2=1002;
  var IDC_EDIT=1003;

  if (AkelPad.WindowRegisterClass("My Class"))
  {
    AkelPad.CreateDialog(0, "My Class", "My Title",  0x90ca0040 /*DS_SETFONT|WS_VISIBLE|WS_POPUP|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX*/, 10, 10, 300, 200, hMainWnd, DialogCallback, dwFlags, "|",
                         0, "BUTTON", "Button text 1", 0x50010001 /*WS_VISIBLE|WS_CHILD|WS_TABSTOP|BS_DEFPUSHBUTTON*/, 10, 10, 200, 20, IDC_BUTTON1, "|",
                         0, "BUTTON", "Button text 2", 0x50010000 /*WS_VISIBLE|WS_CHILD|WS_TABSTOP*/, 10, 50, 200, 20, IDC_BUTTON2, "|",
                         0, "EDIT", "Edit text 3", 0x50010000 /*WS_VISIBLE|WS_CHILD|WS_TABSTOP*/, 10, 90, 200, 20, IDC_EDIT);

    if (hWndDialog && !(dwFlags & 0x1 /*CDF_MODAL*/))
    {
      AkelPad.ScriptNoMutex();
      AkelPad.WindowGetMessage(0x4 /*WGM_KEYDOWNUP*/);
    }
    AkelPad.WindowUnregisterClass("My Class");
  }

  function DialogCallback(hWnd, uMsg, wParam, lParam)
  {
    if (uMsg == 0x110 /*WM_INITDIALOG*/)
    {
      hWndDialog=hWnd;
    }
    else if (uMsg == 273 /*WM_COMMAND*/)
    {
      wCommand=LOWORD(wParam);

      if (wCommand == IDC_BUTTON1 ||
          wCommand == IDC_BUTTON2)
      {
        AkelPad.MessageBox(hWnd, "Button=" + wCommand, WScript.ScriptName, 0 /*MB_OK*/);
      }
      else if (wCommand == 2 /*IDCANCEL*/)
      {
        //Destroy dialog
        if (!(dwFlags & 0x1 /*CDF_MODAL*/))
        {
          //Exit message loop
          oSys.Call("user32::PostQuitMessage", 0);

          oSys.Call("user32::DestroyWindow", hWnd);
        }
        else oSys.Call("user32::EndDialog", hWnd, 0);
      }
    }
    return 0;
  }

  function LOWORD(dwNumber)
  {
    return (dwNumber & 0xffff);
  }


AkelPad.WindowGetMessage (+ActiveX)
___________________________________

Process thread messages (message loop).

  WindowGetMessage([nFlags]);

Arguments
  nFlags
    0x1  //WGM_ENABLE    Set in any case.
    0x2  //WGM_NOKEYSEND Don't send key messages to dialog from children windows
         //              (WM_KEYDOWN, WM_KEYUP, WM_CHAR, WM_DEADCHAR, WM_SYSKEYDOWN, WM_SYSKEYUP, WM_SYSCHAR, WM_SYSDEADCHAR, WM_UNICHAR).
    0x4  //WGM_KEYDOWNUP Send only WM_KEYDOWN, WM_KEYUP messages to dialog from children windows.
         //Default is 0x0.

Return Value
  Zero.

Example:
  See WindowRegisterClass example.


AkelPad.WindowSubClass (+ActiveX)
_________________________________

Install capture for window messages.

  WindowSubClass(hHandle, lpFunction[, ...]);

Arguments
  hHandle
    Window handle or one of the following values:
      1   //WSC_MAINPROC   Install capture for main window messages.
      2   //WSC_EDITPROC   Install capture for all edit windows messages.
      3   //WSC_FRAMEPROC  Install capture for all MDI frames messages.
  lpFunction
    Function with 4 arguments, in which messages will come.
  ...
    Message filter. Will come only specified messages. If not specified, all messages will come.

Return Value
  Number. Capture handle.

Example:
  var oSys=AkelPad.SystemFunction();
  var hSubClass;
  var nSelStart;

  if (hSubClass=AkelPad.WindowSubClass(2 /*WSC_EDITPROC*/, EditCallback, 258 /*WM_CHAR*/))
  {
    //Message loop
    AkelPad.WindowGetMessage();

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

  function EditCallback(hWnd, uMsg, wParam, lParam)
  {
    if (uMsg == 258 /*WM_CHAR*/)
    {
      if (String.fromCharCode(wParam) == "q")
      {
        AkelPad.MessageBox(0, "Key \"" + String.fromCharCode(wParam) + "\" is pressed. Exiting script...", "", 0);

        //Exit message loop
        oSys.Call("user32::PostQuitMessage", 0);
      }
      else
      {
        //First do default processing
        AkelPad.WindowNextProc(hSubClass, hWnd, uMsg, wParam, lParam);

        //After default processing we can select inserted character
        nSelStart=AkelPad.GetSelStart();
        AkelPad.SetSel(nSelStart - 1, nSelStart);

        //We already do default processing, so skip it
        AkelPad.WindowNoNextProc(hSubClass);
        return 0;
      }
    }
  }


AkelPad.WindowNextProc (+ActiveX)
_________________________________

Send message to the next procedure in chain.

  WindowNextProc(hSubClass, hWnd, nMessage, wParam, lParam);

Arguments
  hSubClass
    Capture handle.
  hWnd
    Handle to the window whose window procedure will receive the message.
  nMessage
    Specifies the message to be sent.
  wParam
    Specifies additional message-specific information.
  lParam
    Specifies additional message-specific information.

Return Value
  Number. Result returned by next procedure.

Example:
  See WindowSubClass example.


AkelPad.WindowNoNextProc (+ActiveX)
___________________________________

Prevent sending current message to the next procedure in chain.

  WindowNoNextProc(hSubClass);

Arguments
  hSubClass
    Capture handle.

Return Value
  Zero.

Example:
  See WindowSubClass example.


AkelPad.WindowUnsubClass (+ActiveX)
___________________________________

Remove capture for window messages.

  WindowUnsubClass(hHandle);

Arguments
  hHandle
    Window handle or one of the following values:
      1   //WSC_MAINPROC   Remove capture of main window messages.
      2   //WSC_EDITPROC   Remove capture of edit windows messages.
      3   //WSC_FRAMEPROC  Remove capture of MDI frames messages.

Return Value
  Zero.

Example:
  See WindowSubClass example.


AkelPad.ThreadHook (+ActiveX)
_____________________________

Install hook for thread.

  ThreadHook(nId, lpFunction, nThreadId[, ...]);

Arguments
  nId
    See first parameter of SetWindowsHookEx in MSDN.
  lpFunction
    Function with 3 arguments, which will be called.
  nThreadId
    Thread identifier. Global hook installing is not supported.
  ...
    Message filter. Will come only specified messages. If not specified, all messages will come.
    nId must be one of the following values: WH_CALLWNDPROC, WH_CALLWNDPROCRET, WH_GETMESSAGE, WH_MSGFILTER, WH_SYSMSGFILTER.

Return Value
  Number. Hook handle.

Remarks
  The maximum number of installed hooks at the same time is 30.

Example:
  var hMainWnd=AkelPad.GetMainWnd();
  var oSys=AkelPad.SystemFunction();
  var dwMainThreadID=oSys.Call("user32::GetWindowThreadProcessId", hMainWnd, 0);
  var hHook;

  if (hHook=AkelPad.ThreadHook(3 /*WH_GETMESSAGE*/, HookCallback, dwMainThreadID, 0x100 /*WM_KEYDOWN*/))
  {
    //Message loop
    AkelPad.WindowGetMessage();

    AkelPad.ThreadUnhook(hHook);
  }

  function HookCallback(nCode, wParam, lParam)
  {
    var uMsg=AkelPad.MemRead(_PtrAdd(lParam, _X64?8:4) /*offsetof(MSG, message)*/, 3 /*DT_DWORD*/);

    if (uMsg == 0x100 /*WM_KEYDOWN*/)
    {
      wParam=AkelPad.MemRead(_PtrAdd(lParam, _X64?16:8) /*offsetof(MSG, wParam)*/, 2 /*DT_QWORD*/);

      AkelPad.MessageBox(0, "Key \"" + String.fromCharCode(wParam) + "\" with code \"" + wParam + "\" is pressed.", "", 0);

      //Exit message loop
      oSys.Call("user32::PostQuitMessage", 0);
    }
  }


AkelPad.ThreadUnhook (+ActiveX)
_______________________________

Remove hook from thread.

  ThreadUnhook(hHandle);

Arguments
  hHandle
    Hook handle.

Return Value
  Zero.

Example:
  See ThreadHook example.


AkelPad.ScriptNoMutex
_____________________

Change synchronization object.

  ScriptNoMutex([nUnlockType]);

Arguments
  nUnlockType
    0x01  //ULT_UNLOCKSCRIPTSQUEUE   Allow other scripts running with this script at the same time (by default).
    0x02  //ULT_UNLOCKPROGRAMTHREAD  Unlock main thread from waiting this script. Only if script is called with external call with code 2.
    0x04  //ULT_LOCKMULTICOPY        Deny execution of the multiple script copies. By default execution is not denied.
    0x08  //ULT_UNLOCKMULTICOPY      Allow execution of the multiple script copies.
    0x10  //ULT_LOCKSENDMESSAGE      AkelPad.SendMessage, AkelPad.Command called with script thread lock (by default).
    0x20  //ULT_UNLOCKSENDMESSAGE    AkelPad.SendMessage, AkelPad.Command called without script thread lock (slower).

Return Value
  Number. Changed synchronization objects, see nUnlockType.

Example:
  AkelPad.ScriptNoMutex();


AkelPad.ScriptExitCode
______________________

Set script exit code. Only if script is called with external call with code 2 or 4.

  ScriptExitCode([nExitCode]);

Arguments
  nExitCode
    Script exit code.

Return Value
  true   success.
  false  calling thread came out of the external procedure call.

Example:
  AkelPad.ScriptExitCode(1);


AkelPad.ScriptHandle (+ActiveX)
_______________________________

Allows to interact with the other running scripts.

  ScriptHandle(vData, nOperation);

Arguments
  vData
    Input data.
  nOperation
    1   //SH_FIRSTSCRIPT  Retrieve first script handle in stack.
        //  vData: zero.
        //  Return value: first script handle in stack.
    2   //SH_THISSCRIPT  Retrieve current script handle in stack.
        //  vData: zero.
        //  Return value: current script handle in stack.
    3   //SH_FINDSCRIPT  Find script handle by its name.
        //  vData: script name.
        //  Return value: first found working script handle in stack.
    10  //SH_GETEXECTYPE  Retrieve code of the external script call.
        //  vData: script handle. If zero then current script handle is used.
        //  Return value: code of the external script call.
    11  //SH_GETTHREADHANDLE  Retrieve script thread handle.
        //  vData: script handle. If zero then current script handle is used.
        //  Return value: script thread handle.
    12  //SH_GETTHREADID  Retrieve script thread identifier.
        //  vData: script handle. If zero then current script handle is used.
        //  Return value: script thread identifier.
    13  //SH_GETMESSAGELOOP  Retrieve message loop existence in script thread.
        //  vData: script handle. If zero then current script handle is used.
        //  Return value: true - exist, false - not exist.
    14  //SH_GETLOCKMULTICOPY  Lock execution of the multiple script copies.
        //  vData: script handle. If zero then current script handle is used.
        //  Return value: true - on, false - off.
    15  //SH_GETLOCKSCRIPTSQUEUE  Lock other scripts running with this script at the same time.
        //  vData: script handle. If zero then current script handle is used.
        //  Return value: true - on, false - off.
    16  //SH_GETLOCKPROGRAMTHREAD  Lock main thread from waiting this script (when script is called with external call with code 2).
        //  vData: script handle. If zero then current script handle is used.
        //  Return value: true - on, false - off.
    17  //SH_GETSERVICEWINDOW  Retrieve script service window handle. Automatically created when using WindowSubClass, ThreadHook and RegisterCallback methods.
        //  vData: script handle. If zero then current script handle is used.
        //  Return value: script service window handle.
    18  //SH_GETLOCKSENDMESSAGE  AkelPad.SendMessage, AkelPad.Command locks script thread.
        //  vData: script handle. If zero then current script handle is used.
        //  Return value: true - on, false - off.
    20  //SH_GETBASENAME  Retrieve script name without extension.
        //  vData: script handle. If zero then current script handle is used.
        //  Return value: script name without extension
    21  //SH_GETNAME  Retrieve script name.
        //  vData: script handle. If zero then current script handle is used.
        //  Return value: script name.
    22  //SH_GETFILE  Retrieve script file.
        //  vData: script handle. If zero then current script handle is used.
        //  Return value: script file.
    23  //SH_GETNCLUDE  Retrieve include script file.
        //  vData: script handle. If zero then current script handle is used.
        //  Return value: include script file.
    24  //SH_GETARGUMENTS  Retrieve script arguments string.
        //  vData: script handle. If zero then current script handle is used.
        //  Return value: script arguments string.
    31  //SH_NEXTSCRIPT   Retrieve next script handle in stack regardless of the name.
        //  vData: script handle. If zero then current script handle is used.
        //  Return value: next script handle in stack.
    32  //SH_NEXTSAMESCRIPT  Retrieve next script handle in stack with the same name.
        //  vData: script handle. If zero then current script handle is used.
        //  Return value: next script handle in stack with the same name.
    33  //SH_CLOSESCRIPT  Exit from script thread's message loop.
        //  vData: script handle. If zero then current script handle is used.
        //  Return value: zero.

Return Value
  Depend on operation.

Example (deny changing font size by scrolling mouse wheel with Ctrl key):
  var hMainWnd=AkelPad.GetMainWnd();
  var oSys=AkelPad.SystemFunction();
  var hSubClass;
  var hScript;

  if ((hScript=AkelPad.ScriptHandle(WScript.ScriptName, 3 /*SH_FINDSCRIPT*/)) && AkelPad.ScriptHandle(hScript, 13 /*SH_GETMESSAGELOOP*/))
  {
    //Script is running, second call close it.
    AkelPad.ScriptHandle(hScript, 33 /*SH_CLOSESCRIPT*/);
  }
  else if (hSubClass=AkelPad.WindowSubClass(2 /*WSC_EDITPROC*/, EditCallback, 0x020A /*WM_MOUSEWHEEL*/))
  {
    //Allow other scripts running.
    AkelPad.ScriptNoMutex();

    //Message loop.
    AkelPad.WindowGetMessage();

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

  function EditCallback(hWnd, uMsg, wParam, lParam)
  {
    if (uMsg == 0x020A /*WM_MOUSEWHEEL*/)
    {
      if ((wParam & 0xffff) == 0x8 /*MK_CONTROL*/)
      {
        AkelPad.WindowNoNextProc(hSubClass);
        return 0;
      }
    }
  }


AkelPad.ConnectObject (+ActiveX)
________________________________

Connects to the object's events.

  ConnectObject(oEventSource, pPrefix[, vIID]);

Arguments
  oEventSource
    Object to connect.
  pPrefix
    Prefix of the functions to handle receiving events.
  vIID
    Event interface IID.
    - vIID can be string in format "{00000000-0000-0000-0000-000000000000}".
    - vIID can be pointer. Example:
        var lpDIID_DWebBrowserEvents2=AkelPad.MemAlloc(16 /*sizeof(IID)*/);
        oSys.Call("ole32::IIDFromString", "{34A715A0-6587-11D0-924A-0020AFC7AC4D}", lpDIID_DWebBrowserEvents2);
    - If vIID not specified, connect to all possible interfaces of the object.

Return Value
  Number. Count of successfully connected interfaces.

Example:
  var oIE=new ActiveXObject("InternetExplorer.Application");
  var oSys=AkelPad.SystemFunction();

  if (AkelPad.ConnectObject(oIE, "IE_", "{34A715A0-6587-11D0-924A-0020AFC7AC4D}" /*DIID_DWebBrowserEvents2*/))
  {
    oIE.Visible=true;
    oIE.Navigate("http://akelpad.sourceforge.net/");
    AkelPad.WindowGetMessage();
    AkelPad.DisconnectObject(oIE);
  }
  oIE.Quit();

  function IE_DocumentComplete(pDisp, URL)
  {
    AkelPad.MessageBox(oIE.HWND, URL, WScript.ScriptName, 0 /*MB_OK*/);
    oSys.Call("user32::PostQuitMessage", 0);
  }


AkelPad.DisconnectObject (+ActiveX)
___________________________________

Disconnects from the object's events.

  DisconnectObject(oEventSource);

Arguments
  oEventSource
    Connected object.

Return Value
  Zero.

Example:
  See ConnectObject example.


AkelPad.ActiveXThis (+ActiveX)
______________________________

Send root IDispatch to plugin. Required for some methods to work in ActiveX mode (ConnectObject, ScriptHandle).

  ActiveXThis(this);

Arguments
  this
    Root script IDispatch.

Return Value
  Zero.

Example:
  See ActiveX section.


WScript.ScriptBaseName
______________________

Get script base name.

  WScript.ScriptBaseName

Return Value
  String. Script base name.

Example:
  WScript.Echo(WScript.ScriptBaseName);


_TCHAR (+ActiveX)
_________________

Constant that determines the end of system functions. Uses for AkelPad.SystemFunction().Call method.

  _TCHAR

Return Value
  String. "A" - functions calls with "A" ending (Windows 95/98/Me).
          "W" - functions calls with "W" ending (Windows NT/2000/XP).

Example:
  //How to provide support for Unicode and not lose compatibility with Win9x:
  var oSys=AkelPad.SystemFunction();
  var lpBuffer;
  var pWinDir;

  if (lpBuffer=AkelPad.MemAlloc(256 * _TSIZE))
  {
    oSys.Call("kernel32::GetWindowsDirectory" + _TCHAR, lpBuffer, 256);
    pWinDir=AkelPad.MemRead(lpBuffer, _TSTR);

    AkelPad.MemFree(lpBuffer);
  }


vbTCHAR (+ActiveX)
__________________

Same as _TCHAR. Uses for VBScript.


_TSTR (+ActiveX)
________________

Constant that determines the string type. Uses for MemCopy and MemRead methods.

  _TSTR

Return Value
  Number. 0 - DT_ANSI - ansi string (Windows 95/98/Me).
          1 - DT_UNICODE - unicode string (Windows NT/2000/XP).

Example:
  See _TCHAR example.


vbTSTR (+ActiveX)
_________________

Same as _TSTR. Uses for VBScript.


_TSIZE (+ActiveX)
_________________

Constant that determines the size of symbol in bytes. Uses for MemAlloc method.

  _TSIZE

Return Value
  Number. 1 - sizeof(char) - one byte (Windows 95/98/Me).
          2 - sizeof(wchar_t) - two bytes (Windows NT/2000/XP).

Example:
  See _TCHAR example.


vbTSIZE (+ActiveX)
__________________

Same as _TSIZE. Uses for VBScript.


_X64 (+ActiveX)
_______________

Constant that determines the program bits type - x86 or x64.

  _X64

Return Value
  Number. 0 - x86 version.
          1 - x64 version.

Example:
  if (_X64)
    WScript.Echo("x64 version");
  else
    WScript.Echo("x86 version");


vbX64 (+ActiveX)
________________

Same as _X64. Uses for VBScript.


_PtrAdd (+ActiveX)
__________________

Add value to a pointer.

  _PtrAdd(lpPointer, nValue)

Arguments
  lpPointer
    Any pointer.
  nValue
    Value to add. Can be negative.

Return Value
  Number. Pointer.

Example:
  See ThreadHook example.


vbPtrAdd (+ActiveX)
___________________

Same as _PtrAdd. Uses for VBScript.


_PtrMath (+ActiveX)
___________________

Do mathematical operation with pointers.

  _PtrMath(lpPointer1, pSign, lpPointer2)

Arguments
  lpPointer1
    First pointer.
  pSign
    One of the following:
      "+", "-", "*", "/", "%", "&", "|", "^", ">", "<", "^", "==", "!=", ">=", "<=", "<<", ">>"
  lpPointer2
    Second pointer.

Return Value
  Number. Pointer.

Example:
  See WindowRegisterClass example (VBScript).


vbPtrMath (+ActiveX)
____________________

Same as _PtrMath. Uses for VBScript.


*** ActiveX ***

Scripts.dll can be used in third party applications after library registration.
- x86 version registration: regsvr32.exe Scripts.dll
- x64 version registration: "%SystemRoot%\System32\regsvr32.exe" Scripts.dll

Usage example:
  if (typeof AkelPad == "undefined")
  {
    AkelPad=new ActiveXObject("AkelPad.Document");
    AkelPad.ActiveXThis(this);
    _TCHAR=AkelPad.Constants._TCHAR;
    _TSTR=AkelPad.Constants._TSTR;
    _TSIZE=AkelPad.Constants._TSIZE;
    _X64=AkelPad.Constants._X64;
    _PtrAdd=function(n1, n2) {return AkelPad.Global._PtrAdd(n1, n2);};
  }
  var oSys=AkelPad.SystemFunction();
  var lpBuffer;
  var pWinDir="";

  if (lpBuffer=AkelPad.MemAlloc(256 * _TSIZE))
  {
    oSys.Call("kernel32::GetWindowsDirectory" + _TCHAR, lpBuffer, 256);
    pWinDir=AkelPad.MemRead(lpBuffer, _TSTR);

    AkelPad.MemFree(lpBuffer);
  }
  WScript.Echo(pWinDir);
