in reply to Re^3: Release Button in Click
in thread Release Button in Click

Yes, I should have given the Win32::GUI context ... eyes glazed over from lengthy fruitless search before finally posting this question resulted in tunnel vision. v1.06 of Win32::GUI is in use here as well, not the older version packaged with LOFT. I've used the ploy of creating an invisible dummyButton which gets clicked or pushed under program control at the end of the Click handler for the button I want to pop, but neither of those events do it; control transfers to dummyButton's handlers without any change in the visual appearance of either Button. And that makes sense to me (though I'd hoped for some luck) because the calls to dummyButton occur in the context of the handler of the Button I want to release. As for the code I'm not showing; that's exactly the problem. Suppose I take control of any event of any button; what code will then trigger redrawing of a button pushed? Short of looking into Win32 itself, I can't find anything in the Perl environment. I hope I'm getting this across more successfully now.

Replies are listed 'Best First'.
Re^5: Release Button in Click
by kejohm (Hermit) on Sep 22, 2010 at 08:34 UTC

    It could be that the code in the event handler is taking a long time to complete, which means Win32::GUI won't have a chance to update the GUI, and the program will appear to hang. This includes redrawing controls. So if a lengthy piece of code is executed when a button is pressed, it will remain pressed until the code returns to the dialog loop. One solution to this problem is to periodically call Win32::GUI::DoEvents() in your code to allow Win32::GUI to process any pending events. Example:

    sub Button_Click { while(1){ # do something... Win32::GUI::DoEvents(); } return 1; }
      The event handler activities are fairly time-consuming, and each already ends with a call to DoEvents() after all widgets in the interface that accept user input have been polled (eachTextfield_Change() or eachCombobox_Change()). However even after the event handler concludes and control returns to the main Dialog() loop, the active button is not redrawn with a released appearance. It remains pushed until the user pressed another button. And that's the objective: to trigger a redraw when the handler finishes to tell the user processing is done.

        You could try using one of the Update()/InvalidateRect()/Redraw() methods on the button at the end of the event handler. Alternatively, you could try running the event handler code in a thread to see if this makes any difference to the button's appearance.