Here's the source of some of your problems:
from play_control.h:
//important: you should call api commands declared in this header ONLY from main thread !!
I've got no clue how you can work around that, but then, I don't know the internal structure of wsgui, so I've got no clue why you're even using separate threads.
Well, that explains a lot. This is my first attempt at using WTL (Windows Template Library) and I was under the mistaken impression that I needed something like this to drive my window.
MSG msg;
while (sRunning && GetMessage ( &msg, NULL, 0, 0 ) > 0 )
{
TranslateMessage ( &msg );
DispatchMessage ( &msg );
}
The only way to do that was with a thread and I was creating a thread to run that.
The above is not needed at all - I didn't realize how the message loop worked in general I guess. My window still gets messages without the above and this happens in the context of the "main thread".
So, I removed the threaded message pump and voila I can set the focused item
Now I'm still having problems with playlist_find not working but I can focus on that now and try to get you some better information.
One thing I noticed is when it stops working I get access violations in foobar every time I type a key in the playlist_find edit box.
First-chance exception in foobar2000.exe: 0xC0000005: Access Violation.
I also noticed I get
metadb_handle leaks, 22 objects
when I close foobar if I have run playlist_find but not if I haven't run playlist_find. I have 22 items in my playlist.
This might be related to
bool do_matching(const char * str, int playlist_index) {
static string8 out;
out.reset();
if (search_list)
search_list->get_item(playlist_index)->handle_format_title(out,get_search_format(),NULL);
else
g_oper->get_item(playlist_index)->handle_format_title(out,get_search_format(),NULL);
but I'm not sure (ie. get_item returns a ref'ed handle? ).