View Single Post
Old 01-25-2020, 03:16 AM   #916
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,458
Default

Quote:
Originally Posted by Edgemeal View Post
I'm pretty sure only way to read listbox item text is to use the LB_ messages and I don't think this extension has them defined so you'll have to add them , most of the LB_ msg I tried seem to work except LB_GETTEXTLEN, it returns a much higher value then the actual text lengths, so I guess as long as its not smaller it should be OK. , this seems to be working, but I'm just VB coder and normally don't use pointers, so assume I'm using JS_Mem_Alloc correctly?

Tested on listbox in Actions un-docked window,..

Code:
LB_GETTEXT = '0x189' -- API (as of v0.998) doesn't have LB_* messages defined.
LB_GETCOUNT = '0x18B'
LB_GETTEXTLEN = '0x18A'

actions = reaper.JS_Window_FindTop('Actions', true)
listbox = reaper.JS_Window_FindChildByID(actions, 0x531) -- assigned shortcuts listbox in Actions window.
itemCount = reaper.JS_WindowMessage_Send(listbox, LB_GETCOUNT, 0,0,0,0)

for i = 0, itemCount-1 do 
  bufSize = reaper.JS_WindowMessage_Send(listbox, LB_GETTEXTLEN, i,0,0,0)
  m = reaper.JS_Mem_Alloc(bufSize)
  txt_len = reaper.JS_WindowMessage_Send(listbox, LB_GETTEXT, i, 0, reaper.JS_Window_AddressFromHandle(m),0)
  retval, item_txt = reaper.JS_String(m, 0, txt_len)
  reaper.JS_Mem_Free(m)
  reaper.ShowConsoleMsg(item_txt..'\n')
end
From MSDN, LB_GETTEXTLEN message


So looks like were OK!

Hmm.. Doesn't seem to work with the ListBox of the Theme development/tweaker.. :/


Code:
local LB_GETTEXT, LB_GETCOUNT,LB_GETTEXTLEN  = '0x189', '0x18B', '0x18A'
t = {}
local wnd =  reaper.JS_Window_Find( "Theme development/tweaker", true )
local listbox = reaper.JS_Window_FindChildByID( wnd, 1209 )
itemCount = reaper.JS_WindowMessage_Send(listbox, LB_GETCOUNT, 0,0,0,0)
for i = 0, itemCount-1 do 
  local bufSize = reaper.JS_WindowMessage_Send(listbox, LB_GETTEXTLEN, i,0,0,0)
  local m = reaper.JS_Mem_Alloc(bufSize)
  txt_len = reaper.JS_WindowMessage_Send(listbox, LB_GETTEXT, i, 0, reaper.JS_Window_AddressFromHandle(m),0)
  retval, item_txt = reaper.JS_String(m, 0, txt_len)
  reaper.JS_Mem_Free(m)
  t[#t+1] = item_txt
  reaper.ShowConsoleMsg(item_txt..'\n')
end

It returns 'chinese'..
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)
amagalma is offline   Reply With Quote