Link to home
Start Free TrialLog in
Avatar of zattz
zattz

asked on

Add an item to a listbox in another running process

I have a running process (not my own) and I want to add an item to a listbox.

I have the handle of the listbox control, can somebody give me some code to add an item to it?

thanks
ASKER CERTIFIED SOLUTION
Avatar of TName
TName

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TName
TName

Oops, sorry, if it's supposed to be the last item, it should be:

SendMessage(hnd, LB_INSERTSTRING,Count,Integer(pc));
Avatar of Russell Libby
Yep... one of the few exceptions where you can send(message) a string to a remote process without first allocating memory in the remote process. You can also just pass (-1) as the index if you want to append to the list (no need to get count)

Russell
>You can also just pass (-1) as the index if you want to append to the list (no need to get count)

Thanks, I wasn't aware of that :)

And I just see there's also LB_ADDSTRING.
So zattz, in fact if you already have the LB handle, all you really need is a line like:
SendMessage(hnd, LB_INSERTSTRING,-1,Integer(PChar('TestString')));

or
SendMessage(hnd, LB_ADDSTRING,0,Integer(PChar('TestString')));

Avatar of zattz

ASKER

Thanks Guys:)

Worked perfectly.

Except that I made a mistake and actually wanted to send to a combobox so I changed LB_ADDSTRING to CB_ADDSTRING