Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I appear to have followed this example (found under "Defining Your Own Event Class"), and my code compiles and runs without error, but I'm not catching the event anywhere.

The code:

class MyCustomEvent : public wxEvent
{
//... stuff here
};
wxDEFINE_EVENT(MY_CUSTOM_EVENT_1,MyCustomEvent);

and later I bind the event:

Bind(MY_CUSTOM_EVENT_1, &MyApp::OnProcessCustom, this);

and later I throw an event of that type:

MyCustomEvent* eventCustom = new MyCustomEvent(MY_CUSTOM_EVENT_1);
eventCustom->SetEventObject(this);
this->QueueEvent(eventCustom); //this is MyApp

Unfortunately, after the event is thrown, it's never caught by OnProcessCustom.

Any ideas?

Note: Similar, but not the same as this question.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
738 views
Welcome To Ask or Share your Answers For Others

1 Answer

Your code looks correct so the problem is probably in the part you're not showing. Just notice that don't need to pass this as last argument to Bind() if you're calling it from a MyApp method.

I'd also advise looking at the event sample, it has working code defining a custom event (albeit using wxCommandEvent instead of a custom class but you can easily modify it to use your class instead).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...