XP is just a number | |
PerlMonks |
Win32::GUI sending Windows messages between threads [solved]by shadrack (Acolyte) |
on Jan 17, 2013 at 09:07 UTC ( [id://1013733]=perlquestion: print w/replies, xml ) | Need Help?? |
shadrack has asked for the wisdom of the Perl Monks concerning the following question:
Running strawberry perl 5.16.2 under XP. I've got a multi-threaded program (parent thread runs the GUI, child is the "worker"). I want the child to send some sort of "wake up" signal to the parent when it has information to pass (via shared variables). The problem is the GUI thread is stuck running Win32::GUI::Dialog(), so it doesn't receive signals and polling isn't possible (not to mention inefficient). Anyway, it occurs to me that really all I have to do is send the parent a Windows message which I've set up to be handled by a custom function which does whatever I want it to do (in this case, it would process the information stored in the shared variables). WM_TIMER seemed to be a good candidate for this message, but I can't for the life of me figure out how to make this work. Here's the test, boiled down to the essentials:
If I run the above code, I never see the "Timer fired" message. However, if I change the SendMessage() call to use WM_CLOSE instead of WM_TIMER, the gui closes (as expected), which I take to be evidence that the theory is sound. I just can't figure out how to get it to work with WM_TIMER or some other message that I can intercept with my own handler. Any suggestions? Oh, and before somebody suggests it, yes I know polling is possible with DoEvents(), however under certain circumstances, DoEvents() can take an indefinite amount of time to return which makes the polling cycle too unpredictable for this particular application. Update: I believe I've solved it. Thanks to roboticus' prodding, I dug a little deeper into trying to use WM_USER and I eventually figured it out. Set up the handler with $WinMain->Hook(WM_USER, \&coderef); (also you'd need to add WM_USER to the constants imported in "use Win32::GUI qw(...". I'm still not sure why it fails with WM_TIMER, but the end result solves my problem. Thanks all!
Back to
Seekers of Perl Wisdom
|
|