Scripts plugin

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

Post by KDJ »

Instructor
In the files Scripts-Eng.txt and Scripts-Rus.txt, in the list of methods is missing AkelPad.SetFrameInfo().

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

Post by Instructor »

KDJ
Corrected.

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

Post by Andrey_A_A »

Можно ли вставить метод AkelPad.Link(N)
Часто приходится заменять, вырезать ... ссылки
Хочу заменить ссылку и сразу сохранить файл. Не нашёл как это сделать, может есть другой способ?

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

Post by Instructor »

Andrey_A_A

Code: Select all

SelectLinkUnderCaret(AkelPad.GetEditWnd());

function SelectLinkUnderCaret(hWndEdit)
{
  var lpSel;
  var lpCaret;
  var bSelected=false;
  
  if (lpCaret=AkelPad.MemAlloc(_X64?24:12 /*sizeof(AECHARINDEX)*/))
  {
    AkelPad.SendMessage(hWndEdit, 3130 /*AEM_GETINDEX*/, 5 /*AEGI_CARETCHAR*/, lpCaret);
    if (lpSel=AkelPad.MemAlloc(_X64?56:28 /*sizeof(AESELECTION)*/))
    {
      if (AkelPad.SendMessage(hWndEdit, 3149 /*AEM_INDEXINURL*/, lpCaret, lpSel))
      {
        AkelPad.SendMessage(hWndEdit, 3126 /*AEM_SETSEL*/, lpCaret, lpSel);
        bSelected=true;
      }
      AkelPad.MemFree(lpSel);
    }
    AkelPad.MemFree(lpCaret);
  }
  return bSelected;
}

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

Post by Andrey_A_A »

Instructor, Спасибо!!! буду разбираться...

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

Post by KDJ »

Instructor
After calling AkelPad.MessageBox (extended version), the dialog box, from which the method has been called (hWndDlg), disappears.

Code: Select all

AkelPad.MessageBox(hWndDlg, "That is the question", "Message Box",
                   32 /*MB_ICONQUESTION*/, 0,
                   1 /*IDOK*/,     "&OK",     1 /*BMB_DEFAULT*/,
                   2 /*IDCANCEL*/, "&Cancel", 0);

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

Post by Instructor »

KDJ
Different threads SendMessage can cause GUI freeze.

One of the way avoiding this is hide dialog:

Code: Select all

  oSys.Call("user32::ShowWindow", hWndDlg, 0 /*SW_HIDE*/);
  AkelPad.MessageBox(hWndDlg, "That is the question", "Message Box",
                     32 /*MB_ICONQUESTION*/, 0,
                     1 /*IDOK*/,     "&OK",     1 /*BMB_DEFAULT*/,
                     2 /*IDCANCEL*/, "&Cancel", 0);
  oSys.Call("user32::ShowWindow", hWndDlg, 5 /*SW_SHOW*/);

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

Post by KDJ »

Instructor
It seems to me, that there is no need to hide dialog window, because it is hidden automatically after MessageBox (extended) call.
But I wanted to, in order to dialog box will be visible at all times.
Below I put the script that shows differences in the behavior of standard and extended MessageBox:

Code: Select all

var oSys         = AkelPad.SystemFunction();
var hInstanceDLL = AkelPad.GetInstanceDll();
var sClassName   = "AkelPad::Scripts::" + WScript.ScriptName + "::" + hInstanceDLL;
var hMainWnd     = AkelPad.GetMainWnd();
var hButton1;
var hButton2;

AkelPad.WindowRegisterClass(sClassName);
oSys.Call("user32::CreateWindowExW",
          0,                 //dwExStyle
          sClassName,        //lpClassName
          "MessageBox test", //lpWindowName
          0x90CA0000,        //dwStyle=WS_VISIBLE|WS_POPUP|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX
          300,               //x
          200,               //y
          270,               //nWidth
          140,               //nHeight
          hMainWnd,          //hWndParent
          0,                 //ID
          hInstanceDLL,      //hInstance
          DialogCallback);
oSys.Call("user32::EnableWindow", hMainWnd, 0);
AkelPad.WindowGetMessage();
AkelPad.WindowUnregisterClass(sClassName);

function DialogCallback(hWnd, uMsg, wParam, lParam)
{
  if (uMsg == 1) //WM_CREATE
  {
    hButton1 =
      oSys.Call("user32::CreateWindowExW",
                0,            //dwExStyle
                "BUTTON",     //lpClassName
                "&Standard",  //lpWindowName
                0x50010001,   //dwStyle
                20,           //x
                40,           //y
                100,          //nWidth
                25,           //nHeight
                hWnd,         //hWndParent
                0,            //ID
                hInstanceDLL, //hInstance
                0);           //lpParam
    hButton2 =
      oSys.Call("user32::CreateWindowExW",
                0,            //dwExStyle
                "BUTTON",     //lpClassName
                "&Extended",  //lpWindowName
                0x50010000,   //dwStyle
                140,          //x
                40,           //y
                100,           //nWidth
                25,           //nHeight
                hWnd,         //hWndParent
                0,            //ID
                hInstanceDLL, //hInstance
                0);           //lpParam
  }
  else if (uMsg == 7) //WM_SETFOCUS
    oSys.Call("user32::SetFocus", hButton1);
  else if (uMsg == 256) //WM_KEYDOWN
  {
    if (wParam == 27) //VK_ESCAPE
      oSys.Call("user32::PostMessageW", hWnd, 16 /*WM_CLOSE*/, 0, 0);
  }
  else if (uMsg == 273) //WM_COMMAND
  {
    if (lParam == hButton1)
      AkelPad.MessageBox(hWnd, "That is the question", "MessageBox Standard",
                         0x21 /*MB_ICONQUESTION|MB_OKCANCEL*/);
    else if (lParam == hButton2)
      AkelPad.MessageBox(hWnd, "That is the question", "MessageBox Extended",
                         0x20 /*MB_ICONQUESTION*/, 0,
                         1 /*IDOK*/,     "&OK",     1 /*BMB_DEFAULT*/,
                         2 /*IDCANCEL*/, "&Cancel", 0);
  }
  else if (uMsg == 16) //WM_CLOSE
  {
    oSys.Call("user32::EnableWindow", hMainWnd, 1);
    oSys.Call("user32::DestroyWindow", hWnd);
  }
  else if (uMsg == 2) //WM_DESTROY
    oSys.Call("user32::PostQuitMessage", 0);

  return 0;
}

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

Post by Instructor »

KDJ
There is no sense to make it visible because you will have GUI freezed. Extended dialog runs from main thread and you call it from its owner - Scripts dialog thread. This will cause GUI thread conflict.

You can try it by your own:

Code: Select all

  else if (uMsg == 273) //WM_COMMAND
  {
    if (lParam == hButton1)
      AkelPad.MessageBox(hWnd, "That is the question", "MessageBox Standard",
                         0x21 /*MB_ICONQUESTION|MB_OKCANCEL*/);
    else if (lParam == hButton2)
    {
      var dwCurThreadID=oSys.Call("kernel32::GetCurrentThreadId");
      var dwMainThreadID=oSys.Call("user32::GetWindowThreadProcessId", hMainWnd, 0);

      if (oSys.Call("user32::AttachThreadInput", dwCurThreadID, dwMainThreadID, true))
      {
        oSys.Call("user32::EnableWindow", hWnd, 0);
        AkelPad.MessageBox(hWnd, "That is the question", "MessageBox Extended",
                           0x20 /*MB_ICONQUESTION*/, 0,
                           1 /*IDOK*/,     "&OK",     1 /*BMB_DEFAULT*/,
                           2 /*IDCANCEL*/, "&Cancel", 0);
        oSys.Call("user32::EnableWindow", hWnd, 1);

        oSys.Call("user32::AttachThreadInput", dwCurThreadID, dwMainThreadID, false);
      }
    }
  }
Last edited by Instructor on Sun May 06, 2012 12:19 pm, edited 1 time in total.

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

Post by Instructor »

Добавлено: методы AkelPad.CallA, AkelPad.CallW, AkelPad.CallExA, AkelPad.CallExW.

Added: AkelPad.CallA, AkelPad.CallW, AkelPad.CallExA, AkelPad.CallExW methods.


Scripts plugin v10.8

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

Post by KDJ »

Instructor wrote:KDJ
There is no sense to make it visible because you will have GUI freezed. Extended dialog runs from main thread and you call it from its owner - Scripts dialog thread. This will cause GUI thread conflict.

You can try it by your own:

Code: Select all

  else if (uMsg == 273) //WM_COMMAND
  {
    if (lParam == hButton1)
      AkelPad.MessageBox(hWnd, "That is the question", "MessageBox Standard",
                         0x21 /*MB_ICONQUESTION|MB_OKCANCEL*/);
    else if (lParam == hButton2)
    {
      var dwCurThreadID=oSys.Call("kernel32::GetCurrentThreadId");
      var dwMainThreadID=oSys.Call("user32::GetWindowThreadProcessId", hMainWnd, 0);

      if (oSys.Call("user32::AttachThreadInput", dwCurThreadID, dwMainThreadID, true))
      {
        oSys.Call("user32::EnableWindow", hWnd, 0);
        AkelPad.MessageBox(hWnd, "That is the question", "MessageBox Extended",
                           0x20 /*MB_ICONQUESTION*/, 0,
                           1 /*IDOK*/,     "&OK",     1 /*BMB_DEFAULT*/,
                           2 /*IDCANCEL*/, "&Cancel", 0);
        oSys.Call("user32::EnableWindow", hWnd, 1);

        oSys.Call("user32::AttachThreadInput", dwCurThreadID, dwMainThreadID, false);
      }
    }
  }
It works a little better, but:
- is very complicated to use,
- if you switch to another window, AkelPad hangs.

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

Post by Instructor »

KDJ wrote:...but...
It is what I'm talking about.

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

Post by KDJ »

Instructor
Maybe you should write your own function MessageBox like InputBox?
Or maybe write a script?

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

Post by FeyFre »

Added: AkelPad.CallA, AkelPad.CallW, AkelPad.CallExA, AkelPad.CallExW methods.
Я так понимаю, они манипулируют вот этими?

Code: Select all

#define PDS_STRANSI      0x20000000  //Flag is set if caller passes Ansi strings in external call arguments (PLUGINDATA.lParam).
#define PDS_STRWIDE      0x40000000  //Flag is set if caller passes Unicode strings in external call arguments (PLUGINDATA.lParam).
                                     //If PDS_STRANSI and PDS_STRWIDE not specified then one of these flags will be set automatically depending on Windows version.
Тогда вопрос:
Что мне(плагинам) делать, если вдруг придет с тем что не поддерживается? У меня у плагинов стоит всегда ставится PDS_NOANSI, а кто-то возьмет и пришлет с PDS_STRANSI. Как минимум, что мне ставить в PLUGINDATA::nUnload ?

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

Post by Instructor »

FeyFre
Так можно:

Code: Select all

    //If plugin already loaded, stay in memory and don't change active status
    if (pd->bInMemory) pd->nUnload=UD_NONUNLOAD_UNCHANGE;
    return;
Post Reply