Scripts discussion (1)

Discuss and announce AkelPad plugins
Locked
  • Author
  • Message
KDJ
Offline
Posts: 1949
Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland

Post by KDJ »

Again, interesting. This time with VBS.

First function:

Code: Select all

Dim oSys, nFontSize
set oSys  = AkelPad.SystemFunction()
nFontSize = -oSys.Call("kernel32::MulDiv", -20, 72, 96)
WScript.Echo "nFontSize=" & nFontSize
Result nFontSize=15.

Second function:

Code: Select all

Dim oSys, lfHeight, nDevCap, nFontSize
set oSys  = AkelPad.SystemFunction()
lfHeight  = -20
nDevCap   = 96
nFontSize = -oSys.Call("kernel32::MulDiv", lfHeight, 72, nDevCap)
WScript.Echo "nFontSize=" & nFontSize
Result nFontSize=1.

What is the difference between these two functions?

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

Post by Instructor »

KDJ
I have made some modifications to Scripts plugin. In new version it should be OK, but in new version you need to avoid passing negative values to "kernel32::MulDiv".

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

Post by KDJ »

Instructor
For now I solved the problem by adding zero to the variable:
nFontSize = -oSys.Call("kernel32::MulDiv", lfHeight + 0, 72, nDevCap + 0)
But the same error occurs in the function gdi32::GetDeviceCaps.

Code: Select all

nDevCap = oSys.Call("gdi32::GetDeviceCaps", hDC,     LOGPIXELSY)
nDevCap = oSys.Call("gdi32::GetDeviceCaps", hDC + 0, LOGPIXELSY)
These functions return two different values (in VBS).
FontIniSize.vbs

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

Post by KDJ »

One more thing. I do not understand why the same function returns different values in JS and VBS:

Code: Select all

//JS
var lfHeight;
lfHeight = eval("0xFFFFFFF1");

Code: Select all

'VBS
Dim lfHeight
lfHeight = Eval("&HFFFFFFF1")
The result in JS is lfHeight=4294967281, in VBS lfHeight=-15.

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

Post by FeyFre »

KDJ
signed and unsigned values. Do not forget, JScript, VBScript and other script languages bind to WSH internally work with own typecast styles. Some languages even do not have neither implicit nor explicit integer typecasts.(because integers are not portable)

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

Post by KDJ »

Fixed CalculatorJS.js. The minus sign was incorrectly displayed in the hex and oct numbers.
In script FontIniSize.js add reading from the registry.

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

Post by Instructor »

В ChmKeyword.js добавлено закрытие CHM окна по Esc. А также залил на narod набор файлов помощи CHM для C/C++, CSS, HTML, VBS, JS, NSIS.

Cpp.chm это старый добрый "Microsoft® Win32® Programmer's Reference" (мини MSDN), который был доступен на скачивание в формате hlp. Чтобы его перевести в chm мне понадобилось 3 дня :) С частью конвертирования справился только "Help & Manual", остальные программы из опробованных не осилили такой объем hlp файла (24Mb), либо форматирование было далеко от оригинала. Для информации: если вы хотите воспользоваться взломанной версией программы, отключайтесь от интернета, а то результат конвертирования будет весьма забавный :)

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

Post by KDJ »

In the script LinesFilter.js the following code checks to see if ESC key was pressed.

Code: Select all

else if (uMsg == 256)  //WM_KEYDOWN
{
  if (wParam == 27)  //VK_ESCAPE
  {
    //Escape key pushes Cancel button
    oSys.Call("user32::PostMessage" + _TCHAR, hWndDialog, 273 /*WM_COMMAND*/, IDC_CANCEL, 0);
  }
How to check, that you have pressed Ctrl+Alt+Left or Ctrl+Alt+End?

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

Post by FeyFre »

KDJ
You should check modifier key state in VK_LEFT and VK_END handling routine:

Code: Select all

oSys.Call("user32::GetAsyncKeyState",0xA2/*VK_LCONTROL*/) & 0x80000000)
oSys.Call("user32::GetAsyncKeyState",0xA3/*VK_RCONTROL*/) & 0x80000000)
oSys.Call("user32::GetAsyncKeyState",0xA4/*VK_LMENU*/) & 0x80000000)
oSys.Call("user32::GetAsyncKeyState",0xA5/*VK_RMENU*/) & 0x80000000)
You must read more at MSDN about this syscall(there are may occur some problems with returned value(that why I added "& 0x80000000"))

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

Post by KDJ »

Thanks FeyFre.
I used it in the script ColumnsSum.js, to move the dialog box using the keyboard.

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

Post by FeyFre »

KDJ, you did good job. But in most cases, if user do not want to use mouse for window manipulation, he(she) will use Alt+Space hotkey to activate window's system menu and select Move(or even resize) item.

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

Post by KDJ »

I'm not entirely happy, because it works with keys "Ctrl+Alt", but do not want to work with keys "Shif+Alt".
Using "Ctrl+Alt+Right", also the caret moves in the edit box.

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

Post by Instructor »

KDJ

Code: Select all

else if (uMsg == 0x100 /*WM_KEYDOWN*/ ||
         uMsg == 0x104 /*WM_SYSKEYDOWN*/)

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

Post by KDJ »

Instructor
This is what I needed - WM_SYSKEYDOWN!
A big thank for you.

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

Post by VladSh »

Instructor
Скажите, что должен делать скрипт NsisCall.js? Он всегда выдаёт сообщение:
NsisCall.js wrote:---------------------------
c:\_1.txt
---------------------------
ОК
Locked