Scripts discussion (2)

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 »


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

Post by KDJ »

Gentlemen, if anyone can help me in this topic:
viewtopic.php?p=17639&hilit=#p17639

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

Post by FeyFre »

KDJ
Fixed: conflict with Templates plugin.
You have used very destructive workaround. There is direct direct solution. I show it on instance of SelectionOpenInTab.js, it applicable to other scripts.
unloading/reloading plugin(and Templates plugin can be not alone who intercepts IDM_FILE_NEW so you will be forced to unload/reload them all) by

Code: Select all

  if (bTemplates = AkelPad.IsPluginRunning("Templates::Main")) 
     AkelPad.Call("Templates::Main"); 

   pSelTxt = AkelPad.GetSelText(); 

   AkelPad.Command(4101); 
   AkelPad.ReplaceSel(pSelTxt); 

   if (bTemplates) 
     AkelPad.Call("Templates::Main");

make special invocation of IDM_FILE_NEW command.

Code: Select all

   pSelTxt = AkelPad.GetSelText(); 

   AkelPad.SendMessage(AkelPad.GetMainWnd(), WM_COMMAND, 4101/*wParam=MAKEWAPARAM(0,IDM_FILE_NEW)*/, 1/*lParam=TRUE*/);
   AkelPad.ReplaceSel(pSelTxt);
In fact, this trick used to allow run both Templates & Sessions plugins
(wow, I wrote this word correctly on first retry.)
.
Last edited by FeyFre on Fri Apr 13, 2012 8:00 pm, edited 1 time in total.

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

Post by FeyFre »

Gentlemen, if anyone can help me in this topic:
But I don't know, how to get the handle to the icon contained in a file (.exe, .dll or .ico).
Maybe using LoadIcon() or LoadImage() functions.
You are on the right way. Preferred way is to use user32.dll LoadImageA/W. You can read more here. Do not forget to use DestroyIcon on received handle after it is not needed any more.

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

Post by KDJ »

FeyFre wrote:Yo can just make special invocation of IDM_FILE_NEW command.
Great, now the entire script takes only four lines.

Code: Select all

var pSelTxt;
if (AkelPad.GetEditWnd() && (AkelPad.IsMDI() > 0) && (pSelTxt = AkelPad.GetSelText()))
{
  AkelPad.SendMessage(AkelPad.GetMainWnd(), 273 /*WM_COMMAND*/, 4101 /*wParam=MAKEWPARAM(0,IDM_FILE_NEW)*/, 1 /*lParam=TRUE*/);
  AkelPad.ReplaceSel(pSelTxt);
}

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

Post by KDJ »

FeyFre wrote:You are on the right way. Preferred way is to use user32.dll LoadImageA/W.
I need to get the icon from Scripts.dll.
Unfortunately, the following code does not work:

Code: Select all

hIcon = AkelPad.SystemFunction().Call("User32::LoadImageW",
  AkelPad.GetInstanceDll(), //hinst
  "1",                      //lpszName
  1,                        //uType=IMAGE_ICON
  0,                        //cxDesired
  0,                        //cyDesired
  0x00000040);              //fuLoad=LR_DEFAULTSIZE
WScript.Echo(hIcon);
How to do this?

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

Post by Instructor »

KDJ

Code: Select all

var oSys=AkelPad.SystemFunction();
var hIconScripts=oSys.Call("user32::LoadIcon" + _TCHAR, AkelPad.GetInstanceDll(), 101 /*IDI_ICON_PLUGIN*/);
AkelPad.SendMessage(AkelPad.GetMainWnd(), 0x0080 /*WM_SETICON*/, 1 /*ICON_BIG*/, hIconScripts);

...
oSys.Call("user32::DestroyIcon", hIconScripts);

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

Post by KDJ »

Yes, this is what I needed:
101 /*IDI_ICON_PLUGIN*/
Thank you very much, Instructor.

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

Post by FeyFre »

Yes, it will not work, although it is absolutely correct.

Each resource item stored in PE Image(.exe .dll etc) have 3 properties which can be used to identify item. They are: resource type (predefined(ICON,DIALOG,BITMAP,STRING) and custom one), resource localization(for each language labels in respective language, LANGID constants from PlatformSDK), and resource item IDentifier.
LANGID is word sized constants(lang+sublang).
Resource type: predefined types are word sized constants(0..0xFFFF), custom - strings.
Resource ID: is word sized numbers(0..0xFFFF) and strings.

What I mean. One resource icon can be identified by number 555, and absolutely other icon can be identified by string "555". These icons are not the same icons. And programmer can give human readable resource ID to each resource instead of awkward numbers(This is what Qt toolkit does in its Windows port - all resource items are identified by strings).

Instructor managed to give you correct variant before me, but I will repeat.

Your code tried to load icon resource from DLL identified by "1". There is no ICON resource in Scripts.DLL identified by "1". There is ICON identified by 101.
Do not regret. This are typical errors(to mismatch string and number and to mismatch item identifier(101 in our case) and its ordinal(1 - first icon in DLL in out case) number in resource directory in PE Image). If you notice all function which have deals with resource IDs have both variants A and W, and ID argument always have type of LPCTSTR. That is because resource IDs in string form. And in order to give resource ID in number form to them in C there are used macros MAKEINTRESOURCEA/W, which receive integer number an cast it to LPCTSTR. In out JScript, there is no need to use any typecasts, and both number and string form can be used without additional casts. Sou your correct script is

Code: Select all

hIcon = AkelPad.SystemFunction().Call("User32::LoadImage"+_TCHAR, 
   AkelPad.GetInstanceDll(), //hinst 
   101,                      //lpszName 
   1,                        //uType=IMAGE_ICON 
   0,                        //cxDesired 
   0,                        //cyDesired 
   0x00000040);              //fuLoad=LR_DEFAULTSIZE 
 WScript.Echo(hIcon);

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

Post by KDJ »

I opened Scripts.dll using ResourceHacker.
There are two resources for icons: "Icon" and "Icon Group".
I thought, that proper is "Icon" resource (Icon:1, Icon:2).
But it is to be "Icon Group" (Icon Group:101).

Image

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

Post by KDJ »

CSVToColumnText.js
FileInfo.js
PluginText.js
PlugTextReadFromIni.js
PlugTextToAkelPad.js
SelectionOpenInTab.js

Changed: solution of conflict with Templates plugin, according to FeyFre idea.

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

Post by KDJ »

InputBox_function.js

Added: icon from Scripts.dll on title bar.
Changed: now window width adjusts to the length of title string and label string.

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

Post by KDJ »

InputBox_function.js

Added: possibility to input multiple values.


Image

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

Post by Andrey_A_A »

Infocatcher у Вас есть скрипт moveResizeWindow.js, который изменяет положение/размеры окна. А можно ли сделать в нём параметр восстановления размеров и положения. К примеру мы растянули по ширине, а хочется вернуть обратно. Конечно в идеале было бы лучше , чтобы одна и та же кнопка и изменяла положение и возвращала при повторном нажатии

Offline
Posts: 1862
Joined: Mon Aug 06, 2007 1:07 pm
Contact:

Post by Infocatcher »

Andrey_A_A
Готово:
moveResizeWindow.js
Если окно уже находится в заданном положении, будет восстановлено предыдущее положение окна.
И добавлен параметр -allowRestore для возможности отключения (по умолчанию включено).
Locked