View Single Post
Old 01-24-2020, 09:09 PM   #916
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,921
Default

Quote:
Originally Posted by amagalma View Post
I tried to do the same with a ListBox but it didn't work. Any idea why? Is there any other way?
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
Quote:
Under certain conditions, the return value is larger than the actual length of the text. This occurs with certain mixtures of ANSI and Unicode, and is due to the operating system allowing for the possible existence of double-byte character set (DBCS) characters within the text. The return value, however, will always be at least as large as the actual length of the text; you can thus always use it to guide buffer allocation. This behavior can occur when an application uses both ANSI functions and common dialogs, which use Unicode.

To obtain the exact length of the text, use the WM_GETTEXT, LB_GETTEXT, or CB_GETLBTEXT messages, or the GetWindowText function.
So looks like were OK!

Last edited by Edgemeal; 01-25-2020 at 01:49 AM. Reason: Tweaked for 100th time! :-)
Edgemeal is offline   Reply With Quote