event handler

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Qasim
Knows some wx things
Knows some wx things
Posts: 29
Joined: Wed May 23, 2007 3:41 pm
Location: London

event handler

Post by Qasim »

Hi, I am trying to attach my fun with a menu. I am doing some thing like this in xp, Visual Studio 2005

//this is global function(not member of any class)

Code: Select all

void myFunc()
{
int x = 0;
}

then in

Code: Select all

void MyFrame::createcontrols()
{
wxMenu* menu = new wxMenu;
menu->Append(1100, "MyMenu");
menu->Connect(1100, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(myFunc), NULL, NULL);
}
having error:

Code: Select all

error C2440: 'static_cast' : cannot convert from 'void (__cdecl *)(void)' to 'wxCommandEventFunction'
Any help will be appreciated.
Regards
Who doubts nothing, Knows nothing
Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg »

You can't connect functions to an event handler. The event sink has to be of the same base class (wxEvtHandler).

Create a normal event handler inside your class, and in there call the gliobal function.

= Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb
Post Reply