Dude!! (..and I don't use that word often!)
The "clean" solution I will have to dig into and study, but...
The wx help mentioned wxSafeYield to avoid some of the problems you
mentioned about wxYield.
I just added wxSafeYield() at the bottom of the loop, and it works great. Should I
still try to avoid even the wxSafeYield()?
Thanks very much, I was nowhere near finding this function on my own.
Code: Select all
void MouseFrm::WxSpinButton1Up(wxSpinEvent& event)
{
bool mouseButtonDown = TRUE;
int n = 1;
wxMouseState mouse_state;
while(mouseButtonDown == TRUE){
WxMemo1->SetValue(wxString::Format(wxT("%d"),n));
n++;
mouse_state = wxGetMouseState();
mouseButtonDown = mouse_state.LeftIsDown();
WxMemo1->SetValue(wxString::Format(wxT("%d"),n));
wxSafeYield();
}
}
Edit...
It still had one quirk left: it stopped updating the display after about half a second.
I added CaptureMouse() and ReleaseMouse and it fixed this last problem. Also added
a 50ms Sleep function so it doesn't test the mouse continuosly (it was using a lot of
cpu time).
Here is what I have so far:
Code: Select all
void MouseFrm::WxSpinButton1Up(wxSpinEvent& event)
{
bool mouseButtonDown = TRUE;
int n = 1;
wxMouseState mouse_state;
CaptureMouse();
while(mouseButtonDown == TRUE){
WxMemo1->SetValue(wxString::Format(wxT("%d"),n));
n++;
Sleep(50);
mouse_state = wxGetMouseState();
mouseButtonDown = mouse_state.LeftIsDown();
if(mouseButtonDown == TRUE){
wxSafeYield();
}
}
ReleaseMouse();
}