   Event handling in DirectX GUI
  Hello,I am working on creating a GUI in VC++ .NET, using DirectX 9.  I am building it into a library as kind of an API, so I can use it for multiple programs.  However, I''m rather stumped on how to tackle one major part of the system: how do I implement event-based programming into the API?  In other words, how do I allow the programmer to dictate what happens when the user clicks a button?  I''ve thought of implementing some sort of event queue that the GUI would dump everything into, and the programmer could pull the events out, but this would lead to a huge switch statement in every program that used the GUI, and I can''t help thinking that there is a better way.I know very little about event-based programming as it relates to C++.  When I think of event-based programming, I tend to think of Visual Basic''s event-based model.  Ideally, I''d love to implement something like Visual Basic''s event scheme and simply allow the programmer to write the code he wants executed when a button is pressed, the mouse passes over a square on the screen, or whatever.  I don''t know how feasible this is, though.I''d love to hear some possible approaches to this, especially from those who have tackled a problem like this already.  By the way, I''ve already read the article here on GameDev about building a GUI in DirectX, but that article provides very little direction on event handling, and as near as I can figure out, implements a system where every object of a certain class behaves the same as all the rest.Thanks in advance. 
  Well, since i guess you''re having each component as a class, you could just hook up the class with a function pointer that''s getting called whenever an event is triggered..or that''s the way I probably would have done it anyway.   -LuctusStatisticly seen, most things happens to other people.[Mail];  Hmmm... Not a bad idea.  I''ve never used function pointers before, though.  I''m familiar with the general concepts, but I''ve just never tried it.  Are function pointers basically like normal pointers?  Anything tricky about using them? ;  Well in it''s most basic form you do something like this (I believe, long time since I last did this. Should work though ):typedef int (*func_ptr)(int, int);int myfunction( int arg1, int arg2 ){  return arg1 + arg2;}void main( void ){  func_ptr my_func_ptr;  my_func_ptr = myfunction;  // Call function through function pointer  int res = my_func_ptr( 3, 5 );}  The hard part is to know how to do the typedef. Here I made a function pointer that took two ints as arguments and returned an int.If you want to refer to a function inside of another class (a public function of course), you just do the typedef like:typedef int (classname::*func_ptr)( int, int );Hope that helps.   -LuctusStatisticly seen, most things happens to other people.[Mail];  I''m having a little trouble decyphering the typedef.  Would you mind disecting that for me?  So you have to do a different typedef for every unique combination of return types and arguments, is that right?One other question...  Can you store function pointers in STL containers?Thanks for the info.  I think this is exactly what I will need. ;www.function-pointer.orgquote:Can you store function pointers in STL containers?Yes.;  Well, the best I can say is that it should look like this:typedef returntype (*typename)(argumentlist);I''m afraid I can''t explain it much better than that. You might want to try the google. But on the other hand, when you''ve got a typedef set, it''s cake to use them.hm, I might clarify a thing about using the pointer to member-functions since it''s a bit trickier than regular function pointers..the typedef looks like typedef int (classname::*func_ptr)( int, int );  But you have to assign the pointer like thisfunc_ptr my_ptr = &classname::functionname;  And call it withclassname instancename;instancename.*my_ptr( 3, 5 );  And to confuse you some more (I''m a lousy teacher ), you don''t have to do typedefs either. You can just doint (*func_ptr_name)( int, int );func_ptr_name = somefunc;func_ptr_name( 3, 5 );  Hope you were able to make something out of that ^_^ -LuctusStatisticly seen, most things happens to other people.[Mail];  NafdahliX: Thanks for the link, looks like good stuff.Luctus: It''s OK, I''m a lousy student, so we''re even.  Seriously, thanks for the info.  This give me a good start, and the method you outlined should be perfect for my needs in my GUI. ;  Another thing you could do is have the outputs of your GUI, for example filtered messages and object IDs, feed into a state machine code to process the events. ;  You could also pass functors, so that virtually any function could be called to handle the event. 