Scripts collection

Discuss and announce AkelPad plugins
  • Author
  • Message
Offline
Posts: 670
Joined: Thu Jun 03, 2010 8:47 am
Location: Сочи, Хоста
Contact:

Post by Andrey_A_A »

Code: Select all

' getMail.vbs
'========================   Описание   =====================================
' Извлекает e-mail адреса из выделенного текста и отображает их в новой вкладке
' Если ничего не выделено, адреса извлекаются из всего текста

' -"Извлечение e-mail адресов" +Call("Scripts::Main", 1, "getMail.vbs")

' используется Functions.vbs, который следует положить ...AkelFiles\Plugs\Scripts\Include\

' Автор:           Аверин Андрей
' Версия:          1.7 (17.03.2011 - 08.09.2012)
' Mail:            Averin-And@yandex.ru
' Site:            http://tc-image.3dn.ru/forum/9-370-1134-16-1333617560
' Site:            http://akelpad.sourceforge.net/forum/viewtopic.php?p=13870#p13870
'===========================================================================
With AkelPad If .GetEditWnd() = 0 Then WScript.Quit()
  tTxt = .GetSelText()
  If Len(tTxt) = 0 Then tTxt = .GetTextRange(0, -1)
  If Len(tTxt) = 0 Then Wscript.Quit
  Txt = Split(tTxt, Chr(13))

  For i = 0 To Ubound(Txt)
    If InStr(Txt(i), "@") > 0 Then Text = Text & Txt(i) & Chr(32)
  Next

  CllStr = "/*?><%[]()*^\<>&=|'~`!+%;:$#№" & Chr(34) & vbTab & vbVerticalTab & vbLf & vbFormFeed & vbCr & vbCrLf
  Call .Include("Functions.vbs")
  tTxt = ReplSymbols(Text, CllStr, Chr(32)) : Text = ""
  tTxt = RegExpReplace(tTxt, "( )+", Chr(32), 0, 1, 1)
  Txt = DelDublicateArr(Split(tTxt, Chr(32)))
  For i = 0 To Ubound(Txt)
    A = Txt(i)
    If Len(A) > 5 Then
       If Instr(A, "@") > 0 And Instr(A, ".") > 0 And Left(A, 1) <> "@" And Right(A, 1) <> "@" Then Text = Text & Txt(i) & vbNewLine
    End If
  Next
  Call CreateNewTab
  Call SetRedraw(.GetEditWnd(), False)
  Call .ReplaceSel(DelDublicateStr(Text, vbNewLine))
  Call .SendMessage(.GetEditWnd(), 3087, False, 0)
  Call .SendMessage(.GetEditWnd(), 3079, 0, 0)
  Call .SetSel(0, 0)
  Call SetRedraw(.GetEditWnd(), True)
End With


Используется: Functions.vbs
Last edited by Andrey_A_A on Thu Sep 13, 2012 2:35 am, edited 3 times in total.

Offline
Site Admin
Posts: 6311
Joined: Thu Jul 06, 2006 7:20 am

Post by Instructor »

Show menu for current tab window.

Code: Select all

// http://akelpad.sourceforge.net/forum/viewtopic.php?p=13970#p13970
// Version: 1.2
// Author: Shengalts Aleksander aka Instructor
//
//
// Description(1033): Show menu for current tab window.
// Description(1049): Показать меню текущей вкладки.

//Variables
var hMainWnd=AkelPad.GetMainWnd();
var oSys=AkelPad.SystemFunction();
var hWndTab;
var nCurSel;
var lpRect;
var rcRect=[];

if (hWndTab=AkelPad.SendMessage(hMainWnd, 1222 /*AKD_GETMAININFO*/, 13 /*MI_WNDTAB*/, 0))
{
  if (oSys.Call("user32::IsWindowVisible", hWndTab))
  {
    nCurSel=AkelPad.SendMessage(hWndTab, 4875 /*TCM_GETCURSEL*/, 0, 0);

    if (lpRect=AkelPad.MemAlloc(16 /*sizeof(RECT)*/))
    {
      if (AkelPad.SendMessage(hWndTab, 4874 /*TCM_GETITEMRECT*/, nCurSel, lpRect))
      {
        AkelPad.ScriptNoMutex();

        //Screen
        oSys.Call("user32::ClientToScreen", hWndTab, _PtrAdd(lpRect, 0) /*offsetof(RECT, left)*/);
        oSys.Call("user32::ClientToScreen", hWndTab, _PtrAdd(lpRect, 8) /*offsetof(RECT, right)*/);
        RectToArray(lpRect, rcRect);
        oSys.Call("user32::SetCursorPos", rcRect.left + (rcRect.right - rcRect.left) / 2, rcRect.top + (rcRect.bottom - rcRect.top) / 2);

        //Client
        oSys.Call("user32::GetCursorPos", _PtrAdd(lpRect, 0) /*offsetof(RECT, left)*/);
        oSys.Call("user32::ScreenToClient", hWndTab, _PtrAdd(lpRect, 0) /*offsetof(RECT, left)*/);
        RectToArray(lpRect, rcRect);

        //Button down
        oSys.Call("user32::PostMessage" + _TCHAR, hWndTab, 0x0204 /*WM_RBUTTONDOWN*/, 0x2 /*MK_RBUTTON*/, MAKELONG(rcRect.left, rcRect.top));
        oSys.Call("user32::PostMessage" + _TCHAR, hWndTab, 0x0205 /*WM_RBUTTONUP*/, 0, MAKELONG(rcRect.left, rcRect.top));
      }
      AkelPad.MemFree(lpRect);
    }
  }
}

function RectToArray(lpRect, rcRect)
{
  rcRect.left=AkelPad.MemRead(_PtrAdd(lpRect, 0) /*offsetof(RECT, left)*/, 3 /*DT_DWORD*/);
  rcRect.top=AkelPad.MemRead(_PtrAdd(lpRect, 4) /*offsetof(RECT, top)*/, 3 /*DT_DWORD*/);
  rcRect.right=AkelPad.MemRead(_PtrAdd(lpRect, 8) /*offsetof(RECT, right)*/, 3 /*DT_DWORD*/);
  rcRect.bottom=AkelPad.MemRead(_PtrAdd(lpRect, 12) /*offsetof(RECT, bottom)*/, 3 /*DT_DWORD*/);
  return rcRect;
}

function MAKELONG(a, b)
{
  return (a & 0xffff) | ((b & 0xffff) << 16);
}
Last edited by Instructor on Sat Jan 31, 2015 3:47 pm, edited 2 times in total.

Offline
Posts: 2247
Joined: Tue Aug 07, 2007 2:03 pm
Location: Vinnitsa, Ukraine

Post by FeyFre »

Sets both left and right margins

Code: Select all

 // === [SetMargins.js] ===
// FeyFre (c) 2011
//
// http://akelpad.sourceforge.net/forum/viewtopic.php?p=14026#p14026
// Set both left and right margin value
// Arguments:
//			Margin value to set
//
// Example:
//   Call("Scripts::Main", 1, "SetMargins.js", "22")
//


// check arguments
if (!WScript.Arguments(0))
	WScript.Quit();
var mainwnd = AkelPad.GetMainWnd();
var WM_USER = 1024;
var AKD_GETEDITOPTION = WM_USER + 216;
var AKD_SETEDITOPTION = WM_USER + 217;
var EO_TEXTMARGINS = 1;
var margin = WScript.Arguments(0);
if(Number(margin) == NaN)
	WScript.Quit();
AkelPad.SendMessage(mainwnd, AKD_SETEDITOPTION, EO_TEXTMARGINS, 0x00010001*Number(margin));

Offline
Posts: 767
Joined: Mon Sep 28, 2009 10:03 am
Location: Minsk, Belarus

Post by se7h »

Random color theme
Cлучайная цветовая тема

Code: Select all

/// Random Color Theme v0.1 
// (с) se7h
// 
// http://akelpad.sourceforge.net/forum/viewtopic.php?p=14069#p14069
// 
// Usage in Toolbar/ContextMenu plugin: 
// -"Randomly color theme" Call("Scripts::Main", 1, "randomCTheme.js") Icon("pathToAnyIcon") 

var themes = ["Default",
              "Active4D",
              "Bespin",
              "Cobalt",
              "Dawn",
              "Earth",
              "iPlastic",
              "Lazy",
              "Mac Classic",
              "Monokai",
              "Solarized Light",
              "Solarized Dark",
              "SpaceCadet",
              "Sunburst",
              "Twilight",
              "Zenburn"];


var edit = AkelPad.GetEditWnd();

if (edit && AkelPad.IsPluginRunning("Coder::Highlight")){
   var r = getRandomInt(0, themes.length-1);

   AkelPad.Call("Coder::Settings", 5, themes[r]);
 }
 

function getRandomInt(min, max){
  return Math.floor(Math.random() * (max - min + 1)) + min;
}

KDJ
Offline
Posts: 1949
Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland

Post by KDJ »

Show/hide scroll bars in edit window.

Code: Select all

// http://akelpad.sourceforge.net/forum/viewtopic.php?p=14071#p14071
// Version: 2011-08-20
// Author: KDJ
//
// *** Show/hide scroll bars in edit window ***
//
// Usage:
//   Call("Scripts::Main", 1, "ShowScrollBar.js")       - switch (show/hide) horizontal and vertical scroll bars
//   Call("Scripts::Main", 1, "ShowScrollBar.js", "+")  - show horizontal and vertical scroll bars
//   Call("Scripts::Main", 1, "ShowScrollBar.js", "-")  - hide horizontal and vertical scroll bars
//   Call("Scripts::Main", 1, "ShowScrollBar.js", "H")  - switch (show/hide) horizontal scroll bar
//   Call("Scripts::Main", 1, "ShowScrollBar.js", "H+") - show horizontal scroll bar
//   Call("Scripts::Main", 1, "ShowScrollBar.js", "H-") - hide horizontal scroll bar
//   Call("Scripts::Main", 1, "ShowScrollBar.js", "V")  - switch (show/hide) vertical scroll bar
//   Call("Scripts::Main", 1, "ShowScrollBar.js", "V+") - show vertical scroll bar
//   Call("Scripts::Main", 1, "ShowScrollBar.js", "V-") - hide vertical scroll bar

var AEM_SHOWSCROLLBAR = 3375;

var SB_HORZ  = 0;
var SB_VERT  = 1;
var SB_BOTH  = 3;
var hEditWnd = AkelPad.GetEditWnd();
var sAction  = "";
var nSB      = SB_BOTH;
var lpPoint;
var bVisible;

if ((hEditWnd) && (lpPoint = AkelPad.MemAlloc(8 /*sizeof(POINT)*/)))
{
  if (WScript.Arguments.length)
  {
  	sAction = WScript.Arguments(0).toUpperCase().replace(/\s+/, "");
  
    if (sAction.charAt(0) == "H")
      nSB = SB_HORZ;
    else if (sAction.charAt(0) == "V")
      nSB = SB_VERT;
  }

  if (sAction.charAt(sAction.length - 1) == "+")
    bVisible = 1;
  else if (sAction.charAt(sAction.length - 1) == "-")
    bVisible = 0;
  else if ((AkelPad.SendMessage(hEditWnd, AEM_SHOWSCROLLBAR, -1, 0) == nSB) ||
           (AkelPad.SendMessage(hEditWnd, AEM_SHOWSCROLLBAR, -1, 0) == SB_BOTH))
    bVisible = 0;
  else
    bVisible = 1;

  AkelPad.SendMessage(hEditWnd, 1245 /*EM_GETSCROLLPOS*/, 0, lpPoint);
  AkelPad.SendMessage(hEditWnd, AEM_SHOWSCROLLBAR, nSB, bVisible);
  AkelPad.SendMessage(hEditWnd, 1246 /*EM_SETSCROLLPOS*/, 0, lpPoint);
  AkelPad.MemFree(lpPoint);
}

Last edited by KDJ on Sat Dec 20, 2014 7:25 pm, edited 1 time in total.

KDJ
Offline
Posts: 1949
Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland

Post by KDJ »

Change margins in edit window.

Code: Select all

// http://akelpad.sourceforge.net/forum/viewtopic.php?p=14187#p14187
// Version: 2015-01-06
// Author: KDJ
//
// *** Change margins in edit window ***
//
// Usage:
//   Call("Scripts::Main", 1, "MarginsChange.js", "-2 35 8 20") - decrease left margin of 2 pixels,
//                                                                increase top margin of 35 pixels,
//                                                                increase right margin of 8 pixels,
//                                                                increase bottom margin of 20 pixels

var DT_DWORD = 3;
var hEditWnd = AkelPad.GetEditWnd();
var oRect    = new Object();

if (hEditWnd)
{
  GetMargins(hEditWnd, oRect);

  if ((WScript.Arguments.length >= 1) && isFinite(WScript.Arguments(0)))
    oRect.L += Number(WScript.Arguments(0));

  if ((WScript.Arguments.length >= 2) && isFinite(WScript.Arguments(1)))
    oRect.T += Number(WScript.Arguments(1));

  if ((WScript.Arguments.length >= 3) && isFinite(WScript.Arguments(2)))
    oRect.R -= Number(WScript.Arguments(2));

  if ((WScript.Arguments.length >= 4) && isFinite(WScript.Arguments(3)))
    oRect.B -= Number(WScript.Arguments(3));

  SetMargins(hEditWnd, oRect);
}

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

  AkelPad.SendMessage(hWnd, 3177 /*AEM_GETRECT*/, 0, lpRect);

  oRect.L = AkelPad.MemRead(_PtrAdd(lpRect,  0), DT_DWORD);
  oRect.T = AkelPad.MemRead(_PtrAdd(lpRect,  4), DT_DWORD);
  oRect.R = AkelPad.MemRead(_PtrAdd(lpRect,  8), DT_DWORD);
  oRect.B = AkelPad.MemRead(_PtrAdd(lpRect, 12), DT_DWORD);

  AkelPad.MemFree(lpRect);
}

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

  AkelPad.MemCopy(_PtrAdd(lpRect,  0), oRect.L, DT_DWORD);
  AkelPad.MemCopy(_PtrAdd(lpRect,  4), oRect.T, DT_DWORD);
  AkelPad.MemCopy(_PtrAdd(lpRect,  8), oRect.R, DT_DWORD);
  AkelPad.MemCopy(_PtrAdd(lpRect, 12), oRect.B, DT_DWORD);

  AkelPad.SendMessage(hWnd, 3178 /*AEM_SETRECT*/, 1, lpRect);

  AkelPad.MemFree(lpRect);
}

Last edited by KDJ on Tue Jan 06, 2015 7:49 pm, edited 2 times in total.

Offline
Posts: 670
Joined: Thu Jun 03, 2010 8:47 am
Location: Сочи, Хоста
Contact:

Post by Andrey_A_A »

Code: Select all

' WriteInWhiteSpellCheckList.vbs
'========================   Описание   =====================================
' Добавляет к белому списку SpellCheck выделенное слово или выделенный вертикальный список слов
' (если ничего не выделено слово выделяется)
'========================  Параметры =======================================
' 1-й параметр:
'     имя белого списка (по умолчанию txt)
' 2-й параметр:
'     0 - добавление слова без учёта регистра (|слово) (по умолчанию)
'     1 - добавление слова с заглавной буквой (Пётр, Россия)
'     2 - добавление слова со всеми заглавными буквами (СНГ, ГОСТ)
'     3 - добавление слова как есть (без |)
' 3-й параметр:
'     0 - снять выделение после добавления (по умолчанию)
'     1 - оставить выделение
'     2 - удалить слово после добавления
'     3 - удалить строку после добавления
' файл должен быть заранее создан папке ...AkelFiles\Plugs\SpellCheck\
'
' -"Добавить |слова к белому списку" Call("Scripts::Main", 1, "WriteInWhiteSpellCheckList.vbs")
' -"Добавить |слова к белому списку.(удалить слова)" Call("Scripts::Main", 1, "WriteInWhiteSpellCheckList.vbs", `"txt" "0" "2"`)
' -"Добавить |слова к белому списку.(удалить строки)" Call("Scripts::Main", 1, "WriteInWhiteSpellCheckList.vbs", `"txt" "0" "3"`)
'     SEPARATOR
' -"Добавить Слова к белому списку" Call("Scripts::Main", 1, "WriteInWhiteSpellCheckList.vbs", `"txt" "1"`)
' -"Добавить Слова к белому списку.(удалить слова)" Call("Scripts::Main", 1, "WriteInWhiteSpellCheckList.vbs", `"txt" "1" "2"`)
' -"Добавить Слова к белому списку (удалить строки)" Call("Scripts::Main", 1, "WriteInWhiteSpellCheckList.vbs", `"txt" "1" "3"`)
'     SEPARATOR
' -"Добавить СЛОВА к белому списку" Call("Scripts::Main", 1, "WriteInWhiteSpellCheckList.vbs", `"txt" "2"`)
' -"Добавить СЛОВА к белому списку.(удалить слова)" Call("Scripts::Main", 1, "WriteInWhiteSpellCheckList.vbs", `"txt" "2" "2"`)
' -"Добавить СЛОВА к белому списку (удалить строки)" Call("Scripts::Main", 1, "WriteInWhiteSpellCheckList.vbs", `"txt" "2" "3"`)

' используется Functions.vbs, который следует положить в ...AkelFiles\Plugs\Scripts\Include\

' Автор:           Аверин Андрей
' Версия:          1.7 (28.08.2011 - 08.09.2012)
' Mail:            Averin-And@yandex.ru
' Site:            http://tc-image.3dn.ru/forum/9-416-1200-16-1333819115
' Site:            http://akelpad.sourceforge.net/forum/viewtopic.php?p=14489#p14489
'===========================================================================
sName = "txt" : nW = 0 : N = 0
Cnt = WScript.Arguments.Count
If Cnt > 0 Then
  sName = WScript.Arguments(0)
  If Cnt > 1 Then
    nW = WScript.Arguments(1) : If Cnt > 2 Then N = WScript.Arguments(2)
  End If
End If

With AkelPad Call .Include("Functions.vbs") : hMainWnd = .GetMainWnd() : tWord = .GetSelText()
  If Len(tWord) = 0 Then
    Call SelectWord : tWord = .GetSelText()
  Else
    If InStr(tWord, Chr(13)) > 0 Then
      Call SupplementSelectionLines(0) : tWord = .GetSelText()
    End If  
    nWordBeg = .GetSelStart()
  End If
  If Len(tWord) = 0 Then Wscript.Quit

  Select Case N
    Case 0 Call .SetSel(nWordBeg, nWordBeg)
    Case 2 Call .SendMessage(hMainWnd, 273, 4156, 0)
    Case 3 Call .SendMessage(hMainWnd, 273, 4197, 0)
  End Select

  sFile = .GetAkelDir(4) & "\SpellCheck\" & sName & ".spck"
  If Not CreateObject("Scripting.FileSystemObject").FileExists(sFile) Then WScript.Quit
  
  pEditFile = .GetEditFile(0)
  If Len(pEditFile) > 0 Then Call .Call("SpellCheck::Background", 1, vbNewLine & "+" & GetOtherObjectFile(pEditFile, 1) & vbNewLine & "|" & LCase(tWord) & vbNewLine)
End With

If InStr(tWord, Chr(13)) > 0 Then
  Txt = Split(tWord, Chr(13))
  For i = 0 To Ubound(Txt)
    Text = Text & ConvWord(Txt(i), nW) : If i <> Ubound(Txt) Then Text = Text & vbNewLine
  Next
Else
  Text = ConvWord(tWord, nW)
End If

Call CreateObject("Scripting.FileSystemObject").OpenTextFile(sFile, 8, False).Write(vbNewLine & Text)

Function ConvWord(Word, n)
  Select Case n
    Case 0 ConvWord = "|" & LCase(Word)
    Case 1 ConvWord = UCase(Left(Word, 1)) & Mid(Word, 2)
    Case 2 ConvWord = UCase(Word)
    Case 3 ConvWord = Word
  End Select
End Function


Предварительно надо создать файл txt.spck в папке в папке ...AkelFiles\Plugs\SpellCheck\ в кодировке Windows-1251
если такой файл есть перекодируйте
вот шаблон файла:

Code: Select all

;--   SpellCheck's Плагин - белый список - файл определения 
;-- 
; слова, которые не будут подсвечиваться при проверке 
+txt 
;
Last edited by Andrey_A_A on Thu Sep 13, 2012 2:31 am, edited 7 times in total.

KDJ
Offline
Posts: 1949
Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland

Post by KDJ »

Run ContextMenu plugin with font, that is set in AkelPad or modified:

Code: Select all

// http://akelpad.sourceforge.net/forum/viewtopic.php?p=14524#p14524
// Version: 2015-01-06
// Author: KDJ
//
// *** Show ContextMenu plugin dialog with another font ***
//
// Usage:
//   Call("Scripts::Main", 1, "PlugContextMenuAkelFont.js") - set font from AkelPad edit window
//   or
//   Call("Scripts::Main", 1, "PlugContextMenuAkelFont.js", 'pFont nStyle nSize') - set another font
//
//   Arguments (as in AkelPad.Font() method):
//    pFont
//      Font face, for example, "Courier". Unchanged, if "".
//    nStyle
//      0 ignored.
//      1 normal.
//      2 bold.
//      3 italic.
//      4 bold italic.
//    nSize
//      Font size in pixels. Unchanged, if 0.
//
// Example:
//   Call("Scripts::Main", 1, "PlugContextMenuAkelFont.js", '"Lucida Console" 3 14')

var oSys         = AkelPad.SystemFunction();
var hMainWnd     = AkelPad.GetMainWnd();
var sPlugFunc    = "ContextMenu::Main";
var sPlugWndName = "ContextMenu ";
var nStopTime    = new Date().getTime() + 1000;
var hPlugWnd;
var hCtrlWnd;
var lpLOGFONT;
var sFontName;
var nFontStyle;
var nFontSize;
var hDC;
var nDevCap;
var nHeight;
var nWeight;
var bItalic;
var hFont;

if (AkelPad.GetLangId(1 /*LANGID_PRIMARY*/) == 0x19 /*LANG_RUSSIAN*/)
  sPlugWndName += "плагин";
else
  sPlugWndName += "plugin";

AkelPad.Call(sPlugFunc, 1, 1);

while(! (hPlugWnd = oSys.Call("user32::FindWindow" + _TCHAR, 0, sPlugWndName)) ||
      ! (hCtrlWnd = oSys.Call("user32::FindWindowEx" + _TCHAR, hPlugWnd, 0, "RichEdit20" + _TCHAR, 0)))
{
  if (new Date().getTime() > nStopTime)
    WScript.Quit();

  WScript.Sleep(5);
} 

lpLOGFONT = AkelPad.MemAlloc(28 + 32 * _TSIZE); //sizeof(LOGFONT)
AkelPad.SendMessage(hMainWnd, 1231 /*AKD_GETFONT*/, 0, lpLOGFONT);

if (WScript.Arguments.length >= 1)
{
  if (sFontName = WScript.Arguments(0))
    AkelPad.MemCopy(_PtrAdd(lpLOGFONT, 28), sFontName, _TSTR); //lfFaceName
}

if ((WScript.Arguments.length >= 2) && isFinite(WScript.Arguments(1)))
{
  nFontStyle = Number(WScript.Arguments(1));
  if ((nFontStyle > 0) && (nFontStyle < 5))
  {
    nWeight = 400;
    bItalic = 0;
    if (nFontStyle == 2)
      nWeight = 700;
    else if (nFontStyle == 3)
      bItalic = 1;
    else if (nFontStyle == 4)
    {
      nWeight = 700;
      bItalic = 1;
    }
    AkelPad.MemCopy(_PtrAdd(lpLOGFONT, 16), nWeight, 3 /*DT_DWORD*/); //lfWeight
    AkelPad.MemCopy(_PtrAdd(lpLOGFONT, 20), bItalic, 5 /*DT_BYTE*/);  //lfItalic
  }
}

if ((WScript.Arguments.length >= 3) && isFinite(WScript.Arguments(2)))
{
  nFontSize = Number(WScript.Arguments(2));
  if (nFontSize > 0)
  {
    hDC     = oSys.Call("user32::GetDC", hCtrlWnd);
    nDevCap = oSys.Call("gdi32::GetDeviceCaps" , hDC, 90 /*LOGPIXELSY*/);
    nHeight = -oSys.Call("kernel32::MulDiv", nFontSize, nDevCap, 72);
    oSys.Call("user32::ReleaseDC", hCtrlWnd, hDC);
    AkelPad.MemCopy(lpLOGFONT, nHeight, 3 /*DT_DWORD*/); //lfHeight
  }
}

hFont = oSys.Call("gdi32::CreateFontIndirect" + _TCHAR, lpLOGFONT);
AkelPad.MemFree(lpLOGFONT);

AkelPad.SendMessage(hCtrlWnd, 48 /*WM_SETFONT*/, hFont, true);




Change the font in ToolBar plugin window.
Required to include: EnumerateWindows_functions.js

Code: Select all

// http://akelpad.sourceforge.net/forum/viewtopic.php?p=14524#p14524
// Version: 2015-01-06
// Author: KDJ
//
// *** Change edit font in ToolBar plugin dialog ***
//
// Required to include: EnumerateWindows_functions.js
//
// Usage:
//   Call("Scripts::Main", 1, "PlugToolBarAkelFont.js") - set font from AkelPad
//   or
//   Call("Scripts::Main", 1, "PlugToolBarAkelFont.js", 'pFont nStyle nSize') - set another font
//
//   Arguments (as in AkelPad.Font() method):
//    pFont
//      Font face, for example, "Courier". Unchanged, if "".
//    nStyle
//      0 ignored.
//      1 normal.
//      2 bold.
//      3 italic.
//      4 bold italic.
//    nSize
//      Font size in pixels. Unchanged, if 0.
//
// Example:
//   Call("Scripts::Main", 1, "PlugToolBarAkelFont.js", '"Lucida Console" 3 14')
//
// Remark:
//   Because there is no way to call ToolBar dialog from the script, you must first open ToolBar plugin dialog box, and then run the script.

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

var oSys     = AkelPad.SystemFunction();
var hMainWnd = AkelPad.GetMainWnd();
var hPlugWnd;
var hCtrlWnd;
var lpLOGFONT;
var sFontName;
var nFontStyle;
var nFontSize;
var hDC;
var nDevCap;
var nHeight;
var nWeight;
var bItalic;
var hFont;

if ((hPlugWnd = GetPluginWnd()) &&
    (hCtrlWnd = oSys.Call("user32::FindWindowEx" + _TCHAR, hPlugWnd, 0, "RichEdit20" + _TCHAR, 0)))
{
  lpLOGFONT = AkelPad.MemAlloc(28 + 32 * _TSIZE); //sizeof(LOGFONT)
  AkelPad.SendMessage(hMainWnd, 1231 /*AKD_GETFONT*/, 0, lpLOGFONT);

  if (WScript.Arguments.length >= 1)
  {
    if (sFontName = WScript.Arguments(0))
      AkelPad.MemCopy(_PtrAdd(lpLOGFONT, 28), sFontName, _TSTR); //lfFaceName
  }

  if ((WScript.Arguments.length >= 2) && isFinite(WScript.Arguments(1)))
  {
    nFontStyle = Number(WScript.Arguments(1));
    if ((nFontStyle > 0) && (nFontStyle < 5))
    {
      nWeight = 400;
      bItalic = 0;
      if (nFontStyle == 2)
        nWeight = 700;
      else if (nFontStyle == 3)
        bItalic = 1;
      else if (nFontStyle == 4)
      {
        nWeight = 700;
        bItalic = 1;
      }
      AkelPad.MemCopy(_PtrAdd(lpLOGFONT, 16), nWeight, 3 /*DT_DWORD*/); //lfWeight
      AkelPad.MemCopy(_PtrAdd(lpLOGFONT, 20), bItalic, 5 /*DT_BYTE*/);  //lfItalic
    }
  }

  if ((WScript.Arguments.length >= 3) && isFinite(WScript.Arguments(2)))
  {
    nFontSize = Number(WScript.Arguments(2));
    if (nFontSize > 0)
    {
      hDC     = oSys.Call("user32::GetDC", hCtrlWnd);
      nDevCap = oSys.Call("gdi32::GetDeviceCaps" , hDC, 90 /*LOGPIXELSY*/);
      nHeight = -oSys.Call("kernel32::MulDiv", nFontSize, nDevCap, 72);
      oSys.Call("user32::ReleaseDC", hCtrlWnd, hDC);
      AkelPad.MemCopy(lpLOGFONT, nHeight, 3 /*DT_DWORD*/); //lfHeight
    }
  }

  hFont = oSys.Call("gdi32::CreateFontIndirect" + _TCHAR, lpLOGFONT);
  AkelPad.MemFree(lpLOGFONT);

  AkelPad.SendMessage(hCtrlWnd, 48 /*WM_SETFONT*/, hFont, true);

  oSys.Call("user32::SetForegroundWindow", hPlugWnd);
}
else
  WScript.Echo("There is no open dialog box of ToolBar plugin");

function GetPluginWnd()
{
  var hPlugWnd = 0;
  var sEndName;
  var aWndList;
  var oRE;
  var i;

  if (AkelPad.GetLangId(1 /*LANGID_PRIMARY*/) == 0x19 /*LANG_RUSSIAN*/)
    sEndName = "плагин";
  else
    sEndName = "plugin";

  oRE = new RegExp("ToolBar.*" + sEndName);

  aWndList = EnumTopLevelWindows(1, 1, 2, 2, 1, 2, 0);

  for (i = 0; i < aWndList.length; ++i)
  {
    if (oRE.test(aWndList[i].Title))
    {
      hPlugWnd = aWndList[i].Handle;
      break;
    }
  }

  return hPlugWnd;
}



Scripts should be saved in Unicode.
Last edited by KDJ on Tue Jan 06, 2015 8:04 pm, edited 4 times in total.

KDJ
Offline
Posts: 1949
Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland

Post by KDJ »

Copy the text from edit window of ContextMenu/ToolBar plugin to AkelPad or vice versa.
Required to include: EnumerateWindows_functions.js
For the syntax highlighting uses akelmenu.coder by Infocatcher.
Script should be saved in Unicode.

Code: Select all

// http://akelpad.sourceforge.net/forum/viewtopic.php?p=14660#p14660
// Version: 2015-01-07
// Author: KDJ
//
// *** Copy text from edit window of ContextMenu/ToolBar plugin to AkelPad or vice versa ***
//
// Usage:
//   First, display dialog box of ContextMenu/ToolBar plugin and then
//   Call("Scripts::Main", 1, "PlugTextToAkelPad.js")
//
// Required to include: EnumerateWindows_functions.js
//
// For the syntax highlighting uses akelmenu.coder by Infocatcher: http://infocatcher.ucoz.net/akelpad/coder/_akelmenu.coder

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

var oSys         = AkelPad.SystemFunction();
var hInstanceDLL = AkelPad.GetInstanceDll();
var sClassName   = "AkelPad::Scripts::" + WScript.ScriptName + "::" + hInstanceDLL;
var sTxtCaption  = "Text: AkelPad <-> Plugin";
var hPlugWnd;
var hCtrlWnd;
var hWndDlg;
var hWndToAkel;
var hWndToPlug;
var oRect;

if ((hPlugWnd = GetPluginWnd()) &&
    (hCtrlWnd = oSys.Call("user32::FindWindowEx" + _TCHAR, hPlugWnd, 0, "RichEdit20" + _TCHAR, 0)))
{
  oRect = new Object();
  GetWndPos(hPlugWnd, oRect);

  AkelPad.WindowRegisterClass(sClassName);

  hWndDlg = oSys.Call("user32::CreateWindowEx" + _TCHAR,
                      0,               //dwExStyle
                      sClassName,      //lpClassName
                      sTxtCaption,     //lpWindowName
                      0x90C80000,      //WS_VISIBLE|WS_POPUP|WS_CAPTION|WS_SYSMENU
                      oRect.X,         //x
                      oRect.Y + 30,    //y
                      215,             //nWidth
                      75,              //nHeight
                      hPlugWnd,        //hWndParent
                      0,               //ID
                      hInstanceDLL,    //hInstance
                      DialogCallback); //Script function callback. To use it class must be registered by WindowRegisterClass.

  AkelPad.ScriptNoMutex();

  //Message loop
  AkelPad.WindowGetMessage();

  AkelPad.WindowUnregisterClass(sClassName);
}
else
{
  WScript.Echo("You must first open dialog box of ContextMenu/ToolBar plugin.");
}

function DialogCallback(hWnd, uMsg, wParam, lParam)
{
  if (uMsg == 1) //WM_CREATE
  {
    hWndToAkel = oSys.Call("user32::CreateWindowEx" + _TCHAR,
                 0,            //dwExStyle
                 "BUTTON",     //lpClassName
                 0,            //lpWindowName
                 0x50010001,   //dwStyle = WS_VISIBLE|WS_CHILD|WS_TABSTOP|BS_DEFPUSHBUTTON
                 20,           //x
                 10,           //y
                 80,           //nWidth
                 25,           //nHeight
                 hWnd,         //hWndParent
                 0,            //ID
                 hInstanceDLL, //hInstance
                 0);           //lpParam

    hWndToPlug = oSys.Call("user32::CreateWindowEx" + _TCHAR,
                 0,            //dwExStyle
                 "BUTTON",     //lpClassName
                 0,            //lpWindowName
                 0x50010000,   //dwStyle = WS_VISIBLE|WS_CHILD|WS_TABSTOP
                 110,          //x
                 10,           //y
                 80,           //nWidth
                 25,           //nHeight
                 hWnd,         //hWndParent
                 0,            //ID
                 hInstanceDLL, //hInstance
                 0);           //lpParam

    SetWndText(hWndToAkel, "AkelPad <-");
    SetWndText(hWndToPlug, "-> Plugin");
  }

  else if (uMsg == 7) //WM_SETFOCUS
    oSys.Call("user32::SetFocus", hWndToAkel);

  else if (uMsg == 256) //WM_KEYDOWN
  {
    if (wParam == 27) //VK_ESCAPE
      oSys.Call("user32::PostMessage" + _TCHAR, hWnd, 16 /*WM_CLOSE*/, 0, 0);
  }

  else if (uMsg == 273) //WM_COMMAND
  {
    if (lParam == hWndToAkel)
      TextToAkelPad();
    else if (lParam == hWndToPlug)
      TextToPlugin();
  }

  else if (uMsg == 16) //WM_CLOSE
    oSys.Call("user32::DestroyWindow", hWnd);

  else if (uMsg == 2) //WM_DESTROY
    //Exit message loop
    oSys.Call("user32::PostQuitMessage", 0);

  else if (! oSys.Call("user32::FindWindowEx" + _TCHAR, hPlugWnd, 0, "RichEdit20" + _TCHAR, 0))
    oSys.Call("user32::PostMessage" + _TCHAR, hWnd, 16 /*WM_CLOSE*/, 0, 0);

  return 0;
}

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

  oSys.Call("user32::GetWindowRect", hWnd, lpRect);

  oRect.X = AkelPad.MemRead(_PtrAdd(lpRect, 0), 3 /*DT_DWORD*/);
  oRect.Y = AkelPad.MemRead(_PtrAdd(lpRect, 4), 3 /*DT_DWORD*/);

  AkelPad.MemFree(lpRect);
}

function SetWndText(hWnd, sText)
{
  AkelPad.SendMessage(hWnd, 48 /*WM_SETFONT*/, oSys.Call("gdi32::GetStockObject", 17 /*DEFAULT_GUI_FONT*/), true);
  oSys.Call("user32::SetWindowText" + _TCHAR, hWnd, sText);
}

function TextToAkelPad()
{
  var nTxtLen    = oSys.Call("user32::GetWindowTextLength" + _TCHAR, hCtrlWnd);
  var hEditWnd;
  var lpTxtBuf;
  var lpSelBuf;

  if (nTxtLen)
  {
    AkelPad.SendMessage(AkelPad.GetMainWnd(), 273 /*WM_COMMAND*/, 4101 /*wParam=MAKEWPARAM(0,IDM_FILE_NEW)*/, 1 /*lParam=TRUE*/);
    AkelPad.Command(4125); //Reopen as UTF-16LE

    if (AkelPad.IsPluginRunning("Coder::HighLight"))
      AkelPad.Call("Coder::Settings", 1, "akelmenu");

    hEditWnd = AkelPad.GetEditWnd();
    lpTxtBuf = AkelPad.MemAlloc((nTxtLen + 1) * _TSIZE);
    lpSelBuf = AkelPad.MemAlloc(8 /*sizeof(CHARRANGE)*/);

    oSys.Call("user32::GetWindowText" + _TCHAR, hCtrlWnd, lpTxtBuf, nTxtLen + 1);
    oSys.Call("user32::SetWindowText" + _TCHAR, hEditWnd, lpTxtBuf);

    AkelPad.SendMessage(hCtrlWnd, 1076 /*EM_EXGETSEL*/, 0, lpSelBuf);
    AkelPad.SendMessage(hEditWnd, 1079 /*EM_EXSETSEL*/, 0, lpSelBuf);

    AkelPad.MemFree(lpTxtBuf);
    AkelPad.MemFree(lpSelBuf);
  }
}

function TextToPlugin()
{
  var hEditWnd = AkelPad.GetEditWnd();
  var nTxtLen  = oSys.Call("user32::GetWindowTextLength" + _TCHAR, hEditWnd);
  var lpTxtBuf;
  var lpSelBuf;

  if (nTxtLen)
  {
    lpTxtBuf = AkelPad.MemAlloc((nTxtLen + 1) * _TSIZE);
    lpSelBuf = AkelPad.MemAlloc(8 /*sizeof(CHARRANGE)*/);

    oSys.Call("user32::GetWindowText" + _TCHAR, hEditWnd, lpTxtBuf, nTxtLen + 1);
    oSys.Call("user32::SetWindowText" + _TCHAR, hCtrlWnd, lpTxtBuf);

    AkelPad.SendMessage(hCtrlWnd, 185 /*EM_SETMODIFY*/, true, 0);
    AkelPad.SendMessage(hEditWnd, 1076 /*EM_EXGETSEL*/, 0, lpSelBuf);
    AkelPad.SendMessage(hCtrlWnd, 1079 /*EM_EXSETSEL*/, 0, lpSelBuf);

    AkelPad.MemFree(lpTxtBuf);
    AkelPad.MemFree(lpSelBuf);
  }
}

function GetPluginWnd()
{
  var hPlugWnd = 0;
  var sEndName;
  var aWndList;
  var oRE;
  var i;

  if (AkelPad.GetLangId(1 /*LANGID_PRIMARY*/) == 0x19 /*LANG_RUSSIAN*/)
    sEndName = "плагин";
  else
    sEndName = "plugin";

  oRE = new RegExp("(ContextMenu)|(ToolBar.*)" + " " + sEndName);

  aWndList = EnumTopLevelWindows(1, 1, 2, 2, 1, 2, 0);

  for (i = 0; i < aWndList.length; ++i)
  {
    if (oRE.test(aWndList[i].Title))
    {
      hPlugWnd = aWndList[i].Handle;
      break;
    }
  }

  return hPlugWnd;
}

Last edited by KDJ on Wed Jan 07, 2015 8:24 pm, edited 6 times in total.

KDJ
Offline
Posts: 1949
Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland

Post by KDJ »

Opens text of ContextMenu/ToolBar plugin in AkelPad edit window.
The text is read from plugin .ini file or registry.

Extended version of this script is here: PluginText.js

Code: Select all

// http://akelpad.sourceforge.net/forum/viewtopic.php?p=14720#p14720
// Version: 2015-01-07
// Author: KDJ
//
// *** Opens text of ContextMenu/ToolBar plugin in AkelPad edit window ***
//
// Usage:
//   Call("Scripts::Main", 1, "PlugTextReadFromIni.js")
//
// Remarks:
//   The text is read from plugin settings (.ini file or registry).
//   For the syntax highlighting uses akelmenu.coder by Infocatcher: http://infocatcher.ucoz.net/akelpad/coder/_akelmenu.coder

var oSys         = AkelPad.SystemFunction();
var hMainWnd     = AkelPad.GetMainWnd();
var hInstanceDLL = AkelPad.GetInstanceDll();
var sClassName   = "AkelPad::Scripts::" + WScript.ScriptName + "::" + hInstanceDLL;
var aPlugs       = [];
var bSetInReg;
var oRect;
var hWndLB;
var hWndOpen;

GetPlugArray(aPlugs);

if (aPlugs.length)
{
  bSetInReg = IsSettingsInReg();
  oRect     = new Object();

  GetWndPos(hMainWnd, oRect);

  AkelPad.WindowRegisterClass(sClassName);

  oSys.Call("user32::CreateWindowExW",
            0,                  //dwExStyle
            sClassName,         //lpClassName
            WScript.ScriptName, //lpWindowName
            0x90C80000,         //WS_VISIBLE|WS_POPUP|WS_CAPTION|WS_SYSMENU
            oRect.X2 - 215,     //x
            oRect.Y2 - 220,     //y
            215,                //nWidth
            195,                //nHeight
            hMainWnd,           //hWndParent
            0,                  //ID
            hInstanceDLL,       //hInstance
            DialogCallback);    //Script function callback. To use it class must be registered by WindowRegisterClass.

  AkelPad.ScriptNoMutex();

  //Message loop
  AkelPad.WindowGetMessage();

  AkelPad.WindowUnregisterClass(sClassName);
}
else
{
  AkelPad.MessageBox(hMainWnd, "There is no files ContextMenu.dll and ToolBar.dll", WScript.ScriptName, 48);
}

function DialogCallback(hWnd, uMsg, wParam, lParam)
{
  if (uMsg == 1) //WM_CREATE
  {
    var i;

    hWndLB = oSys.Call("user32::CreateWindowExW",
             0,            //dwExStyle
             "LISTBOX",    //lpClassName
             0,            //lpWindowName
             0x50A10000,   //dwStyle = WS_VISIBLE|WS_CHILD|WS_VSCROLL|WS_BORDER|WS_TABSTOP
             15,           //x
             15,           //y
             180,          //nWidth
             120,          //nHeight
             hWnd,         //hWndParent
             0,            //ID
             hInstanceDLL, //hInstance
             0);           //lpParam

    hWndOpen = oSys.Call("user32::CreateWindowExW",
               0,            //dwExStyle
               "BUTTON",     //lpClassName
               0,            //lpWindowName
               0x50010001,   //dwStyle = WS_VISIBLE|WS_CHILD|WS_TABSTOP|BS_DEFPUSHBUTTON
               65,           //x
               130,          //y
               85,           //nWidth
               25,           //nHeight
               hWnd,         //hWndParent
               0,            //ID
               hInstanceDLL, //hInstance
               0);           //lpParam

    for (i = 0; i < aPlugs.length; ++i)
      oSys.Call("user32::SendMessageW", hWndLB, 0x0180 /*LB_ADDSTRING*/, 0, aPlugs[i].Display);

    AkelPad.SendMessage(hWndLB, 48 /*WM_SETFONT*/, oSys.Call("gdi32::GetStockObject", 17 /*DEFAULT_GUI_FONT*/), true);
    AkelPad.SendMessage(hWndLB, 0x0186 /*LB_SETCURSEL*/, 0, 0);

    SetWndText(hWndOpen, "Open");
  }

  else if (uMsg == 7) //WM_SETFOCUS
    oSys.Call("user32::SetFocus", hWndLB);

  else if (uMsg == 256) //WM_KEYDOWN
  {
    if (wParam == 13) //VK_RETURN
      oSys.Call("user32::PostMessageW", hWnd, 273 /*WM_COMMAND*/, 0, hWndOpen);
    else if (wParam == 27) //VK_ESCAPE
      oSys.Call("user32::PostMessageW", hWnd, 16 /*WM_CLOSE*/, 0, 0);
  }

  else if (uMsg == 273) //WM_COMMAND
  {
    if (lParam == hWndOpen)
      OpenText();
  }

  else if (uMsg == 16) //WM_CLOSE
    oSys.Call("user32::DestroyWindow", hWnd);

  else if (uMsg == 2) //WM_DESTROY
    //Exit message loop
    oSys.Call("user32::PostQuitMessage", 0);

  return 0;
}

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

  oSys.Call("user32::GetWindowRect", hWnd, lpRect);

  oRect.X1 = AkelPad.MemRead(_PtrAdd(lpRect,  0), 3 /*DT_DWORD*/);
  oRect.Y1 = AkelPad.MemRead(_PtrAdd(lpRect,  4), 3 /*DT_DWORD*/);
  oRect.X2 = AkelPad.MemRead(_PtrAdd(lpRect,  8), 3 /*DT_DWORD*/);
  oRect.Y2 = AkelPad.MemRead(_PtrAdd(lpRect, 12), 3 /*DT_DWORD*/);

  AkelPad.MemFree(lpRect);
}

function SetWndText(hWnd, sText)
{
  AkelPad.SendMessage(hWnd, 48 /*WM_SETFONT*/, oSys.Call("gdi32::GetStockObject", 17 /*DEFAULT_GUI_FONT*/), true);
  oSys.Call("user32::SetWindowTextW", hWnd, sText);
}

function GetPlugArray(aPlugs)
{
  var lpBuf     = AkelPad.MemAlloc(44 + 260 * _TSIZE + 14 * _TSIZE); //sizeof(WIN32_FIND_DATA)
  var sPlugDir  = AkelPad.GetAkelDir(4 /*ADTYPE_PLUGS*/);
  var sPlugName = "ContextMenu";
  var sTemplate = sPlugDir + "\\" + sPlugName + ".dll";
  var hFindFile = oSys.Call("kernel32::FindFirstFileW", sTemplate, lpBuf);

  if (hFindFile != -1) //INVALID_HANDLE_VALUE
  {
    aPlugs.push({Display: sPlugName + ": Show menu",         PlugName: sPlugName, ValName: "ManualMenuText"});
    aPlugs.push({Display: sPlugName + ": Main menu",         PlugName: sPlugName, ValName: "MainMenuText"});
    aPlugs.push({Display: sPlugName + ": Edit menu",         PlugName: sPlugName, ValName: "EditMenuText"});
    aPlugs.push({Display: sPlugName + ": Tab menu",          PlugName: sPlugName, ValName: "TabMenuText"});
    aPlugs.push({Display: sPlugName + ": URL menu",          PlugName: sPlugName, ValName: "UrlMenuText"});
    aPlugs.push({Display: sPlugName + ": Recent files menu", PlugName: sPlugName, ValName: "RecentFilesMenuText"});
    oSys.Call("kernel32::FindClose", hFindFile);
  }

  sTemplate = sPlugDir + "\\ToolBar*.dll";
  hFindFile = oSys.Call("kernel32::FindFirstFileW", sTemplate, lpBuf);

  if (hFindFile != -1) //INVALID_HANDLE_VALUE
  {
    do
    {
      sPlugName = AkelPad.MemRead(_PtrAdd(lpBuf, 44 /*offsetof(WIN32_FIND_DATAW, cFileName)*/), _TSTR);
      sPlugName = sPlugName.substring(sPlugName.lastIndexOf("\\") + 1, sPlugName.lastIndexOf("."));
      aPlugs.push({Display: sPlugName, PlugName: sPlugName, ValName: "ToolBarText"});
    }
    while (oSys.Call("kernel32::FindNextFileW", hFindFile, lpBuf));

    oSys.Call("kernel32::FindClose", hFindFile);
  }

  AkelPad.MemFree(lpBuf);
}

function IsSettingsInReg()
{
  var oFSO      = new ActiveXObject("Scripting.FileSystemObject");
  var sFile     = AkelPad.GetAkelDir(0 /*ADTYPE_ROOT*/) + "\\AkelPad.ini";
  var bSetInReg = true;
  var sText;

  if (oFSO.FileExists(sFile))
  {
    sText = AkelPad.ReadFile(sFile);
    sText = sText.substr(sText.indexOf("SaveSettings=") + 13, 1);

    if (sText == "2")
      bSetInReg = false;
  }

  return bSetInReg;
}

function OpenText()
{
  var nPos = AkelPad.SendMessage(hWndLB, 0x0188 /*LB_GETCURSEL*/, 0, 0);
  var aKeyVal;
  var sKeyVal;
  var sPlugDir;
  var sFile;
  var oShell;
  var oFSO;
  var oRE;
  var lpBuf;
  var oError;
  var i;

  AkelPad.SendMessage(hMainWnd, 273 /*WM_COMMAND*/, 4101 /*wParam=MAKEWPARAM(0,IDM_FILE_NEW)*/, 1 /*lParam=TRUE*/);
  AkelPad.Command(4125); //Reopen as UTF-16LE

  if (AkelPad.IsPluginRunning("Coder::HighLight"))
    AkelPad.Call("Coder::Settings", 1, "akelmenu");

  //Settings in registry
  if (bSetInReg)
  {
    oShell = new ActiveXObject("WScript.shell");
    try
    {
      aKeyVal = oShell.RegRead("HKCU\\Software\\Akelsoft\\AkelPad\\Plugs\\" + aPlugs[nPos].PlugName + "\\" + aPlugs[nPos].ValName);
      aKeyVal = aKeyVal.toArray(); //VBArray to JScript Array

      if (aKeyVal.length)
      {
        lpBuf = AkelPad.MemAlloc(aKeyVal.length);

        for (i = 0; i < aKeyVal.length; ++i)
          AkelPad.MemCopy(_PtrAdd(lpBuf, i), aKeyVal[i], 5 /*DT_BYTE*/);

        oSys.Call("user32::SetWindowTextW", AkelPad.GetEditWnd(), lpBuf);
        AkelPad.MemFree(lpBuf);
      }
    }
    catch (oError)
    {
    }
  }

  //Settings in .ini file
  else
  {
    oFSO     = new ActiveXObject("Scripting.FileSystemObject");
    sPlugDir = AkelPad.GetAkelDir(4 /*ADTYPE_PLUGS*/);
    sFile    = sPlugDir + "\\" + aPlugs[nPos].PlugName + ".ini";

    if (oFSO.FileExists(sFile))
    {
      oRE = new RegExp(aPlugs[nPos].ValName + "=([\\dA-F]*)");
      if (oRE.test(AkelPad.ReadFile(sFile)))
        sKeyVal = RegExp.$1;

      if (sKeyVal)
      {
        lpBuf = AkelPad.MemAlloc(sKeyVal.length / 2);

        for (i = 0; i < sKeyVal.length; i += 2)
          AkelPad.MemCopy(_PtrAdd(lpBuf, i / 2), parseInt(sKeyVal.substr(i, 2), 16), 5 /*DT_BYTE*/);

        oSys.Call("user32::SetWindowTextW", AkelPad.GetEditWnd(), lpBuf);
        AkelPad.MemFree(lpBuf);
      }
    }
  }
}

Last edited by KDJ on Wed Jan 07, 2015 8:23 pm, edited 7 times in total.

KDJ
Offline
Posts: 1949
Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland

Post by KDJ »

Restores initial settings of font face, style and size from AkelPad.ini or registry.

Code: Select all

// http://akelpad.sourceforge.net/forum/viewtopic.php?p=14756#p14756
// Version: 2015-01-06
// Author: KDJ
//
// *** Restore initial font (face, style, size) ***
//
// Usage:
//   Call("Scripts::Main", 1, "FontIniRestore.js")
//
// Remark:
//   Can assign shortcut key, eg. Ctrl+Num*

var lpLOGFONT = AkelPad.MemAlloc(28 + 32 * _TSIZE); //sizeof(LOGFONT);
var hMainWnd  = AkelPad.GetMainWnd();
var oFSO      = new ActiveXObject("Scripting.FileSystemObject");
var bSetInReg = true;
var sIniName  = AkelPad.GetAkelDir(0 /*ADTYPE_ROOT*/) + "\\AkelPad.ini";
var sIniText;
var oShell;
var oRE;
var aFontVal;
var sFontVal;
var sFaceVal;
var oError;
var i;

if (oFSO.FileExists(sIniName))
{
  sIniText = AkelPad.ReadFile(sIniName);

  if (sIniText.substr(sIniText.indexOf("SaveSettings=") + 13, 1) == "2")
    bSetInReg = false;
}

//Settings in registry
if (bSetInReg)
{
  oShell = new ActiveXObject("WScript.shell");
  try
  {
    aFontVal = oShell.RegRead("HKCU\\Software\\Akelsoft\\AkelPad\\Options\\Font").toArray();
    sFaceVal = oShell.RegRead("HKCU\\Software\\Akelsoft\\AkelPad\\Options\\FontFace");

    if (aFontVal.length && sFaceVal.length)
    {
      for (i = 0; i < aFontVal.length; ++i)
        AkelPad.MemCopy(_PtrAdd(lpLOGFONT, i), aFontVal[i], 5 /*DT_BYTE*/);

      AkelPad.MemCopy(_PtrAdd(lpLOGFONT, 28), sFaceVal, _TSTR);
      AkelPad.SendMessage(hMainWnd, 1234 /*AKD_SETFONT*/, 0, lpLOGFONT);
    }
  }
  catch (oError)
  {
  }
}

//Settings in .ini file
else
{
  oRE = new RegExp("Font=([\\dA-F]*)");
  if (oRE.test(sIniText))
    sFontVal = RegExp.$1;

  oRE = new RegExp("FontFace=([^\r\n]*)");
  if (oRE.test(sIniText))
    sFaceVal = RegExp.$1;

  if (sFontVal.length && sFaceVal.length)
  {
    for (i = 0; i < sFontVal.length; i += 2)
      AkelPad.MemCopy(_PtrAdd(lpLOGFONT, i / 2), parseInt(sFontVal.substr(i, 2), 16), 5 /*DT_BYTE*/);

    AkelPad.MemCopy(_PtrAdd(lpLOGFONT, 28), sFaceVal, _TSTR);
    AkelPad.SendMessage(hMainWnd, 1234 /*AKD_SETFONT*/, 0, lpLOGFONT);
  }
}

AkelPad.MemFree(lpLOGFONT);



VBS version:

Code: Select all

' http://akelpad.sourceforge.net/forum/viewtopic.php?p=14756#p14756
' Version: 2015-01-06
' Author: KDJ
'
' *** Restore initial font (face, style, size) ***
'
' Usage:
'   Call("Scripts::Main", 1, "FontIniRestore.vbs")
'
' Remark:
'   Can assign shortcut key, eg. Ctrl+Num*

Option Explicit
On Error Resume Next

Const ADTYPE_ROOT = 0
Const DT_UNICODE  = 1
Const DT_BYTE     = 5
Const AKD_SETFONT = 1234

Dim lpLOGFONT
Dim hMainWnd
Dim oFSO
Dim bSetInReg
Dim sIniName
Dim sIniText
Dim nPos
Dim oShell
Dim oRE
Dim oMatches
Dim aFontVal
Dim sFontVal
Dim sFaceVal
Dim i

lpLOGFONT = AkelPad.MemAlloc(28 + 32 * 2) 'sizeof(LOGFONT)
hMainWnd  = AkelPad.GetMainWnd
set oFSO  = CreateObject("Scripting.FileSystemObject")
bSetInReg = True
sIniName  = AkelPad.GetAkelDir(ADTYPE_ROOT) & "\AkelPad.ini"

If oFSO.FileExists(sIniName) Then
  sIniText = AkelPad.ReadFile(sIniName)
  nPos     = InStr(sIniText, "SaveSettings=")

  If (nPos > 0) And (Mid(sIniText, nPos + 13, 1) = "2") Then
    bSetInReg = False
  End If
End If

'Settings in registry
If bSetInReg Then
  set oShell = CreateObject("WScript.shell")

  aFontVal = oShell.RegRead("HKCU\Software\Akelsoft\AkelPad\Options\Font")
  sFaceVal = oShell.RegRead("HKCU\Software\Akelsoft\AkelPad\Options\FontFace")

  If ((Not IsEmpty(aFontVal)) And (Not IsEmpty(sFaceVal))) Then
    For i = 0 To UBound(aFontVal) - 1 Step 1
      AkelPad.MemCopy vbPtrAdd(lpLOGFONT, i), aFontVal(i), DT_BYTE
    Next

    AkelPad.MemCopy vbPtrAdd(lpLOGFONT, 28), sFaceVal, DT_UNICODE
    AkelPad.SendMessage hMainWnd, AKD_SETFONT, 0, lpLOGFONT
  End If

'Settings in .ini file
Else
  Set oRE        = New RegExp
  oRE.Pattern    = "Font=[\dA-F]*"
  oRE.IgnoreCase = True   
  Set oMatches   = oRE.Execute(sIniText)

  If Not IsEmpty(oMatches) Then
    sFontVal = Mid(oMatches(0), 6)
  End If

  Set oRE      = New RegExp
  oRE.Pattern  = "FontFace=[^\r\n]*"
  Set oMatches = oRE.Execute(sIniText)

  If Not IsEmpty(oMatches) Then
    sFaceVal = Mid(oMatches(0), 10)
  End If

  If ((Not IsEmpty(sFontVal)) And (Not IsEmpty(sFaceVal))) Then
    For i = 0 To Len(sFontVal) - 1 Step 2
      AkelPad.MemCopy vbPtrAdd(lpLOGFONT, i / 2), Eval("&H" + Mid(sFontVal, i + 1, 2)), DT_BYTE
    Next

    AkelPad.MemCopy vbPtrAdd(lpLOGFONT, 28), sFaceVal, DT_UNICODE
    AkelPad.SendMessage hMainWnd, AKD_SETFONT, 0, lpLOGFONT
  End If
End If

AkelPad.MemFree lpLOGFONT

Last edited by KDJ on Tue Jan 06, 2015 7:36 pm, edited 2 times in total.

KDJ
Offline
Posts: 1949
Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland

Post by KDJ »

Displays a dialog box with a choice of fonts.
Script must be placed in directory: ...\AkelPad\AkelFiles\Plugs\Scripts\Include\

Code: Select all

// ChooseFont_function.js
// http://akelpad.sourceforge.net/forum/viewtopic.php?p=14871#p14871
// Version: 2015-01-05
// Author: KDJ
//
// Contains functions:
// ChooseFont() - displays a dialog box with a choice of fonts
// ConvertFontFormat()
//
// Usage in script:
// if (! AkelPad.Include("ChooseFont_function.js")) WScript.Quit();
//--------------------------------------------------------------------------------------------------------
// vResult = ChooseFont(hWndOwn, nIniType, vIniVal, bEffects, bFixedPitchOnly, nResultType, sDialogTitle);
//
// Arguments:
// hWndOwn - handle to the window that owns the dialog box of ChooseFont. It can be 0.
// nIniType - type of value in the argument vIniVal, used to initialize the dialog box:
//   0 - no initial, vIniVal is ignored,
//   1 - pointer to LOGFONTW structure,
//   2 - handle to font,
//   3 - array [sFontFace, nFontStyle, nFontSize] as in the method AkelPad.Font(), see below,
//   4 - handle to window from which the font will be used to initialize.
// vIniVal - pointer, handle or array, depending on nIniType value.
// bEffects - 0 or 1, if 1 - dialog box additionally displays the controls with strikeout, underline, and text color options.
// bFixedPitchOnly - 0 or 1, if 1 - displays only fixed-pitch fonts.
// nResultType - type of return value from the function:
//   1 - pointer to LOGFONTW structure,
//   2 - handle to font,
//   3 - array [sFontFace, nFontStyle, nFontSize] as in the method AkelPad.Font():
//       sFontFace - for example "Courier New",
//       nFontStyle:
//         1 - normal,
//         2 - bold,
//         3 - italic,
//         4 - bold italic,
//       nFontSize - font size in points.
// sDialogTitle - title od dialog box (optional)
//
// Return value:
// If you press OK button, the function returns a value depending on the argument nResultType (see above).
// Otherwise, returns 0.
//--------------------------------------------------------------------------------------------------------
function ChooseFont(hWndOwn, nIniType, vIniVal, bEffects, bFixedPitchOnly, nResultType, sDialogTitle)
{
  var CF_EFFECTS             = 0x00000100;
  var CF_ENABLEHOOK          = 0x00000008;
  var CF_FIXEDPITCHONLY      = 0x00004000;
  var CF_FORCEFONTEXIST      = 0x00010000;
  var CF_INITTOLOGFONTSTRUCT = 0x00000040;
  var CF_SCREENFONTS         = 0x00000001;

  var hWndDesk   = AkelPad.SystemFunction().Call("User32::GetDesktopWindow");
  var lpCallback = AkelPad.SystemFunction().RegisterCallback(CFCallback);
  var nFlags     = CF_ENABLEHOOK | CF_FORCEFONTEXIST | CF_SCREENFONTS;
  var nCFSize    = _X64 ? 104 : 60; //sizeof(CHOOSEFONT)
  var lpCF       = AkelPad.MemAlloc(nCFSize);
  var lpLF;
  var vResult;
  var i;

  if (! AkelPad.SystemFunction().Call("User32::IsWindow", hWndOwn))
    hWndOwn = hWndDesk;

  if (nIniType && vIniVal)
  {
    if (nIniType == 4) //handle to window
      lpLF = ConvertFontFormat(AkelPad.SystemFunction().Call("User32::SendMessageW", vIniVal, 0x0031 /*WM_GETFONT*/, 0, 0), 2, 1);
    else
      lpLF = ConvertFontFormat(vIniVal, nIniType, 1);
  }

  if (lpLF)
    nFlags |= CF_INITTOLOGFONTSTRUCT;
  else
    lpLF = AkelPad.MemAlloc(28 + 32 * 2 /*sizeof(LOGFONTW)*/);

  if (bEffects)
    nFlags |= CF_EFFECTS;

  if (bFixedPitchOnly)
    nFlags |= CF_FIXEDPITCHONLY;

  AkelPad.MemCopy(_PtrAdd(lpCF,              0),    nCFSize, 3 /*DT_DWORD*/); //lStructSize
  AkelPad.MemCopy(_PtrAdd(lpCF, _X64 ?  8 :  4),    hWndOwn, 2 /*DT_QWORD*/); //hwndOwner
  AkelPad.MemCopy(_PtrAdd(lpCF, _X64 ? 24 : 12),       lpLF, 2 /*DT_QWORD*/); //lpLogFont
  AkelPad.MemCopy(_PtrAdd(lpCF, _X64 ? 36 : 20),     nFlags, 3 /*DT_DWORD*/); //Flags
  AkelPad.MemCopy(_PtrAdd(lpCF, _X64 ? 56 : 32), lpCallback, 2 /*DT_QWORD*/); //lpfnHook

  if (AkelPad.SystemFunction().Call("Comdlg32::ChooseFontW", lpCF))
  {
    if (nResultType == 1) //pointer to LOGFONTW
      vResult = lpLF;
    else //handle to font or array
    {
      vResult = ConvertFontFormat(lpLF, 1, nResultType);
      AkelPad.MemFree(lpLF);
    }
  }
  else
  {
    vResult = 0;
    AkelPad.MemFree(lpLF);
  }

  AkelPad.SystemFunction().UnregisterCallback(lpCallback);
  AkelPad.MemFree(lpCF);

  return vResult;

  function CFCallback(hWnd, uMsg, wParam, lParam)
  {
    if (uMsg == 272 /*WM_INITDIALOG*/)
    {
      var lpRect = AkelPad.MemAlloc(16); //sizeof(RECT)
      var sTitle;
      var nTextLen;
      var lpText;
      var nWndX, nWndY, nWndW, nWndH;
      var nOwnX, nOwnY, nOwnW, nOwnH;
      var nDeskW, nDeskH;

      //dialog title
      if (sDialogTitle)
        AkelPad.SystemFunction().Call("User32::SendMessageW", hWnd, 0x000C /*WM_SETTEXT*/, 0, sDialogTitle);
      else if (bFixedPitchOnly)
      {
        nTextLen = AkelPad.SystemFunction().Call("User32::SendMessageW", hWnd, 0x000E /*WM_GETTEXTLENGTH*/, 0, 0);
        sTitle   = " [Monospace]";
        lpText   = AkelPad.MemAlloc((nTextLen + sTitle.length + 1) * 2);

        AkelPad.SystemFunction().Call("User32::SendMessageW", hWnd, 0x000D /*WM_GETTEXT*/, nTextLen + 1, lpText);
        AkelPad.MemCopy(_PtrAdd(lpText, nTextLen * 2), sTitle, 1 /*DT_UNICODE*/);
        AkelPad.SystemFunction().Call("User32::SendMessageW", hWnd, 0x000C /*WM_SETTEXT*/, 0, lpText);
        AkelPad.MemFree(lpText);
      }

      //center dialog
      AkelPad.SystemFunction().Call("User32::GetWindowRect", hWnd, lpRect);
      nWndX = AkelPad.MemRead(_PtrAdd(lpRect,  0), 3 /*DT_DWORD*/);
      nWndY = AkelPad.MemRead(_PtrAdd(lpRect,  4), 3 /*DT_DWORD*/);
      nWndW = AkelPad.MemRead(_PtrAdd(lpRect,  8), 3 /*DT_DWORD*/) - nWndX;
      nWndH = AkelPad.MemRead(_PtrAdd(lpRect, 12), 3 /*DT_DWORD*/) - nWndY;

      AkelPad.SystemFunction().Call("User32::GetWindowRect", hWndOwn, lpRect);
      nOwnX = AkelPad.MemRead(_PtrAdd(lpRect,  0), 3 /*DT_DWORD*/);
      nOwnY = AkelPad.MemRead(_PtrAdd(lpRect,  4), 3 /*DT_DWORD*/);
      nOwnW = AkelPad.MemRead(_PtrAdd(lpRect,  8), 3 /*DT_DWORD*/) - nOwnX;
      nOwnH = AkelPad.MemRead(_PtrAdd(lpRect, 12), 3 /*DT_DWORD*/) - nOwnY;

      AkelPad.SystemFunction().Call("User32::GetWindowRect", hWndDesk, lpRect);
      nDeskW = AkelPad.MemRead(_PtrAdd(lpRect,  8), 3 /*DT_DWORD*/);
      nDeskH = AkelPad.MemRead(_PtrAdd(lpRect, 12), 3 /*DT_DWORD*/);
      AkelPad.MemFree(lpRect);

      nWndX = nOwnX + (nOwnW - nWndW) / 2;
      nWndY = nOwnY + (nOwnH - nWndH) / 2;

      if ((nWndX + nWndW) > nDeskW)
        nWndX = nDeskW - nWndW;
      if (nWndX < 0)
        nWndX = 0;
      if ((nWndY + nWndH) > nDeskH)
        nWndY = nDeskH - nWndH;
      if (nWndY < 0)
        nWndY = 0;

      AkelPad.SystemFunction().Call("User32::MoveWindow", hWnd, nWndX, nWndY, nWndW, nWndH, 0);
    }

    return 0;
  }
}

//-------------------------------------------------------
// vResult = ConvertFontFormat(vFont, nInType, nRetType);
//
// Arguments:
// vFont - pointer to LOGFONTW structure, handle to font, or array [sFontName, nFontStyle, nFontSize]
// nInType - vFont type,
// nRetType - vResult type:
//   1 - pointer to LOGFONTW structure
//   2 - handle to font
//   3 - array [sFontName, nFontStyle, nFontSize]
//-------------------------------------------------------
function ConvertFontFormat(vFont, nInType, nRetType)
{
  var nLFSize = 28 + 32 * 2; //sizeof(LOGFONTW)
  var lpLF    = AkelPad.MemAlloc(nLFSize);
  var hFont;
  var hDC;
  var nHeight;
  var nWeight;
  var bItalic;
  var vRetVal;
  var i;

  if (nInType == 1)
  {
    for (i = 0; i < nLFSize; ++i)
      AkelPad.MemCopy(_PtrAdd(lpLF, i), AkelPad.MemRead(_PtrAdd(vFont, i), 5 /*DT_BYTE*/), 5 /*DT_BYTE*/);
  }
  else if (nInType == 2)
  {
    if (! vFont)
      vFont = AkelPad.SystemFunction().Call("Gdi32::GetStockObject", 13 /*SYSTEM_FONT*/);

    AkelPad.SystemFunction().Call("Gdi32::GetObjectW", vFont, nLFSize, lpLF);
  }
  else if (nInType == 3)
  {
    hDC     = AkelPad.SystemFunction().Call("User32::GetDC", AkelPad.GetMainWnd());
    nHeight = -AkelPad.SystemFunction().Call("Kernel32::MulDiv", vFont[2], AkelPad.SystemFunction().Call("Gdi32::GetDeviceCaps", hDC, 90 /*LOGPIXELSY*/), 72);
    AkelPad.SystemFunction().Call("User32::ReleaseDC", AkelPad.GetMainWnd(), hDC);

    nWeight = 400;
    bItalic = 0;
    if ((vFont[1] == 2) || (vFont[1] == 4))
      nWeight = 700;
    if (vFont[1] > 2)
      bItalic = 1;

    AkelPad.MemCopy(_PtrAdd(lpLF,  0), nHeight,  3 /*DT_DWORD*/);   //lfHeight
    AkelPad.MemCopy(_PtrAdd(lpLF, 16), nWeight,  3 /*DT_DWORD*/);   //lfWeight
    AkelPad.MemCopy(_PtrAdd(lpLF, 20), bItalic,  5 /*DT_BYTE*/);    //lfItalic
    AkelPad.MemCopy(_PtrAdd(lpLF, 28), vFont[0], 1 /*DT_UNICODE*/); //lfFaceName
  }

  if (nRetType == 1)
    vRetVal = lpLF;
  else if (nRetType == 2)
  {
    vRetVal = AkelPad.SystemFunction().Call("Gdi32::CreateFontIndirectW", lpLF);
    AkelPad.MemFree(lpLF);
  }
  else if (nRetType == 3)
  {
    vRetVal    = [];
    vRetVal[0] = AkelPad.MemRead(_PtrAdd(lpLF, 28), 1 /*DT_UNICODE*/); //lfFaceName

    nWeight = AkelPad.MemRead(_PtrAdd(lpLF, 16), 3 /*DT_DWORD*/); //lfWeight
    bItalic = AkelPad.MemRead(_PtrAdd(lpLF, 20), 5 /*DT_BYTE*/);  //lfItalic

    if (nWeight < 600)
      vRetVal[1] = 1;
    else
      vRetVal[1] = 2;

    if (bItalic)
      vRetVal[1] += 2;

    hDC        = AkelPad.SystemFunction().Call("User32::GetDC", AkelPad.GetMainWnd());
    nHeight    = AkelPad.MemRead(lpLF, 3 /*DT_DWORD*/); //lfHeight
    vRetVal[2] = -AkelPad.SystemFunction().Call("Kernel32::MulDiv", nHeight, 72, AkelPad.SystemFunction().Call("Gdi32::GetDeviceCaps", hDC, 90 /*LOGPIXELSY*/));
    AkelPad.SystemFunction().Call("User32::ReleaseDC", AkelPad.GetMainWnd(), hDC); 
    AkelPad.MemFree(lpLF);
  }

  return vRetVal;
}


Example of use ChooseFont function.
Allows you to change the font, to monospace font.
It works similarly to Command(4201) - Font dialog, but displays only monospace fonts.

Code: Select all

// http://akelpad.sourceforge.net/forum/viewtopic.php?p=14871#p14871
// Version: 2013-08-15
// Author: KDJ
//
// *** Font dialog with monospace fonts ***
//
// Required to include: ChooseFont_function.js
//
// Usage:
//   Call("Scripts::Main", 1, "FontDialogMonospace.js")
//
// Remark:
//   It works similarly to Command(4201) - Font dialog, but displays only monospace fonts.

if (AkelPad.Include("ChooseFont_function.js"))
{
  var hMainWnd = AkelPad.GetMainWnd();
  var hEditWnd = AkelPad.GetEditWnd();
  var lpLOGFONT;

  if (hEditWnd)
  {
    if (lpLOGFONT = ChooseFont(hMainWnd, 4, hEditWnd, 0, 1, 1))
    {
      AkelPad.SystemFunction().Call("User32::SendMessageW", hMainWnd, 1234 /*AKD_SETFONT*/, 0, lpLOGFONT);
      AkelPad.MemFree(lpLOGFONT);
    }
  }
}



Other examples:

Code: Select all

// Examples of use ChooseFont function - 2013-08-14 (x86/x64)
//
// Usage:
// Call("Scripts::Main", 1, "ChooseFont_examples.js")
// Required to include: ChooseFont_function.js

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

var oSys = AkelPad.SystemFunction();

WScript.Echo("Example 1\nChange font in AkelPad edit window.\nChooseFont displays only fixed-width fonts.");
Example1();

WScript.Echo("Example 2\nChange font in AkelPad edit window, another method.\nChooseFont displays all fonts.");
Example2();

WScript.Echo("Example 3\nChange font in AkelPad status bar.\nChooseFont displays effects.");
Example3();

WScript.Echo("Example 4\nOpens ContextMenu plugin dialog and change font in edit control.\nChooseFont displays effects.");
Example4();

function Example1()
{
  //Example 1.
  //Change font in AkelPad edit window.
  //ChooseFont displays only fixed-width fonts.

  var hMainWnd  = AkelPad.GetMainWnd();
  var hEditWnd  = AkelPad.GetEditWnd();
  var lpLOGFONT = ChooseFont(hMainWnd, 4, hEditWnd, 0, 1, 1);

  if (lpLOGFONT)
    SendMessage(hMainWnd, 1234 /*AKD_SETFONT*/, 0, lpLOGFONT);

  AkelPad.MemFree(lpLOGFONT);
}

function Example2()
{
  //Example 2.
  //Change font in AkelPad edit window, another method.
  //ChooseFont displays all fonts.

  var hMainWnd = AkelPad.GetMainWnd();
  var hEditWnd = AkelPad.GetEditWnd();
  var aFont    = ChooseFont(hMainWnd, 4, hEditWnd, 0, 0, 3);

  if (aFont)
    AkelPad.Font(aFont[0], aFont[1], aFont[2]);
}

function Example3()
{
  //Example 3.
  //Change font in AkelPad status bar.
  //ChooseFont displays effects.

  var hMainWnd = AkelPad.GetMainWnd();
  var hStatBar = AkelPad.SystemFunction().Call("user32::FindWindowExW", hMainWnd, 0, "msctls_statusbar32" , 0);
  var hFont;

  if (hStatBar)
  {
    if (hFont = ChooseFont(hMainWnd, 4, hStatBar, 1, 0, 2))
      SendMessage(hStatBar, 48 /*WM_SETFONT*/, hFont, true);
  }
}

function Example4()
{
  //Example 4.
  //Opens ContextMenu plugin dialog and change font in edit control.
  //ChooseFont displays effects.

  var sPlugWndName = "ContextMenu ";
  var nStopTime    = new Date().getTime() + 2000;
  var hPlugWnd;
  var hCtrlWnd;
  var hFont;

  if (AkelPad.GetLangId(1 /*LANGID_PRIMARY*/) == 0x19 /*LANG_RUSSIAN*/)
    sPlugWndName += "плагин";
  else
    sPlugWndName += "plugin";

  AkelPad.Call("ContextMenu::Main", 1, 1);

  while(! (hPlugWnd = oSys.Call("user32::FindWindowW", 0, sPlugWndName)) ||
        ! (hCtrlWnd = oSys.Call("user32::FindWindowExW", hPlugWnd, 0, "RichEdit20W", 0)))
  {
    if (new Date().getTime() > nStopTime)
      return;
    WScript.Sleep(5);
  }

  WScript.Sleep(100);

  if (hFont = ChooseFont(hPlugWnd, 4, hCtrlWnd, 1, 0, 2))
    SendMessage(hCtrlWnd, 48 /*WM_SETFONT*/, hFont, true);
}

function SendMessage(hWnd, uMsg, wParam, lParam)
{
  return oSys.Call("User32::SendMessageW", hWnd, uMsg, wParam, lParam);
}
Last edited by KDJ on Mon Jan 05, 2015 5:08 pm, edited 12 times in total.

KDJ
Offline
Posts: 1949
Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland

Post by KDJ »

Enumerates top level windows and child windows (functions).
Script must be placed in directory: ...\AkelPad\AkelFiles\Plugs\Scripts\Include\

Code: Select all

// EnumerateWindows_functions.js
// http://akelpad.sourceforge.net/forum/viewtopic.php?p=14988#p14988
// Version: 2015-01-05
// Author: KDJ
//
// Contains functions:
// EnumTopLevelWindows()
// EnumChildWindows()
//
// Usage in script:
// if (! AkelPad.Include("EnumerateWindows_functions.js")) WScript.Quit();

//----------------------------------------------------------------------------------------------------
// aWndTop = EnumTopLevelWindows(nTitle, nVisible, nMinimized, nMaximized, nSize, nTopMost, nToolWin);
//
// Arguments:
// nTitle     - determines, whether the window contains the title,
// nVisible   - whether the window is visible,
// nMinimized - whether the window is minimized,
// nMaximized - whether the window is maximized,
// nSize      - whether the window have non zero size.
// nTopMost   - whether the window is top-most.
// nToolWin   - whether the window is tool window.
// Arguments can have the following value:
// 0 - no,
// 1 - yes,
// 2 - all windows, argument is ignored.
//
// Return value:
// Array of objects. Each element of array contains information about a single window:
// aWnd[n].Handle    - handle to window (number),
// aWnd[n].Menu      - handle to menu assigned to the window (number),
// aWnd[n].Title     - title of window (string),
// aWnd[n].Visible   - is window visible (bool),
// aWnd[n].Minimized - is window minimized (bool),
// aWnd[n].Maximized - is window maximized (bool),
// aWnd[n].X         - left-top corner x position (number),
// aWnd[n].Y         - left-top corner y position (number),
// aWnd[n].W         - window width (number),
// aWnd[n].H         - window height (number),
// aWnd[n].TopMost   - is window top-most (bool),
// aWnd[n].ToolWin   - is tool window (bool),
// aWnd[n].Class     - name of the window class (string),
// aWnd[n].PID       - identifier of the process, that created the window (number),
// aWnd[n].TID       - identifier of the thread, that created the window (number),
// aWnd[n].FileName  - full file name (with the path) of the process, that created the window (string),
// aWnd[n].BaseName  - file name of the process, that created the window (string).
//-----------------------------------------------------------------------------------------------
function EnumTopLevelWindows(nTitle, nVisible, nMinimized, nMaximized, nSize, nTopMost, nToolWin)
{
  var oSys = AkelPad.SystemFunction();
  var aWnd = [];
  var lpInfo;
  var hMenu;
  var sTitle;
  var bVisible;
  var bMinimized;
  var bMaximized;
  var nX;
  var nY;
  var nW;
  var nH;
  var bTopMost;
  var sClass;
  var nPID;
  var nTID;
  var hProcess;
  var sFileName;
  var sBaseName;

  try
  {
    oSys.RegisterCallback(EnumWindowsProc);
  }
  catch (oError)
  {
    AkelPad.MessageBox(0, 'Unable to register callback function: "EnumWindowsProc".', 'EnumTopLevelWindows', 0x10 /*MB_ICONERROR*/);
    return aWnd;
  }

  lpInfo = AkelPad.MemAlloc(260 * _TSIZE);

  oSys.Call("User32::EnumWindows", EnumWindowsProc, 0);

  oSys.UnregisterCallback(EnumWindowsProc);
  AkelPad.MemFree(lpInfo);

  return aWnd;

  function EnumWindowsProc(hWnd, lParam)
  {
    if (oSys.Call("User32::GetWindowText" + _TCHAR, hWnd, lpInfo, 260))
      sTitle = AkelPad.MemRead(lpInfo, _TSTR);
    else
      sTitle = "";

    hMenu      = oSys.Call("User32::GetMenu", hWnd);
    bVisible   = oSys.Call("User32::IsWindowVisible", hWnd);
    bMinimized = oSys.Call("User32::IsIconic", hWnd);
    bMaximized = oSys.Call("User32::IsZoomed", hWnd);

    if (oSys.Call("User32::GetWindowRect", hWnd, lpInfo))
    {
      nX = AkelPad.MemRead(_PtrAdd(lpInfo,  0), 3 /*DT_DWORD*/);
      nY = AkelPad.MemRead(_PtrAdd(lpInfo,  4), 3 /*DT_DWORD*/);
      nW = AkelPad.MemRead(_PtrAdd(lpInfo,  8), 3 /*DT_DWORD*/) - nX;
      nH = AkelPad.MemRead(_PtrAdd(lpInfo, 12), 3 /*DT_DWORD*/) - nY;
    }
    else
    {
      nX = 0;
      nY = 0;
      nW = 0;
      nH = 0;
    }

    bTopMost = oSys.Call("User32::GetWindowLong" + _TCHAR, hWnd, -20 /*GWL_EXSTYLE*/) & 0x00000008 /*WS_EX_TOPMOST*/;
    bToolWin = oSys.Call("User32::GetWindowLong" + _TCHAR, hWnd, -20 /*GWL_EXSTYLE*/) & 0x00000080 /*WS_EX_TOOLWINDOW*/;

    if (! (((nTitle == 0)     && sTitle)     || ((nTitle == 1)     && (! sTitle)) ||
           ((nVisible == 0)   && bVisible)   || ((nVisible == 1)   && (! bVisible)) ||
           ((nMinimized == 0) && bMinimized) || ((nMinimized == 1) && (! bMinimized)) ||
           ((nMaximized == 0) && bMaximized) || ((nMaximized == 1) && (! bMaximized)) ||
           ((nSize == 0)      && (nW + nH))  || ((nSize == 1)      && (! (nW + nH))) ||
           ((nTopMost == 0)   && bTopMost)   || ((nTopMost == 1)   && (! bTopMost)) ||
           ((nToolWin == 0)   && bToolWin)   || ((nToolWin == 1)   && (! bToolWin))))
    {
      if (oSys.Call("User32::GetClassName" + _TCHAR, hWnd, lpInfo, 260))
        sClass = AkelPad.MemRead(lpInfo, _TSTR);
      else
        sClass = "";

      nTID = oSys.Call("User32::GetWindowThreadProcessId", hWnd, lpInfo);
      nPID = AkelPad.MemRead(lpInfo, 3 /*DT_DWORD*/);

      hProcess = oSys.Call("Kernel32::OpenProcess", 0x0410 /*PROCESS_QUERY_INFORMATION|PROCESS_VM_READ*/, 0, nPID);

      if (oSys.Call("Psapi::GetModuleFileNameEx" + _TCHAR, hProcess, 0, lpInfo, 260))
        sFileName = AkelPad.MemRead(lpInfo, _TSTR);
      else
        sFileName = "<unknown>";

      if (oSys.Call("Psapi::GetModuleBaseName" + _TCHAR, hProcess, 0, lpInfo, 260))
        sBaseName = AkelPad.MemRead(lpInfo, _TSTR);
      else
        sBaseName = "<unknown>";

      oSys.Call("Kernel32::CloseHandle", hProcess);

      aWnd.push({Handle    : hWnd,
                 Menu      : hMenu,
                 Title     : sTitle,
                 Visible   : bVisible,
                 Minimized : bMinimized,
                 Maximized : bMaximized,
                 X         : nX,
                 Y         : nY,
                 W         : nW,
                 H         : nH,
                 TopMost   : bTopMost,
                 ToolWin   : bToolWin,
                 Class     : sClass,
                 PID       : nPID,
                 TID       : nTID,
                 FileName  : sFileName,
                 BaseName  : sBaseName});
    }

    return true;
  }
}

//------------------------------------------
// aWndChild = EnumChildWindows(hWndParent);
//
// Argument:
// hWndParent - handle to the parent window whose child windows are to be enumerated.
//
// Return value:
// Array of objects. Each element of array contains information about a single window:
// aWnd[n].Handle  - handle to window (number),
// aWnd[n].Text    - window text (string),
// aWnd[n].Visible - is window visible (bool),
// aWnd[n].Enabled - is window enabled (bool),
// aWnd[n].X       - left-top corner x position (number),
// aWnd[n].Y       - left-top corner y position (number),
// aWnd[n].W       - window width (number),
// aWnd[n].H       - window height (number),
// aWnd[n].Class   - name of the window class (string),
// aWnd[n].Style   - window style (number),
// aWnd[n].ExStyle - window exstyle (number).
// aWnd[n].ID      - window identifier (number).
//-----------------------------------
function EnumChildWindows(hWndParent)
{
  var oSys = AkelPad.SystemFunction();
  var aWnd = [];
  var lpInfo;
  var sText;
  var nX;
  var nY;
  var nW;
  var nH;
  var sClass;

  try
  {
    oSys.RegisterCallback(EnumChildProc);
  }
  catch (oError)
  {
    AkelPad.MessageBox(0, 'Unable to register callback function: "EnumChildProc".', 'EnumChildWindows', 0x10 /*MB_ICONERROR*/);
    return aWnd;
  }

  lpInfo = AkelPad.MemAlloc(260 * _TSIZE);

  oSys.Call("User32::EnumChildWindows", hWndParent, EnumChildProc, 0);

  oSys.UnregisterCallback(EnumChildProc);
  AkelPad.MemFree(lpInfo);

  return aWnd;

  function EnumChildProc(hWnd, lParam)
  {
    if (AkelPad.SendMessage(hWnd, 0x000D /*WM_GETTEXT*/, 260, lpInfo))
      sText = AkelPad.MemRead(lpInfo, _TSTR);
    else
      sText = "";

    if (oSys.Call("User32::GetWindowRect", hWnd, lpInfo))
    {
      nX = AkelPad.MemRead(_PtrAdd(lpInfo,  0), 3 /*DT_DWORD*/);
      nY = AkelPad.MemRead(_PtrAdd(lpInfo,  4), 3 /*DT_DWORD*/);
      nW = AkelPad.MemRead(_PtrAdd(lpInfo,  8), 3 /*DT_DWORD*/) - nX;
      nH = AkelPad.MemRead(_PtrAdd(lpInfo, 12), 3 /*DT_DWORD*/) - nY;
    }
    else
    {
      nX = 0;
      nY = 0;
      nW = 0;
      nH = 0;
    }

    if (oSys.Call("User32::GetClassName" + _TCHAR, hWnd, lpInfo, 260))
      sClass = AkelPad.MemRead(lpInfo, _TSTR);
    else
      sClass = "";

    aWnd.push({Handle  : hWnd,
               Text    : sText,
               Visible : oSys.Call("User32::IsWindowVisible", hWnd),
               Enabled : oSys.Call("User32::IsWindowEnabled", hWnd),
               X       : nX,
               Y       : nY,
               W       : nW,
               H       : nH,
               Class   : sClass,
               Style   : oSys.Call("User32::GetWindowLong" + _TCHAR, hWnd, -16 /*GWL_STYLE*/),
               ExStyle : oSys.Call("User32::GetWindowLong" + _TCHAR, hWnd, -20 /*GWL_EXSTYLE*/),
               ID      : oSys.Call("User32::GetWindowLong" + _TCHAR, hWnd, -12 /*GWL_ID*/)});

    return true;
  }
}


Example of use

Code: Select all

if (AkelPad.Include("EnumerateWindows_functions.js"))
{
  var aWndTop = EnumTopLevelWindows(1 /*nTitle*/, 1 /*nVisible*/, 2 /*nMinimized*/, 2 /*nMaximized*/,
                                 1 /*nSize*/,  2 /*nTopMost*/, 2 /*nToolWin*/);
  var sTxt = "";
  var i;

  for (i = 0; i < aWndTop.length; ++i)
    sTxt += aWndTop[i].BaseName + "     " + aWndTop[i].Title + "\n";

  AkelPad.Command(4101 /*IDM_FILE_NEW*/);
  AkelPad.ReplaceSel(sTxt);
  AkelPad.SendMessage(AkelPad.GetEditWnd(), 3087 /*AEM_SETMODIFY*/, false, 0);
  AkelPad.SendMessage(AkelPad.GetEditWnd(), 3079 /*AEM_EMPTYUNDOBUFFER*/, 0, 0);
}


Example of use

Code: Select all

if (AkelPad.Include("EnumerateWindows_functions.js"))
{
  var hWndParent = AkelPad.GetMainWnd();
  var aWndChild  = EnumChildWindows(hWndParent);
  var sTxt = "";
  var i;

  for (i = 0; i < aWndChild.length; ++i)
    sTxt += aWndChild[i].ID + "     " + aWndChild[i].Class + "    " + aWndChild[i].Text + "\n";

  AkelPad.Command(4101 /*IDM_FILE_NEW*/);
  AkelPad.ReplaceSel(sTxt);
  AkelPad.SendMessage(AkelPad.GetEditWnd(), 3087 /*AEM_SETMODIFY*/, false, 0);
  AkelPad.SendMessage(AkelPad.GetEditWnd(), 3079 /*AEM_EMPTYUNDOBUFFER*/, 0, 0);
}
Last edited by KDJ on Mon Jan 05, 2015 5:11 pm, edited 9 times in total.

KDJ
Offline
Posts: 1949
Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland

Post by KDJ »

Windows lister.

Code: Select all

// http://akelpad.sourceforge.net/forum/viewtopic.php?p=15078#p15078
// Version: 2016-08-05
// Author: KDJ
//
// *** Windows lister ***
//
// Run in AkelPad window:
//   Call("Scripts::Main", 1, "WindowsList.js")
// Run from command line (required registration: regsvr32.exe Scripts.dll):
//   wscript.exe WindowsList.js
//
// Shortcut keys in dialog box:
//   F5, F9 - refresh list
//   Alt+1  - set focus to windows list box

if (typeof AkelPad == "undefined")
{
  try
  {
    AkelPad = new ActiveXObject("AkelPad.Document");
    _PtrAdd = function(n1, n2) {return AkelPad.Global._PtrAdd(n1, n2);};
    _TCHAR  = AkelPad.Constants._TCHAR;
    _TSTR   = AkelPad.Constants._TSTR;
    _TSIZE  = AkelPad.Constants._TSIZE;
  }
  catch (oError)
  {
    WScript.Echo("You need register Scripts.dll");
    WScript.Quit();
  }
}

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

if (hWndDlg = oSys.Call("User32::FindWindowEx" + _TCHAR, 0, 0, sClassName, 0))
{
  if (! oSys.Call("User32::IsWindowVisible", hWndDlg))
    oSys.Call("User32::ShowWindow", hWndDlg, 8 /*SW_SHOWNA*/);
  if (oSys.Call("User32::IsIconic", hWndDlg))
    oSys.Call("User32::ShowWindow", hWndDlg, 9 /*SW_RESTORE*/);

  oSys.Call("User32::SetForegroundWindow", hWndDlg);
}
else
{
  var hIconSmall = oSys.Call("User32::LoadImageW",
                     hInstDLL, //hinst
                     101,      //lpszName
                     1,        //uType=IMAGE_ICON
                     16,       //cxDesired
                     16,       //cyDesired
                     0);       //fuLoad
  var hIconBig = oSys.Call("User32::LoadImageW",
                   hInstDLL, //hinst
                   101,      //lpszName
                   1,        //uType=IMAGE_ICON
                   32,       //cxDesired
                   32,       //cyDesired
                   0);       //fuLoad

  var sScripName = "Windows list";
  var hGuiFont   = oSys.Call("Gdi32::GetStockObject", 17 /*DEFAULT_GUI_FONT*/);
  var nWndX      = 220;
  var nWndY      = 40;
  var nTitle     = 1;
  var nVisible   = 1;
  var nMinim     = 2;
  var nMaxim     = 2;
  var nSize      = 1;
  var nTopMost   = 2;
  var nToolWin   = 2;
  var hFocus;
  var hFocusChild;
  var aListTop;
  var aListChild;

  var CLASS   = 0;
  var HWND    = 1;
  var EXSTYLE = 2;
  var STYLE   = 3;
  var X       = 4;
  var Y       = 5;
  var W       = 6;
  var H       = 7;
  var TXT     = 8;

  var aWnd        = [];
  var IDTITLEG    = 1000;
  var IDTITLE0    = 1001;
  var IDTITLE1    = 1002;
  var IDTITLE2    = 1003;
  var IDVISIBLEG  = 1004;
  var IDVISIBLE0  = 1005;
  var IDVISIBLE1  = 1006;
  var IDVISIBLE2  = 1007;
  var IDMINIMG    = 1008;
  var IDMINIM0    = 1009;
  var IDMINIM1    = 1010;
  var IDMINIM2    = 1011;
  var IDMAXIMG    = 1012;
  var IDMAXIM0    = 1013;
  var IDMAXIM1    = 1014;
  var IDMAXIM2    = 1015;
  var IDSIZEG     = 1016;
  var IDSIZE0     = 1017;
  var IDSIZE1     = 1018;
  var IDSIZE2     = 1019;
  var IDTOPMOSTG  = 1020;
  var IDTOPMOST0  = 1021;
  var IDTOPMOST1  = 1022;
  var IDTOPMOST2  = 1023;
  var IDTOOLWING  = 1024;
  var IDTOOLWIN0  = 1025;
  var IDTOOLWIN1  = 1026;
  var IDTOOLWIN2  = 1027;
  var IDPROCESS   = 1028;
  var IDWNDTITLE  = 1029;
  var IDCOUNT     = 1030;
  var IDWNDLB     = 1031;
  var IDTITLES    = 1032;
  var IDTITLEE    = 1033;
  var IDCLASSS    = 1034;
  var IDCLASSE    = 1035;
  var IDHANDLES   = 1036;
  var IDHANDLEE   = 1037;
  var IDMENUS     = 1038;
  var IDMENUE     = 1039;
  var IDVISIBLES  = 1040;
  var IDVISIBLEE  = 1041;
  var IDMINIMS    = 1042;
  var IDMINIME    = 1043;
  var IDMAXIMS    = 1044;
  var IDMAXIME    = 1045;
  var IDLOCATIONS = 1046;
  var IDLOCATIONE = 1047;
  var IDSIZES     = 1048;
  var IDSIZEE     = 1049;
  var IDTOPMOSTS  = 1050;
  var IDTOPMOSTE  = 1051;
  var IDTOOLWINS  = 1052;
  var IDTOOLWINE  = 1053;
  var IDPIDS      = 1054;
  var IDPIDE      = 1055;
  var IDTIDS      = 1056;
  var IDTIDE      = 1057;
  var IDFILES     = 1058;
  var IDFILEE     = 1059;
  var IDREFRESHB  = 1060;
  var IDSWITCHTOB = 1061;
  var IDHIDESHOWB = 1062;
  var IDMINIMIZEB = 1063;
  var IDMAXIMIZEB = 1064;
  var IDRESTOREB  = 1065;
  var IDCENTERB   = 1066;
  var IDTOPMOSTB  = 1067;
  var IDCHILDB    = 1068;

  //0x50000000 - WS_VISIBLE|WS_CHILD
  //0x50000002 - WS_VISIBLE|WS_CHILD|SS_RIGHT
  //0x50000007 - WS_VISIBLE|WS_CHILD|BS_GROUPBOX
  //0x50000009 - WS_VISIBLE|WS_CHILD|BS_AUTORADIOBUTTON
  //0x50010000 - WS_VISIBLE|WS_CHILD|WS_TABSTOP
  //0x50010880 - WS_VISIBLE|WS_CHILD|WS_TABSTOP|ES_READONLY|ES_AUTOHSCROLL
  //0x50A10081 - WS_VISIBLE|WS_CHILD|WS_VSCROLL|WS_BORDER|WS_TABSTOP|LBS_USETABSTOPS|LBS_NOTIFY
  //0x50A10083 - WS_VISIBLE|WS_CHILD|WS_VSCROLL|WS_BORDER|WS_TABSTOP|LBS_USETABSTOPS|LBS_NOTIFY|LBS_SORT
  //Windows               CLASS,HWND,EXSTYLE,      STYLE,   X,   Y,   W,   H, TXT
  aWnd[IDTITLEG   ] = ["BUTTON",   0,      0, 0x50000007,  10,  10,  70,  70, "Title"];
  aWnd[IDTITLE0   ] = ["BUTTON",   0,      0, 0x50000009,  25,  30,  40,  16, "No"];
  aWnd[IDTITLE1   ] = ["BUTTON",   0,      0, 0x50000009,  25,  45,  40,  16, "Yes"];
  aWnd[IDTITLE2   ] = ["BUTTON",   0,      0, 0x50000009,  25,  60,  40,  16, "All"];
  aWnd[IDVISIBLEG ] = ["BUTTON",   0,      0, 0x50000007,  90,  10,  70,  70, "Visible"];
  aWnd[IDVISIBLE0 ] = ["BUTTON",   0,      0, 0x50000009, 105,  30,  40,  16, "No"];
  aWnd[IDVISIBLE1 ] = ["BUTTON",   0,      0, 0x50000009, 105,  45,  40,  16, "Yes"];
  aWnd[IDVISIBLE2 ] = ["BUTTON",   0,      0, 0x50000009, 105,  60,  40,  16, "All"];
  aWnd[IDMINIMG   ] = ["BUTTON",   0,      0, 0x50000007, 170,  10,  70,  70, "Minimized"];
  aWnd[IDMINIM0   ] = ["BUTTON",   0,      0, 0x50000009, 185,  30,  40,  16, "No"];
  aWnd[IDMINIM1   ] = ["BUTTON",   0,      0, 0x50000009, 185,  45,  40,  16, "Yes"];
  aWnd[IDMINIM2   ] = ["BUTTON",   0,      0, 0x50000009, 185,  60,  40,  16, "All"];
  aWnd[IDMAXIMG   ] = ["BUTTON",   0,      0, 0x50000007, 250,  10,  70,  70, "Maximized"];
  aWnd[IDMAXIM0   ] = ["BUTTON",   0,      0, 0x50000009, 265,  30,  40,  16, "No"];
  aWnd[IDMAXIM1   ] = ["BUTTON",   0,      0, 0x50000009, 265,  45,  40,  16, "Yes"];
  aWnd[IDMAXIM2   ] = ["BUTTON",   0,      0, 0x50000009, 265,  60,  40,  16, "All"];
  aWnd[IDSIZEG    ] = ["BUTTON",   0,      0, 0x50000007, 330,  10,  70,  70, "Size"];
  aWnd[IDSIZE0    ] = ["BUTTON",   0,      0, 0x50000009, 345,  30,  40,  16, "No"];
  aWnd[IDSIZE1    ] = ["BUTTON",   0,      0, 0x50000009, 345,  45,  40,  16, "Yes"];
  aWnd[IDSIZE2    ] = ["BUTTON",   0,      0, 0x50000009, 345,  60,  40,  16, "All"];
  aWnd[IDTOPMOSTG ] = ["BUTTON",   0,      0, 0x50000007, 410,  10,  70,  70, "TopMost"];
  aWnd[IDTOPMOST0 ] = ["BUTTON",   0,      0, 0x50000009, 425,  30,  40,  16, "No"];
  aWnd[IDTOPMOST1 ] = ["BUTTON",   0,      0, 0x50000009, 425,  45,  40,  16, "Yes"];
  aWnd[IDTOPMOST2 ] = ["BUTTON",   0,      0, 0x50000009, 425,  60,  40,  16, "All"];
  aWnd[IDTOOLWING ] = ["BUTTON",   0,      0, 0x50000007, 490,  10,  70,  70, "ToolWin"];
  aWnd[IDTOOLWIN0 ] = ["BUTTON",   0,      0, 0x50000009, 505,  30,  40,  16, "No"];
  aWnd[IDTOOLWIN1 ] = ["BUTTON",   0,      0, 0x50000009, 505,  45,  40,  16, "Yes"];
  aWnd[IDTOOLWIN2 ] = ["BUTTON",   0,      0, 0x50000009, 505,  60,  40,  16, "All"];
  aWnd[IDPROCESS  ] = ["STATIC",   0,      0, 0x50000000,  10,  95, 100,  13, "Process"];
  aWnd[IDWNDTITLE ] = ["STATIC",   0,      0, 0x50000000, 130,  95, 100,  13, "Window title"];
  aWnd[IDCOUNT    ] = ["STATIC",   0,      0, 0x50000002, 500,  95,  60,  13, ""];
  aWnd[IDWNDLB    ] = ["LISTBOX",  0,      0, 0x50A10083,  10, 110, 550, 200, ""];
  aWnd[IDTITLES   ] = ["STATIC",   0,      0, 0x50000000,  10, 310,  60,  13, "Title:"];
  aWnd[IDTITLEE   ] = ["EDIT",     0,  0x200, 0x50010880,  65, 310, 415,  20, ""];
  aWnd[IDCLASSS   ] = ["STATIC",   0,      0, 0x50000000,  10, 330,  60,  13, "Class:"];
  aWnd[IDCLASSE   ] = ["EDIT",     0,  0x200, 0x50010880,  65, 330, 300,  20, ""];
  aWnd[IDHANDLES  ] = ["STATIC",   0,      0, 0x50000000,  10, 350,  60,  13, "WinHandle:"];
  aWnd[IDHANDLEE  ] = ["EDIT",     0,  0x200, 0x50010880,  65, 350, 175,  20, ""];
  aWnd[IDMENUS    ] = ["STATIC",   0,      0, 0x50000000, 243, 350,  60,  13, "MenuHandle:"];
  aWnd[IDMENUE    ] = ["EDIT",     0,  0x200, 0x50010880, 305, 350, 175,  20, "hex=FFFFFFFF,  dec=4294967295"];
  aWnd[IDVISIBLES ] = ["STATIC",   0,      0, 0x50000000,  10, 370,  60,  13, "Visible:"];
  aWnd[IDVISIBLEE ] = ["EDIT",     0,  0x200, 0x50010880,  65, 370,  30,  20, ""];
  aWnd[IDMINIMS   ] = ["STATIC",   0,      0, 0x50000000,  10, 390,  60,  13, "Minimized:"];
  aWnd[IDMINIME   ] = ["EDIT",     0,  0x200, 0x50010880,  65, 390,  30,  20, ""];
  aWnd[IDMAXIMS   ] = ["STATIC",   0,      0, 0x50000000,  10, 410,  60,  13, "Maximized:"];
  aWnd[IDMAXIME   ] = ["EDIT",     0,  0x200, 0x50010880,  65, 410,  30,  20, ""];
  aWnd[IDLOCATIONS] = ["STATIC",   0,      0, 0x50000000,  10, 430,  60,  13, "Location:"];
  aWnd[IDLOCATIONE] = ["EDIT",     0,  0x200, 0x50010880,  65, 430, 120,  20, ""];
  aWnd[IDSIZES    ] = ["STATIC",   0,      0, 0x50000000, 210, 430,  60,  13, "Size:"];
  aWnd[IDSIZEE    ] = ["EDIT",     0,  0x200, 0x50010880, 240, 430, 120,  20, ""];
  aWnd[IDTOPMOSTS ] = ["STATIC",   0,      0, 0x50000000,  10, 450,  60,  13, "TopMost:"];
  aWnd[IDTOPMOSTE ] = ["EDIT",     0,  0x200, 0x50010880,  65, 450,  30,  20, ""];
  aWnd[IDTOOLWINS ] = ["STATIC",   0,      0, 0x50000000,  10, 470,  60,  13, "ToolWin:"];
  aWnd[IDTOOLWINE ] = ["EDIT",     0,  0x200, 0x50010880,  65, 470,  30,  20, ""];
  aWnd[IDPIDS     ] = ["STATIC",   0,      0, 0x50000000,  10, 490,  60,  13, "ProcessID:"];
  aWnd[IDPIDE     ] = ["EDIT",     0,  0x200, 0x50010880,  65, 490, 175,  20, ""];
  aWnd[IDTIDS     ] = ["STATIC",   0,      0, 0x50000000, 250, 490,  60,  13, "ThreadID:"];
  aWnd[IDTIDE     ] = ["EDIT",     0,  0x200, 0x50010880, 305, 490, 175,  20, ""];
  aWnd[IDFILES    ] = ["STATIC",   0,      0, 0x50000000,  10, 510,  60,  13, "ProcFile:"];
  aWnd[IDFILEE    ] = ["EDIT",     0,  0x200, 0x50010880,  65, 510, 415,  20, ""];
  aWnd[IDREFRESHB ] = ["BUTTON",   0,      0, 0x50010000, 490, 310,  70,  23, "Refresh (F5)"];
  aWnd[IDSWITCHTOB] = ["BUTTON",   0,      0, 0x50010000, 490, 335,  70,  23, "&Switch to"];
  aWnd[IDHIDESHOWB] = ["BUTTON",   0,      0, 0x50010000, 490, 360,  70,  23, "&Hide/Show"];
  aWnd[IDMINIMIZEB] = ["BUTTON",   0,      0, 0x50010000, 490, 385,  70,  23, "Mi&nimize"];
  aWnd[IDMAXIMIZEB] = ["BUTTON",   0,      0, 0x50010000, 490, 410,  70,  23, "Ma&ximize"];
  aWnd[IDRESTOREB ] = ["BUTTON",   0,      0, 0x50010000, 490, 435,  70,  23, "&Restore"];
  aWnd[IDCENTERB  ] = ["BUTTON",   0,      0, 0x50010000, 490, 460,  70,  23, "&Center"];
  aWnd[IDTOPMOSTB ] = ["BUTTON",   0,      0, 0x50010000, 490, 485,  70,  23, "&TopMost"];
  aWnd[IDCHILDB   ] = ["BUTTON",   0,      0, 0x50010000, 490, 510,  70,  23, "Child &Win"];

  var aWndChild        = [];
  var IDCHILDID        = 1100;
  var IDCHILDVISIBLE   = 1101;
  var IDCHILDENABLED   = 1102;
  var IDCHILDCLASS     = 1103;
  var IDCHILDTEXT      = 1104;
  var IDCHILDCOUNT     = 1105;
  var IDCHILDWNDLB     = 1106;
  var IDCHILDHANDLES   = 1107;
  var IDCHILDHANDLEE   = 1108;
  var IDCHILDSTYLES    = 1109;
  var IDCHILDSTYLEE    = 1110;
  var IDCHILDEXSTYLES  = 1111;
  var IDCHILDEXSTYLEE  = 1112;
  var IDCHILDLOCATIONS = 1113;
  var IDCHILDLOCATIONE = 1114;
  var IDCHILDSIZES     = 1115;
  var IDCHILDSIZEE     = 1116;

  //Windows                         CLASS,HWND,EXSTYLE,      STYLE,   X,   Y,   W,   H, TXT
  aWndChild[IDCHILDID       ] = ["STATIC",   0,      0, 0x50000000,  10,  10, 100,  13, "WinID"];
  aWndChild[IDCHILDVISIBLE  ] = ["STATIC",   0,      0, 0x50000000,  64,  10, 100,  13, "Visible"];
  aWndChild[IDCHILDENABLED  ] = ["STATIC",   0,      0, 0x50000000, 108,  10, 100,  13, "Enabled"];
  aWndChild[IDCHILDCLASS    ] = ["STATIC",   0,      0, 0x50000000, 162,  10, 100,  13, "Class"];
  aWndChild[IDCHILDTEXT     ] = ["STATIC",   0,      0, 0x50000000, 340,  10, 100,  13, "Text"];
  aWndChild[IDCHILDCOUNT    ] = ["STATIC",   0,      0, 0x50000002, 515,  10,  60,  13, ""];
  aWndChild[IDCHILDWNDLB    ] = ["LISTBOX",  0,      0, 0x50A10081,  10,  25, 565, 200, ""];
  aWndChild[IDCHILDHANDLES  ] = ["STATIC",   0,      0, 0x50000000,  10, 225,  60,  13, "Handle:"];
  aWndChild[IDCHILDHANDLEE  ] = ["EDIT",     0,  0x200, 0x50010880,  60, 225, 180,  20, ""];
  aWndChild[IDCHILDSTYLES   ] = ["STATIC",   0,      0, 0x50000000,  10, 245,  60,  13, "Style:"];
  aWndChild[IDCHILDSTYLEE   ] = ["EDIT",     0,  0x200, 0x50010880,  60, 245, 180,  20, ""];
  aWndChild[IDCHILDEXSTYLES ] = ["STATIC",   0,      0, 0x50000000, 260, 245,  60,  13, "ExStyle:"];
  aWndChild[IDCHILDEXSTYLEE ] = ["EDIT",     0,  0x200, 0x50010880, 300, 245, 180,  20, ""];
  aWndChild[IDCHILDLOCATIONS] = ["STATIC",   0,      0, 0x50000000,  10, 265,  60,  13, "Location:"];
  aWndChild[IDCHILDLOCATIONE] = ["EDIT",     0,  0x200, 0x50010880,  60, 265, 120,  20, ""];
  aWndChild[IDCHILDSIZES    ] = ["STATIC",   0,      0, 0x50000000, 260, 265,  60,  13, "Size:"];
  aWndChild[IDCHILDSIZEE    ] = ["EDIT",     0,  0x200, 0x50010880, 300, 265, 120,  20, ""];

  ReadWriteIni(false);
  AkelPad.ScriptNoMutex(0x11 /*ULT_LOCKSENDMESSAGE|ULT_UNLOCKSCRIPTSQUEUE*/);
  AkelPad.WindowRegisterClass(sClassName);

  hWndDlg = oSys.Call("User32::CreateWindowEx" + _TCHAR,
                      0,               //dwExStyle
                      sClassName,      //lpClassName
                      sScripName,      //lpWindowName
                      0x90CA0000,      //WS_VISIBLE|WS_POPUP|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX
                      nWndX,           //x
                      nWndY,           //y
                      575,             //nWidth
                      570,             //nHeight
                      0,               //hWndParent
                      0,               //ID
                      hInstDLL,        //hInstance
                      DialogCallback); //Script function callback. To use it class must be registered by WindowRegisterClass.

  AkelPad.WindowGetMessage();
  AkelPad.WindowUnregisterClass(sClassName);
  oSys.Call("User32::DestroyIcon", hIconSmall);
  oSys.Call("User32::DestroyIcon", hIconBig);
}

function DialogCallback(hWnd, uMsg, wParam, lParam)
{
  if (uMsg == 1) //WM_CREATE
  {
    var i;

    for (i = 1000; i < aWnd.length; ++i)
    {
      aWnd[i][HWND] =
        oSys.Call("User32::CreateWindowEx" + _TCHAR,
                  aWnd[i][EXSTYLE], //dwExStyle
                  aWnd[i][CLASS],   //lpClassName
                  0,                //lpWindowName
                  aWnd[i][STYLE],   //dwStyle
                  aWnd[i][X],       //x
                  aWnd[i][Y],       //y
                  aWnd[i][W],       //nWidth
                  aWnd[i][H],       //nHeight
                  hWnd,             //hWndParent
                  i,                //ID
                  hInstDLL,         //hInstance
                  0);               //lpParam

      //Set font and text
      SetWndFontAndText(aWnd[i][HWND], hGuiFont, aWnd[i][TXT]);
    }

    AkelPad.SendMessage(hWnd, 0x0080 /*WM_SETICON*/, 0 /*ICON_SMALL*/, hIconSmall);
    AkelPad.SendMessage(hWnd, 0x0080 /*WM_SETICON*/, 1 /*ICON_BIG*/,   hIconBig);

    //Set TabStops in listbox
    SetTabStopsLB(aWnd[IDWNDLB][HWND], [80]);

    hFocus = aWnd[IDWNDLB][HWND];
  }

  else if ((uMsg == 6 /*WM_ACTIVATE*/) && (wParam == 0 /*WA_INACTIVE*/))
    hFocus = oSys.Call("User32::GetFocus");

  else if (uMsg == 7 /*WM_SETFOCUS*/)
  {
    if (CheckRadioButtons())
      oSys.Call("User32::SetFocus", hFocus);
    else
      oSys.Call("User32::DestroyWindow", hWnd); //Destroy dialog
  }

  else if (uMsg == 256 /*WM_KEYDOWN*/)
  {
    if ((wParam == 0x74 /*VK_F5*/) || (wParam == 0x78 /*VK_F9*/))
      oSys.Call("User32::PostMessage" + _TCHAR, hWnd, 273 /*WM_COMMAND*/, IDREFRESHB, 0);
    else if (wParam == 27 /*VK_ESCAPE*/)
      oSys.Call("User32::PostMessage" + _TCHAR, hWnd, 16 /*WM_CLOSE*/, 0, 0);
  }

  else if (uMsg == 260) //WM_SYSKEYDOWN
  {
    if (wParam == 0x31) //1 key
      oSys.Call("User32::SetFocus", aWnd[IDWNDLB][HWND]);
  }

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

    if ((nLowParam >= IDTITLE0) && (nLowParam <= IDTITLE2))
    {
      nTitle = nLowParam - IDTITLE0;
      CheckRadioButtons(IDTITLE0);
    }
    else if ((nLowParam >= IDVISIBLE0) && (nLowParam <= IDVISIBLE2))
    {
      nVisible = nLowParam - IDVISIBLE0;
      CheckRadioButtons(IDVISIBLE0);
    }
    else if ((nLowParam >= IDMINIM0) && (nLowParam <= IDMINIM2))
    {
      nMinim = nLowParam - IDMINIM0;
      CheckRadioButtons(IDMINIM0);
    }
    else if ((nLowParam >= IDMAXIM0) && (nLowParam <= IDMAXIM2))
    {
      nMaxim = nLowParam - IDMAXIM0;
      CheckRadioButtons(IDMAXIM0);
    }
    else if ((nLowParam >= IDSIZE0) && (nLowParam <= IDSIZE2))
    {
      nSize = nLowParam - IDSIZE0;
      CheckRadioButtons(IDSIZE0);
    }
    else if ((nLowParam >= IDTOPMOST0) && (nLowParam <= IDTOPMOST2))
    {
      nTopMost = nLowParam - IDTOPMOST0;
      CheckRadioButtons(IDTOPMOST0);
    }
    else if ((nLowParam >= IDTOOLWIN0) && (nLowParam <= IDTOOLWIN2))
    {
      nToolWin = nLowParam - IDTOOLWIN0;
      CheckRadioButtons(IDTOOLWIN0);
    }
    else if (nLowParam == IDWNDLB)
    {
      if (nHiwParam == 1 /*LBN_SELCHANGE*/)
        ShowWndData();
    }
    else if (nLowParam == IDREFRESHB)
      FillWndLB();
    else if (nLowParam == IDSWITCHTOB)
      ShowWindow(-1);
    else if (nLowParam == IDHIDESHOWB)
      ShowWindow(0 /*SW_HIDE*/);
    else if (nLowParam == IDMINIMIZEB)
      ShowWindow(7 /*SW_SHOWMINNOACTIVE*/);
    else if (nLowParam == IDMAXIMIZEB)
      ShowWindow(3 /*SW_MAXIMIZE*/);
    else if (nLowParam == IDRESTOREB)
      ShowWindow(9 /*SW_RESTORE*/);
    else if (nLowParam == IDCENTERB)
      ShowWindow(-2);
    else if (nLowParam == IDTOPMOSTB)
      ShowWindow(-3);
    else if (nLowParam == IDCHILDB)
    {
      ChildWindows();
      oSys.Call("User32::PostMessage" + _TCHAR, hWnd, 273 /*WM_COMMAND*/, IDREFRESHB, 0);
    }
  }

  else if (uMsg == 16 /*WM_CLOSE*/)
  {
    ReadWriteIni(true);
    oSys.Call("User32::DestroyWindow", hWnd); //Destroy dialog
  }

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

  return 0;
}

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

  oSys.Call("User32::GetWindowRect", hWnd, lpRect);

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

  AkelPad.MemFree(lpRect);
  return oRect;
}

function SetWndFontAndText(hWnd, hFont, sText)
{
  AkelPad.SendMessage(hWnd, 48 /*WM_SETFONT*/, hFont, true);
  oSys.Call("User32::SetWindowText" + _TCHAR, hWnd, sText);
}

function SetTabStopsLB(hWnd, aTab)
{
  var lpBuffer = AkelPad.MemAlloc(aTab.length * 4);
  var i;

  for (i = 0; i < aTab.length; ++i)
    AkelPad.MemCopy(_PtrAdd(lpBuffer, i * 4), aTab[i], 3 /*DT_DWORD*/);

  AkelPad.SendMessage(hWnd, 0x0192 /*LB_SETTABSTOPS*/, aTab.length, lpBuffer);

  AkelPad.MemFree(lpBuffer);
}

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

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

function CheckRadioButtons(nID)
{
  if (nID)
  {
    AkelPad.SendMessage(aWnd[nID    ][HWND], 241 /*BM_SETCHECK*/, 0 /*BST_UNCHECKED*/, 0);
    AkelPad.SendMessage(aWnd[nID + 1][HWND], 241 /*BM_SETCHECK*/, 0 /*BST_UNCHECKED*/, 0);
    AkelPad.SendMessage(aWnd[nID + 2][HWND], 241 /*BM_SETCHECK*/, 0 /*BST_UNCHECKED*/, 0);
  }

  AkelPad.SendMessage(aWnd[IDTITLE0   + nTitle  ][HWND], 241 /*BM_SETCHECK*/, 1 /*BST_CHECKED*/, 0);
  AkelPad.SendMessage(aWnd[IDVISIBLE0 + nVisible][HWND], 241 /*BM_SETCHECK*/, 1 /*BST_CHECKED*/, 0);
  AkelPad.SendMessage(aWnd[IDMINIM0   + nMinim  ][HWND], 241 /*BM_SETCHECK*/, 1 /*BST_CHECKED*/, 0);
  AkelPad.SendMessage(aWnd[IDMAXIM0   + nMaxim  ][HWND], 241 /*BM_SETCHECK*/, 1 /*BST_CHECKED*/, 0);
  AkelPad.SendMessage(aWnd[IDSIZE0    + nSize   ][HWND], 241 /*BM_SETCHECK*/, 1 /*BST_CHECKED*/, 0);
  AkelPad.SendMessage(aWnd[IDTOPMOST0 + nTopMost][HWND], 241 /*BM_SETCHECK*/, 1 /*BST_CHECKED*/, 0);
  AkelPad.SendMessage(aWnd[IDTOOLWIN0 + nToolWin][HWND], 241 /*BM_SETCHECK*/, 1 /*BST_CHECKED*/, 0);

  return FillWndLB();
}

function FillWndLB()
{
  var hSelWnd = 0;
  var oInd    = GetSelIndexObject();
  var nPos;
  var i;

  if (oInd.Array >= 0)
    hSelWnd = aListTop[oInd.Array].Handle;

  aListTop = EnumTopLevelWindows(nTitle, nVisible, nMinim, nMaxim, nSize, nTopMost, nToolWin);

  if (! aListTop)
    return 0;

  AkelPad.SendMessage(aWnd[IDWNDLB][HWND], 0x0184 /*LB_RESETCONTENT*/, 0, 0);

  for (i = 0; i < aListTop.length; ++i)
  {
    nPos = AkelPad.SendMessage(aWnd[IDWNDLB][HWND], 0x0180 /*LB_ADDSTRING*/, 0, aListTop[i].BaseName + "\t" + aListTop[i].Title);
    AkelPad.SendMessage(aWnd[IDWNDLB][HWND], 0x019A /*LB_SETITEMDATA*/, nPos, i);
  }

  if (hSelWnd)
  {
    nPos = -1;
    for (i = 0; i < AkelPad.SendMessage(aWnd[IDWNDLB][HWND], 0x018B /*LB_GETCOUNT*/, 0, 0); ++i)
    {
      if (hSelWnd == aListTop[AkelPad.SendMessage(aWnd[IDWNDLB][HWND], 0x0199 /*LB_GETITEMDATA*/, i, 0)].Handle)
      {
        nPos = i;
        break;
      }
    }

    if (nPos == -1)
    {
      if (oInd.LB < aListTop.length)
        nPos = oInd.LB;
      else
        nPos = aListTop.length - 1;
    }
  }
  else
    nPos = 0;

  AkelPad.SendMessage(aWnd[IDWNDLB][HWND], 0x0186 /*LB_SETCURSEL*/, nPos, 0);
  ShowWndData();

  return 1;
}

function GetSelIndexObject()
{
  var oInd = new Object();

  oInd.LB = AkelPad.SendMessage(aWnd[IDWNDLB][HWND], 0x0188 /*LB_GETCURSEL*/, 0, 0);

  if (oInd.LB >= 0)
    oInd.Array = AkelPad.SendMessage(aWnd[IDWNDLB][HWND], 0x0199 /*LB_GETITEMDATA*/, oInd.LB, 0);
  else
    oInd.Array = oInd.LB;

  return oInd;
}

function ShowWndData()
{
  var oInd = GetSelIndexObject();

  oSys.Call("User32::SetWindowText" + _TCHAR, aWnd[IDCOUNT][HWND],
            (oInd.LB + 1).toString() +
            "/" +
            aListTop.length.toString());

  if (oInd.Array >= 0)
  {
    oSys.Call("User32::SetWindowText" + _TCHAR, aWnd[IDTITLEE   ][HWND], aListTop[oInd.Array].Title);
    oSys.Call("User32::SetWindowText" + _TCHAR, aWnd[IDCLASSE   ][HWND], aListTop[oInd.Array].Class);
    oSys.Call("User32::SetWindowText" + _TCHAR, aWnd[IDHANDLEE  ][HWND], HexAndDec(aListTop[oInd.Array].Handle));
    oSys.Call("User32::SetWindowText" + _TCHAR, aWnd[IDMENUE    ][HWND], HexAndDec(aListTop[oInd.Array].Menu));
    oSys.Call("User32::SetWindowText" + _TCHAR, aWnd[IDVISIBLEE ][HWND], YesOrNo(aListTop[oInd.Array].Visible));
    oSys.Call("User32::SetWindowText" + _TCHAR, aWnd[IDMINIME   ][HWND], YesOrNo(aListTop[oInd.Array].Minimized));
    oSys.Call("User32::SetWindowText" + _TCHAR, aWnd[IDMAXIME   ][HWND], YesOrNo(aListTop[oInd.Array].Maximized));
    oSys.Call("User32::SetWindowText" + _TCHAR, aWnd[IDLOCATIONE][HWND],
              "X=" + aListTop[oInd.Array].X.toString() + ", " +
              "Y=" + aListTop[oInd.Array].Y.toString());
    oSys.Call("User32::SetWindowText" + _TCHAR, aWnd[IDSIZEE    ][HWND],
              "W=" + aListTop[oInd.Array].W.toString() + ", " +
              "H=" + aListTop[oInd.Array].H.toString());
    oSys.Call("User32::SetWindowText" + _TCHAR, aWnd[IDTOPMOSTE ][HWND], YesOrNo(aListTop[oInd.Array].TopMost));
    oSys.Call("User32::SetWindowText" + _TCHAR, aWnd[IDTOOLWINE ][HWND], YesOrNo(aListTop[oInd.Array].ToolWin));
    oSys.Call("User32::SetWindowText" + _TCHAR, aWnd[IDPIDE     ][HWND], HexAndDec(aListTop[oInd.Array].PID));
    oSys.Call("User32::SetWindowText" + _TCHAR, aWnd[IDFILEE    ][HWND], aListTop[oInd.Array].FileName);
    oSys.Call("User32::SetWindowText" + _TCHAR, aWnd[IDTIDE     ][HWND], HexAndDec(aListTop[oInd.Array].TID));
  }
  else
  {
    oSys.Call("User32::SetWindowText" + _TCHAR, aWnd[IDTITLEE   ][HWND], "");
    oSys.Call("User32::SetWindowText" + _TCHAR, aWnd[IDCLASSE   ][HWND], "");
    oSys.Call("User32::SetWindowText" + _TCHAR, aWnd[IDHANDLEE  ][HWND], "");
    oSys.Call("User32::SetWindowText" + _TCHAR, aWnd[IDMENUE    ][HWND], "");
    oSys.Call("User32::SetWindowText" + _TCHAR, aWnd[IDVISIBLEE ][HWND], "");
    oSys.Call("User32::SetWindowText" + _TCHAR, aWnd[IDMINIME   ][HWND], "");
    oSys.Call("User32::SetWindowText" + _TCHAR, aWnd[IDMAXIME   ][HWND], "");
    oSys.Call("User32::SetWindowText" + _TCHAR, aWnd[IDLOCATIONE][HWND], "");
    oSys.Call("User32::SetWindowText" + _TCHAR, aWnd[IDSIZEE    ][HWND], "");
    oSys.Call("User32::SetWindowText" + _TCHAR, aWnd[IDTOPMOSTE ][HWND], "");
    oSys.Call("User32::SetWindowText" + _TCHAR, aWnd[IDTOOLWINE ][HWND], "");
    oSys.Call("User32::SetWindowText" + _TCHAR, aWnd[IDPIDE     ][HWND], "");
    oSys.Call("User32::SetWindowText" + _TCHAR, aWnd[IDFILEE    ][HWND], "");
    oSys.Call("User32::SetWindowText" + _TCHAR, aWnd[IDTIDE     ][HWND], "");
  }
}

function HexAndDec(nArg)
{
  if (nArg)
  {
    var sHex = nArg.toString(16).toUpperCase();

    while (sHex.length < 8)
      sHex = "0" + sHex;

    return "hex=" + sHex + ",  dec=" + nArg.toString(10);
  }
  else
    return "";
}

function YesOrNo(bArg)
{
  return bArg ? "Yes" : "No";
}

function ShowWindow(nCmdShow)
{
  var oInd = GetSelIndexObject();
  var hWndDesk;
  var oRectDesk;
  var oRectWnd;
  var nExStyle;

  if ((oInd.Array >= 0) && (IsWindow(aListTop[oInd.Array].Handle)))
  {
    if (nCmdShow == -1) //Switch to window
    {
      if (! oSys.Call("User32::IsWindowVisible", aListTop[oInd.Array].Handle))
        oSys.Call("User32::ShowWindow", aListTop[oInd.Array].Handle, 8 /*SW_SHOWNA*/);
      if (oSys.Call("User32::IsIconic", aListTop[oInd.Array].Handle))
        oSys.Call("User32::ShowWindow", aListTop[oInd.Array].Handle, 10 /*SW_RESTORE*/);

      oSys.Call("User32::SetForegroundWindow", aListTop[oInd.Array].Handle);
    }

    else if (nCmdShow == -2) //Center window
    {
      if (oSys.Call("User32::IsWindowVisible", aListTop[oInd.Array].Handle) &&
         (! oSys.Call("User32::IsIconic", aListTop[oInd.Array].Handle)) &&
         (! oSys.Call("User32::IsZoomed", aListTop[oInd.Array].Handle)))
      {
        hWndDesk   = oSys.Call("User32::GetDesktopWindow");
        oRectDesk  = GetWindowPos(hWndDesk);
        oRectWnd   = GetWindowPos(aListTop[oInd.Array].Handle);
        oRectWnd.X = oRectDesk.X + (oRectDesk.W - oRectWnd.W) / 2;
        oRectWnd.Y = oRectDesk.Y + (oRectDesk.H - oRectWnd.H) / 2;

        oSys.Call("User32::SetWindowPos", aListTop[oInd.Array].Handle, 0, oRectWnd.X, oRectWnd.Y, 0, 0,
                                          0x0045 /*SWP_SHOWWINDOW|SWP_NOZORDER|SWP_NOSIZE*/);
        oSys.Call("User32::SetForegroundWindow", hWndDlg);
      }
    }

    else if (nCmdShow == -3) //TopMost switch
    {
      nExStyle = oSys.Call("User32::GetWindowLong" + _TCHAR, aListTop[oInd.Array].Handle, -20 /*GWL_EXSTYLE*/);

      if (nExStyle & 0x00000008 /*WS_EX_TOPMOST*/)
        oSys.Call("User32::SetWindowPos", aListTop[oInd.Array].Handle, -2 /*HWND_NOTOPMOST*/, 0, 0, 0, 0,
                                          0x0043 /*SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE*/);
      else
      {
        if (oSys.Call("User32::IsIconic", aListTop[oInd.Array].Handle))
          oSys.Call("User32::ShowWindow", aListTop[oInd.Array].Handle, 9 /*SW_RESTORE*/);

        oSys.Call("User32::SetWindowPos", aListTop[oInd.Array].Handle, -1 /*HWND_TOPMOST*/, 0, 0, 0, 0,
                                          0x0043 /*SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE*/);
      }
    }

    else
    {
      if ((nCmdShow == 0 /*SW_HIDE*/) &&
          (! oSys.Call("User32::IsWindowVisible", aListTop[oInd.Array].Handle)))
        nCmdShow = 8 /*SW_SHOWNA*/;

      oSys.Call("User32::ShowWindow", aListTop[oInd.Array].Handle, nCmdShow);
      oSys.Call("User32::SetForegroundWindow", hWndDlg);
    }

    aListTop[oInd.Array].Visible   = oSys.Call("User32::IsWindowVisible", aListTop[oInd.Array].Handle);
    aListTop[oInd.Array].Minimized = oSys.Call("User32::IsIconic", aListTop[oInd.Array].Handle);
    aListTop[oInd.Array].Maximized = oSys.Call("User32::IsZoomed", aListTop[oInd.Array].Handle);
    aListTop[oInd.Array].TopMost   = oSys.Call("User32::GetWindowLong" + _TCHAR,
                                               aListTop[oInd.Array].Handle,
                                               -20 /*GWL_EXSTYLE*/) & 0x00000008 /*WS_EX_TOPMOST*/;

    oRectWnd = GetWindowPos(aListTop[oInd.Array].Handle);
    aListTop[oInd.Array].X = oRectWnd.X;
    aListTop[oInd.Array].Y = oRectWnd.Y;
    aListTop[oInd.Array].W = oRectWnd.W;
    aListTop[oInd.Array].H = oRectWnd.H;

    ShowWndData();
  }
}

function IsWindow(hWnd)
{
  if (oSys.Call("User32::IsWindow", hWnd))
    return true;
  else
  {
    if (AkelPad.MessageBox(hWndDlg,
                           "There is no this window. Is already closed. Do you refresh the windows list?",
                           sScripName,
                           0x00000031 /*MB_DEFBUTTON1|MB_ICONWARNING|MB_OKCANCEL*/) == 1 /*IDOK*/)
      FillWndLB();
    return false;
  }
}

function ChildWindows()
{
  var oInd = GetSelIndexObject();
  var aWndChild;
  var oRect;
  var lpRect;

  if ((oInd.Array >= 0) && (IsWindow(aListTop[oInd.Array].Handle)))
  {
    aListChild = EnumChildWindows(aListTop[oInd.Array].Handle);
    oRect      = GetWindowPos(aWnd[IDWNDLB][HWND]);
    lpRect     = AkelPad.MemAlloc(16); //sizeof(RECT)

    AkelPad.SendMessage(aWnd[IDWNDLB][HWND], 0x0198 /*LB_GETITEMRECT*/, oInd.LB, lpRect);
    oRect.Y = oRect.Y + AkelPad.MemRead(_PtrAdd(lpRect, 4), 3 /*DT_DWORD*/) + 16;

    AkelPad.MemFree(lpRect);

    oSys.Call("User32::CreateWindowEx" + _TCHAR,
              0,                    //dwExStyle
              sClassName,           //lpClassName
              "Child windows",      //lpWindowName
              0x90C80000,           //WS_VISIBLE|WS_POPUP|WS_CAPTION|WS_SYSMENU
              oRect.X - 20,         //x
              oRect.Y,              //y
              oRect.W + 40,         //nWidth
              325,                  //nHeight
              hWndDlg,              //hWndParent
              0,                    //ID
              hInstDLL,             //hInstance
              DialogCallbackChild); //lpParam

    oSys.Call("User32::EnableWindow", hWndDlg, 0);
    AkelPad.WindowGetMessage();
  }
}

function DialogCallbackChild(hWnd, uMsg, wParam, lParam)
{
  if (uMsg == 1) //WM_CREATE
  {
    var i;

    for (i = 1100; i < aWndChild.length; ++i)
    {
      aWndChild[i][HWND] =
        oSys.Call("User32::CreateWindowEx" + _TCHAR,
                  aWndChild[i][EXSTYLE], //dwExStyle
                  aWndChild[i][CLASS],   //lpClassName
                  0,                     //lpWindowName
                  aWndChild[i][STYLE],   //dwStyle
                  aWndChild[i][X],       //x
                  aWndChild[i][Y],       //y
                  aWndChild[i][W],       //nWidth
                  aWndChild[i][H],       //nHeight
                  hWnd,                  //hWndParent
                  i,                     //ID
                  hInstDLL,              //hInstance
                  0);                    //lpParam
      //Set font and text
      SetWndFontAndText(aWndChild[i][HWND], hGuiFont, aWndChild[i][TXT]);
    }

    AkelPad.SendMessage(hWnd, 0x0080 /*WM_SETICON*/, 0 /*ICON_SMALL*/, hIconSmall);

    //Set TabStops in listbox
    SetTabStopsLB(aWndChild[IDCHILDWNDLB][HWND], [40, 70, 100, 220]);

    //Fill listbox
    for (i = 0; i < aListChild.length; ++i)
      AkelPad.SendMessage(aWndChild[IDCHILDWNDLB][HWND], 0x0180 /*LB_ADDSTRING*/, 0,
                          aListChild[i].ID + "\t" +
                          YesOrNo(aListChild[i].Visible) + "\t" +
                          YesOrNo(aListChild[i].Enabled) + "\t" +
                          aListChild[i].Class + "\t" +
                          aListChild[i].Text.replace(/[\r\n]/g, " "));
    AkelPad.SendMessage(aWndChild[IDCHILDWNDLB][HWND], 0x0186 /*LB_SETCURSEL*/, 0, 0);
    ShowChildWndData();

    hFocusChild = aWndChild[IDCHILDWNDLB][HWND];
  }

  else if ((uMsg == 6 /*WM_ACTIVATE*/) && (wParam == 0 /*WA_INACTIVE*/))
    hFocusChild = oSys.Call("User32::GetFocus");

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

  else if (uMsg == 256 /*WM_KEYDOWN*/)
  {
    if (wParam == 27 /*VK_ESCAPE*/)
      oSys.Call("User32::PostMessage" + _TCHAR, hWnd, 16 /*WM_CLOSE*/, 0, 0);
  }

  else if (uMsg == 260) //WM_SYSKEYDOWN
  {
    if (wParam == 0x31) //1 key
      oSys.Call("User32::SetFocus", aWndChild[IDCHILDWNDLB][HWND]);
  }

  else if (uMsg == 273) //WM_COMMAND
  {
    if (LoWord(wParam) == IDCHILDWNDLB)
    {
      if (HiWord(wParam) == 1 /*LBN_SELCHANGE*/)
        ShowChildWndData();
    }
  }

  else if (uMsg == 16) //WM_CLOSE
  {
    oSys.Call("User32::EnableWindow", hWndDlg, 1);
    oSys.Call("User32::DestroyWindow", hWnd);
  }

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

  return 0;
}

function ShowChildWndData()
{
  var nInd = AkelPad.SendMessage(aWndChild[IDCHILDWNDLB][HWND], 0x0188 /*LB_GETCURSEL*/, 0, 0);

  oSys.Call("User32::SetWindowText" + _TCHAR, aWndChild[IDCHILDCOUNT][HWND],
            (nInd + 1).toString() +
            "/" +
            aListChild.length.toString());

  if (nInd >= 0)
  {
    oSys.Call("User32::SetWindowText" + _TCHAR, aWndChild[IDCHILDHANDLEE  ][HWND], HexAndDec(aListChild[nInd].Handle));
    oSys.Call("User32::SetWindowText" + _TCHAR, aWndChild[IDCHILDSTYLEE   ][HWND], HexAndDec(aListChild[nInd].Style));
    oSys.Call("User32::SetWindowText" + _TCHAR, aWndChild[IDCHILDEXSTYLEE ][HWND], HexAndDec(aListChild[nInd].ExStyle));
    oSys.Call("User32::SetWindowText" + _TCHAR, aWndChild[IDCHILDLOCATIONE][HWND],
              "X=" + aListChild[nInd].X.toString() + ", " +
              "Y=" + aListChild[nInd].Y.toString());
    oSys.Call("User32::SetWindowText" + _TCHAR, aWndChild[IDCHILDSIZEE    ][HWND],
              "W=" + aListChild[nInd].W.toString() + ", " +
              "H=" + aListChild[nInd].H.toString());
  }
}

function EnumTopLevelWindows(nTitle, nVisible, nMinimized, nMaximized, nSize, nTopMost, nToolWin)
{
  var aWnd = [];
  var lpInfo;
  var hMenu;
  var sTitle;
  var bVisible;
  var bMinimized;
  var bMaximized;
  var nX;
  var nY;
  var nW;
  var nH;
  var bTopMost;
  var sClass;
  var nPID;
  var nTID;
  var hProcess;
  var sFileName;
  var sBaseName;

  try
  {
    oSys.RegisterCallback(EnumWindowsProc);
  }
  catch (oError)
  {
    AkelPad.MessageBox(hWndDlg, 'Unable to register callback function: "EnumWindowsProc".', sScripName, 0x10 /*MB_ICONERROR*/);
    return 0;
  }

  lpInfo = AkelPad.MemAlloc(260 * _TSIZE);

  oSys.Call("User32::EnumWindows", EnumWindowsProc, 0);

  oSys.UnregisterCallback(EnumWindowsProc);
  AkelPad.MemFree(lpInfo);

  return aWnd;

  function EnumWindowsProc(hWnd, lParam)
  {
    if (oSys.Call("User32::GetWindowText" + _TCHAR, hWnd, lpInfo, 260))
      sTitle = AkelPad.MemRead(lpInfo, _TSTR);
    else
      sTitle = "";

    hMenu      = oSys.Call("User32::GetMenu", hWnd);
    bVisible   = oSys.Call("User32::IsWindowVisible", hWnd);
    bMinimized = oSys.Call("User32::IsIconic", hWnd);
    bMaximized = oSys.Call("User32::IsZoomed", hWnd);

    if (oSys.Call("User32::GetWindowRect", hWnd, lpInfo))
    {
      nX = AkelPad.MemRead(_PtrAdd(lpInfo,  0), 3 /*DT_DWORD*/);
      nY = AkelPad.MemRead(_PtrAdd(lpInfo,  4), 3 /*DT_DWORD*/);
      nW = AkelPad.MemRead(_PtrAdd(lpInfo,  8), 3 /*DT_DWORD*/) - nX;
      nH = AkelPad.MemRead(_PtrAdd(lpInfo, 12), 3 /*DT_DWORD*/) - nY;
    }
    else
    {
      nX = 0;
      nY = 0;
      nW = 0;
      nH = 0;
    }

    bTopMost = oSys.Call("User32::GetWindowLong" + _TCHAR, hWnd, -20 /*GWL_EXSTYLE*/) & 0x00000008 /*WS_EX_TOPMOST*/;
    bToolWin = oSys.Call("User32::GetWindowLong" + _TCHAR, hWnd, -20 /*GWL_EXSTYLE*/) & 0x00000080 /*WS_EX_TOOLWINDOW*/;

    if (! (((nTitle == 0)     && sTitle)     || ((nTitle == 1)     && (! sTitle)) ||
           ((nVisible == 0)   && bVisible)   || ((nVisible == 1)   && (! bVisible)) ||
           ((nMinimized == 0) && bMinimized) || ((nMinimized == 1) && (! bMinimized)) ||
           ((nMaximized == 0) && bMaximized) || ((nMaximized == 1) && (! bMaximized)) ||
           ((nSize == 0)      && (nW + nH))  || ((nSize == 1)      && (! (nW + nH))) ||
           ((nTopMost == 0)   && bTopMost)   || ((nTopMost == 1)   && (! bTopMost)) ||
           ((nToolWin == 0)   && bToolWin)   || ((nToolWin == 1)   && (! bToolWin))))
    {
      if (oSys.Call("User32::GetClassName" + _TCHAR, hWnd, lpInfo, 260))
        sClass = AkelPad.MemRead(lpInfo, _TSTR);
      else
        sClass = "";

      nTID = oSys.Call("User32::GetWindowThreadProcessId", hWnd, lpInfo);
      nPID = AkelPad.MemRead(lpInfo, 3 /*DT_DWORD*/);

      hProcess = oSys.Call("Kernel32::OpenProcess", 0x0410 /*PROCESS_QUERY_INFORMATION|PROCESS_VM_READ*/, 0, nPID);

      if (oSys.Call("Psapi::GetModuleFileNameEx" + _TCHAR, hProcess, 0, lpInfo, 260))
        sFileName = AkelPad.MemRead(lpInfo, _TSTR);
      else
        sFileName = "<unknown>";

      if (oSys.Call("Psapi::GetModuleBaseName" + _TCHAR, hProcess, 0, lpInfo, 260))
        sBaseName = AkelPad.MemRead(lpInfo, _TSTR);
      else
        sBaseName = "<unknown>";

      oSys.Call("Kernel32::CloseHandle", hProcess);

      aWnd.push({Handle    : hWnd,
                 Menu      : hMenu,
                 Title     : sTitle,
                 Visible   : bVisible,
                 Minimized : bMinimized,
                 Maximized : bMaximized,
                 X         : nX,
                 Y         : nY,
                 W         : nW,
                 H         : nH,
                 TopMost   : bTopMost,
                 ToolWin   : bToolWin,
                 Class     : sClass,
                 PID       : nPID,
                 TID       : nTID,
                 FileName  : sFileName,
                 BaseName  : sBaseName});
    }

    return true;
  }
}

function EnumChildWindows(hWndParent)
{
  var oSys = AkelPad.SystemFunction();
  var aWnd = [];
  var lpInfo;
  var sText;
  var nX;
  var nY;
  var nW;
  var nH;
  var sClass;

  try
  {
    oSys.RegisterCallback(EnumChildProc);
  }
  catch (oError)
  {
    AkelPad.MessageBox(hWndDlg, 'Unable to register callback function: "EnumChildProc".', sScripName, 0x10 /*MB_ICONERROR*/);
    return aWnd;
  }

  lpInfo = AkelPad.MemAlloc(260 * _TSIZE);

  oSys.Call("User32::EnumChildWindows", hWndParent, EnumChildProc, 0);

  oSys.UnregisterCallback(EnumChildProc);
  AkelPad.MemFree(lpInfo);

  return aWnd;

  function EnumChildProc(hWnd, lParam)
  {
    if (AkelPad.SendMessage(hWnd, 0x000D /*WM_GETTEXT*/, 260, lpInfo))
      sText = AkelPad.MemRead(lpInfo, _TSTR);
    else
      sText = "";

    if (oSys.Call("User32::GetWindowRect", hWnd, lpInfo))
    {
      nX = AkelPad.MemRead(_PtrAdd(lpInfo,  0), 3 /*DT_DWORD*/);
      nY = AkelPad.MemRead(_PtrAdd(lpInfo,  4), 3 /*DT_DWORD*/);
      nW = AkelPad.MemRead(_PtrAdd(lpInfo,  8), 3 /*DT_DWORD*/) - nX;
      nH = AkelPad.MemRead(_PtrAdd(lpInfo, 12), 3 /*DT_DWORD*/) - nY;
    }
    else
    {
      nX = 0;
      nY = 0;
      nW = 0;
      nH = 0;
    }

    if (oSys.Call("User32::GetClassName" + _TCHAR, hWnd, lpInfo, 260))
      sClass = AkelPad.MemRead(lpInfo, _TSTR);
    else
      sClass = "";

    aWnd.push({Handle  : hWnd,
               Text    : sText,
               Visible : oSys.Call("User32::IsWindowVisible", hWnd),
               Enabled : oSys.Call("User32::IsWindowEnabled", hWnd),
               X       : nX,
               Y       : nY,
               W       : nW,
               H       : nH,
               Class   : sClass,
               Style   : oSys.Call("User32::GetWindowLong" + _TCHAR, hWnd, -16 /*GWL_STYLE*/),
               ExStyle : oSys.Call("User32::GetWindowLong" + _TCHAR, hWnd, -20 /*GWL_EXSTYLE*/),
               ID      : oSys.Call("User32::GetWindowLong" + _TCHAR, hWnd, -12 /*GWL_ID*/)});

    return true;
  }
}

function ReadWriteIni(bWrite)
{
  var oFSO     = new ActiveXObject("Scripting.FileSystemObject");
  var sIniFile = WScript.ScriptFullName.substring(0, WScript.ScriptFullName.lastIndexOf(".")) + ".ini";
  var sIniTxt;
  var oFile;
  var oRect;
  var i;

  if (bWrite)
  {
    oRect   = GetWindowPos(hWndDlg);
    sIniTxt = "nWndX="    + oRect.X  + ";\r\n" +
              "nWndY="    + oRect.Y  + ";\r\n" +
              "nTitle="   + nTitle   + ";\r\n" +
              "nVisible=" + nVisible + ";\r\n" +
              "nMinim="   + nMinim   + ";\r\n" +
              "nMaxim="   + nMaxim   + ";\r\n" +
              "nSize="    + nSize    + ";\r\n" +
              "nTopMost=" + nTopMost + ";\r\n" +
              "nToolWin=" + nToolWin + ";";

    oFile = oFSO.OpenTextFile(sIniFile, 2, true, -1);
    oFile.Write(sIniTxt);
    oFile.Close();
  }

  else if (oFSO.FileExists(sIniFile))
  {
    oFile = oFSO.OpenTextFile(sIniFile, 1, false, -1);

    try
    {
      eval(oFile.ReadAll());
    }
    catch (oError)
    {
    }

    oFile.Close();
  }
}

Last edited by KDJ on Fri Aug 05, 2016 9:30 pm, edited 10 times in total.

Offline
Posts: 3217
Joined: Wed Nov 29, 2006 1:19 pm
Location: Киев, Русь
Contact:

Post by VladSh »

Code: Select all

// http://akelpad.sourceforge.net/forum/viewtopic.php?p=15158#p15158
// Description(1033): Add the current word to the white list
// Description(1049): Добавление текущего слова в белый список проверки орфографии
// Version: 1.4 (2015.01.17)
// Author: VladSh
// 
// Arguments:
// 	ext     - adding the word to <ext>.spck-file
// 	newline - simbol of new line:
// 		"Mac"   = '\r'
// 		["Linux"] or without argument = '\n'
// 		"Win" or other = '\r\n'
// 	enc     - codepage of *.spck-file; examples (down - from the smallest to the largest file weight):
// 		20866   - KOI8 (R);
// 		21866   - KOI8-U;
// 		1251    - ANSI;
// 		[65001] or without argument - UTF8 (without BOM);
// 		1200    - UTF-16LE.
// 
// Usage:
// 	-"В белый список (txt)" Call("Scripts::Main", 1, "SpellCheckAddToWhiteList.js", `-ext="txt" -enc=1251`) - ANSI с '\n'
// 	-"В белый список (txt)" Call("Scripts::Main", 1, "SpellCheckAddToWhiteList.js", `-ext="txt" -newline="Win"`) - UTF8 с '\r\n'

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

var sWord = getWordCaret();
if (!sWord) WScript.Quit();

var fso = new ActiveXObject("Scripting.FileSystemObject");

var pFileExt = AkelPad.GetArgValue("ext", "") || fso.GetExtensionName(AkelPad.GetEditFile(0)) || "txt";

var sFileNameFull = AkelPad.GetAkelDir(4) + "\\SpellCheck\\" + pFileExt + ".spck";

var newline = AkelPad.GetArgValue("newline", "Linux");
if (newline == "Linux")
	newline = '\n';
else {
	if (newline == "Mac")
		newline = '\r';
	else
		newline = '\r\n';
}
var enc = AkelPad.GetArgValue("enc", 65001);		//UTF-8 by default

var sAddedText = "|" + sWord;

if (AkelPad.WriteFile(sFileNameFull, sAddedText + newline, -1, enc, false, 0x1|0x2 /*WFF_WRITEREADONLY|WFF_APPENDFILE*/) == 0) {
	
	AkelPad.Call("SpellCheck::Background", 1, newline + "+" + pFileExt + newline + sAddedText + newline);
	
	// обход бага http://akelpad.sourceforge.net/forum/viewtopic.php?p=25397#p25397
	AkelPad.Call("Scripts::Main", 1, "SpellCheckUnderlightSwitcher.js");
	AkelPad.Call("Scripts::Main", 1, "SpellCheckUnderlightSwitcher.js");
}
N.B.: this script used CaretSelect.js


Code: Select all

// Description(1033): Enable/Disable highlighting misspelled words
// Description(1049): Включение/отключение подчёркивания неправильно набранных слов
// http://akelpad.sourceforge.net/forum/viewtopic.php?p=15158#p15158
// Version: 1.2 (2012.01.17)
// Author: VladSh
// 
// Usage:
// 	-"Правописание: подсветить" Call("Scripts::Main", 1, "SpellCheckUnderlightSwitcher.js", `"txt"`) Icon("%a\AkelFiles\Plugs\Toolbar\spellcheck-error.ico")

var pFunc = "SpellCheck::Background";

if (AkelPad.IsPluginRunning(pFunc))
	AkelPad.Call(pFunc);
else {
	var fileExt = AkelPad.GetArgLine();
	if (!fileExt) {
		if (!AkelPad.GetEditFile(0))
			fileExt = "txt";
		else
			fileExt = 0;		//инициируем авто-определение расширения
	}
	AkelPad.Call(pFunc, 0, fileExt);
}


Code: Select all

// Description(1033): Show area/window code navigation
// Description(1049): Отображение области/окна навигации по коду
// http://akelpad.sourceforge.net/forum/viewtopic.php?p=15158#p15158
// Version: 1.4 (2015.01.14)
// Author: VladSh
// 
// Usage:
// 	-"Область навигации слева" Call("Scripts::Main", 1, "CodeFoldSwitcher.js") Icon("%a\AkelFiles\Plugs\Coder.dll", 1)		-	при отключении отключает и окошко, т.к. окошко без области слева вывести невозможно (
// 	-"Окно навигации..." Call("Scripts::Main", 1, "CodeFoldSwitcher.js", `-ShowDock=1`) Icon("%a\AkelFiles\Plugs\Coder.dll", 3)		-	отображает область с окошком, скрывает только окошко
// 	-"Область навигации с окном" Call("Scripts::Main", 1, "CodeFoldSwitcher.js", `-ShowDock=1 -hideAll=1`) Icon("%a\AkelFiles\Plugs\Coder.dll", 3)		-	отображает область с окошком и скрывает их все

var pParameterName = "ShowDock";

var nShowArg = AkelPad.GetArgValue(pParameterName, 0);		//наличие окошка: командуем при вызове
var nHideAll = AkelPad.GetArgValue("hideAll", 0);

var pPluginFileName = "Coder";
var oSet = AkelPad.ScriptSettings();
var nType = 1 /*PO_DWORD*/;

var nShowDock;		//наличие окошка: что имеется в настройках

if (oSet.Begin(pPluginFileName, 0x21 /* POB_PLUGS + POB_READ */)) {
	nShowDock = oSet.Read(pParameterName, nType) || 0;
	oSet.End();
}

var cf = pPluginFileName + "::CodeFold";
if (AkelPad.IsPluginRunning(cf)) {
	if (nShowArg) {
		AkelPad.Call(cf, 1);
		if (nHideAll && nShowDock)		//на строчке выше ShowDock изменился, но если он раньше был включен, значит надо погасить
			AkelPad.Call(cf);	//выключаем плаг
	}
	else {
		if (nShowDock)
			AkelPad.Call(cf, 1);	//выключаем окошко
		AkelPad.Call(cf);	//выключаем плаг
	}
}
else {
	if (!nShowArg && nShowDock) {
		//для случая, когда окно включать ненужно, но в ini указано ShowDock=1 (мог остаться там при нажатии стандартных кнопок либо закрывалась прога с открытым окном)
		if (oSet.Begin(pPluginFileName, 0x22 /* POB_PLUGS + POB_SAVE */)) {
			nShowDock = oSet.Write(pParameterName, nType, 0);
			oSet.End();
		}
	}
	
	AkelPad.Call(cf);	//загружаем плаг - включается область навигации слева и то, что указано в ShowDock в ini
	
	if (nShowArg && !nShowDock)		//для случая, когда окно нужно включить, а в ini ShowDock=0, ещё одним запуском с "1" выводим и окошко
		AkelPad.Call(cf, 1);
}


Code: Select all

// Description(1033): Displaying group of special characters
// Description(1049): Отображение групп специальных символов
// http://akelpad.sourceforge.net/forum/viewtopic.php?p=15158#p15158
// Version: 1.0 (2012.09.12)
// Author: VladSh
// 
// Usage:
// 	-"Спецсимволы: Пробелы и Табуляции" Call("Scripts::Main", 1, "SpecialCharSwitcher.js", `"1,2,4,5,6"`)
// 	-"Сбросить" Call("Scripts::Main", 1, "SpecialCharSwitcher.js", `"0"`) - без выключения плага
// 	-"Выключить" Call("Scripts::Main", 1, "SpecialCharSwitcher.js")

var fSpecialCharMain = "SpecialChar::Main";
var fSpecialCharSettings = "SpecialChar::Settings";
var scCodes = AkelPad.GetArgLine();

// не запускать, когда плаг включён и переданы коды символов
if (!(AkelPad.IsPluginRunning(fSpecialCharMain) && scCodes) || (AkelPad.IsPluginRunning(fSpecialCharMain) && !scCodes)) {
	AkelPad.Call(fSpecialCharMain);
}

if (scCodes) {
	AkelPad.Call(fSpecialCharSettings, 1, "1,2,3,4,5,6,7,8", "0", "0", 0, 0)	// сброс отображения всех установленных символов
	
	if (scCodes != "0")
		AkelPad.Call(fSpecialCharSettings, 1, scCodes, "0", "0", -1, -1);
}
Last edited by VladSh on Sat Jan 17, 2015 4:51 pm, edited 20 times in total.
Post Reply