wxEvent derived event Topic is solved
-
- Knows some wx things
- Posts: 35
- Joined: Wed Sep 08, 2004 6:22 am
wxEvent derived event
Hello,
I need help writing a derived class from wxEvent.
I need to split it into .h & .cpp.
The sample from documentation can't be compiled saying 'cannot instantiate abstract class' (see Event handling overview).
In my case, I use the dll build of wx 2.8.7 and MSVC 2008 as compiler,a precompiled headers project template of code::blocks.
Thanks in advance,
Mike
I need help writing a derived class from wxEvent.
I need to split it into .h & .cpp.
The sample from documentation can't be compiled saying 'cannot instantiate abstract class' (see Event handling overview).
In my case, I use the dll build of wx 2.8.7 and MSVC 2008 as compiler,a precompiled headers project template of code::blocks.
Thanks in advance,
Mike
-
- Knows some wx things
- Posts: 35
- Joined: Wed Sep 08, 2004 6:22 am
Hi Mike,
Are you missing a #include "wx/event.h" ?
Otherwise try the example at http://www.wxwidgets.org/wiki/index.php ... ethod_4.29
Regards,
David
Are you missing a #include "wx/event.h" ?
Otherwise try the example at http://www.wxwidgets.org/wiki/index.php ... ethod_4.29
Regards,
David
-
- Knows some wx things
- Posts: 35
- Joined: Wed Sep 08, 2004 6:22 am
-
- Knows some wx things
- Posts: 35
- Joined: Wed Sep 08, 2004 6:22 am
-
- Knows some wx things
- Posts: 35
- Joined: Wed Sep 08, 2004 6:22 am
So far, I've found that it is not related to precompiled headers.
I have created a regular application project with no precompiled headers.
In any case I have this linkage warning which results in not triggering the event.
Anybody has a sample of application with one basic event that works and it is written in header and implementation files?
I have created a regular application project with no precompiled headers.
In any case I have this linkage warning which results in not triggering the event.
Anybody has a sample of application with one basic event that works and it is written in header and implementation files?
-
- Knows some wx things
- Posts: 35
- Joined: Wed Sep 08, 2004 6:22 am
I have just pointed to the defines to see what's there.
For: DECLARE_EVENT_TYPE it goes to:
#define DECLARE_EVENT_TYPE(name, value) name = wxEVT_FIRST + value,
For DEFINE_EVENT_TYPE it goes to:
#define DEFINE_EVENT_TYPE(name)
I think this should be the reason, but I don't know why DEFINE_EVENT_TYPE it is not defined.
Any hint?
For: DECLARE_EVENT_TYPE it goes to:
#define DECLARE_EVENT_TYPE(name, value) name = wxEVT_FIRST + value,
For DEFINE_EVENT_TYPE it goes to:
#define DEFINE_EVENT_TYPE(name)
I think this should be the reason, but I don't know why DEFINE_EVENT_TYPE it is not defined.
Any hint?
-
- Super wx Problem Solver
- Posts: 264
- Joined: Mon Aug 07, 2006 3:25 pm
- Location: Baia Mare, Romania
- Contact:
Hi,
Here is how I do it.
Header file:
cpp file:
Note: if you want to be able to set members of the class in the constructor, you must be able to set an implicit value, or you will get errors.
Also remeber to set members in the Clone() method.
Here is how I do it.
Header file:
Code: Select all
#ifndef __CUSTOM_EVENT_H__
#define __CUSTOM_EVENT_H__
#define WXDLLIMPEXP_CUSTOM_EVENT
class CustomEvent : public wxNotifyEvent
{
private:
protected:
public:
CustomEvent(wxEventType commandType = wxEVT_NULL,
int winid = 0
);
CustomEvent(CustomEvent & inEvent);
virtual ~CustomEvent();
virtual wxEvent* Clone() const;
DECLARE_DYNAMIC_CLASS(CustomEvent)
};
BEGIN_DECLARE_EVENT_TYPES()
DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_CUSTOM_EVENT, wxEVT_COMMAND_CUSTOM_EVENT, 52000)
END_DECLARE_EVENT_TYPES()
typedef void (wxEvtHandler::*CustomEventFunction) (CustomEvent&);
#define CustomEventHandler(func) \
(wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(CustomEventFunction, &func)
#define EVT_COMMAND_CUSTOM_EVENT_UPDATE(fn) \
wx__DECLARE_EVT1(wxEVT_COMMAND_CUSTOM_EVENT, 0, CustomEventHandler(fn))
#endif
Code: Select all
#include "CustomEvent.h"
//---------------------------------------------------------------------------------------------------------
//
IMPLEMENT_DYNAMIC_CLASS(CustomEvent, wxNotifyEvent)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_CUSTOM)
//---------------------------------------------------------------------------------------------------------
//
CustomEvent::CustomEvent(wxEventType commandType,
int winid
)
:
wxNotifyEvent(commandType, winid)
{
}
//---------------------------------------------------------------------------------------------------------
//
CustomEvent::CustomEvent(CustomEvent & inEvent)
:
wxNotifyEvent(inEvent.GetEventType(), inEvent.GetId())
{
}
//---------------------------------------------------------------------------------------------------------
//
wxEvent * CustomEvent::Clone() const
{
return new CustomEvent( GetEventType(),
GetId()
);
}
//---------------------------------------------------------------------------------------------------------
//
CustomEvent::~CustomEvent()
{
}
Also remeber to set members in the Clone() method.
Software is like sex,
It's better when it's free.
~Linus Torvalds
It's better when it's free.
~Linus Torvalds
-
- Knows some wx things
- Posts: 35
- Joined: Wed Sep 08, 2004 6:22 am
as far as I know, these macros are not for wxEvent-derived stuff, but for e.g. declaring a custom wxCommandEvent (that's what I do... I use these macros, but do not derive from wxEvent) if you wish to derive, framepointer's example is probably what you're looking formsdobrescu wrote:I have just pointed to the defines to see what's there.
For: DECLARE_EVENT_TYPE it goes to:
#define DECLARE_EVENT_TYPE(name, value) name = wxEVT_FIRST + value,
For DEFINE_EVENT_TYPE it goes to:
#define DEFINE_EVENT_TYPE(name)
I think this should be the reason, but I don't know why DEFINE_EVENT_TYPE it is not defined.
Any hint?
* Note that I say "probably", i'm not a guru when it comes to event handling
-
- Super wx Problem Solver
- Posts: 264
- Joined: Mon Aug 07, 2006 3:25 pm
- Location: Baia Mare, Romania
- Contact:
What do you mean by offiacly recommanded?msdobrescu wrote:Thanks, it links with no error/warning.
But I still don't know why.
I wish to understand why it works this way when it doesn't in the 'officially recommended' way.
You have to know that the examples that are on wxWiki might be outdated or incomplete sometimes.
The example I gave you is the simplest way of dealing with custom errors. Of course, these events wont propagate, so usually you must send them to the object that is responsable for handling the event.
Regards
Software is like sex,
It's better when it's free.
~Linus Torvalds
It's better when it's free.
~Linus Torvalds
-
- Knows some wx things
- Posts: 35
- Joined: Wed Sep 08, 2004 6:22 am
I mean: why DECLARE_EXPORTED_EVENT_TYPE and not DECLARE_EVENT_TYPE?
Btw, WXDLLIMPEXP_CUSTOM_EVENT is defined to nothing, so
DECLARE_EXPORTED_EVENT_TYPE(, wxEVT_COMMAND_CUSTOM_EVENT, 52000)
is the same thing.
I need to know if there's some build option I set wrong that makes it need DECLARE_EXPORTED_EVENT_TYPE in a plain exe.
Btw, WXDLLIMPEXP_CUSTOM_EVENT is defined to nothing, so
DECLARE_EXPORTED_EVENT_TYPE(, wxEVT_COMMAND_CUSTOM_EVENT, 52000)
is the same thing.
I need to know if there's some build option I set wrong that makes it need DECLARE_EXPORTED_EVENT_TYPE in a plain exe.