프로그래밍/C/C++2007.05.17 17:20

 #include <stdio.h>
#include <tchar.h>

#include <iostream>
using namespace std;

#include <map>

enum EVENT_TYPE {
 EVENT_MOUSE_DOWN,
 EVENT_MOUSE_UP
};

//void (*pEventHandler[3])(void);
typedef void (*fnpoint)(void);

fnpoint g_eventListener;

void sayHello()
{
 printf("hello!\n");
}

void OnMouseDown()
{
 printf("OnMouseDown!\n");
}

void OnMouseUp()
{
 printf("OnMouseUp!\n");
}

map<EVENT_TYPE, fnpoint> eventMap;


void AddEventListener(EVENT_TYPE eventType, fnpoint e)
{
 g_eventListener = e;
}

void FireEvent(EVENT_TYPE eventType)
{
 switch (eventType) {
  case EVENT_MOUSE_DOWN:
   g_eventListener();
   break;
 }

}

void MouseDown()
{
 //g_eventListener();

 FireEvent(EVENT_MOUSE_DOWN);
}

 


int _tmain(int argc, _TCHAR* argv[])
{
/*
 void (*pFn)(void);
 pFn = sayHello;
 pFn();
*/

 //AddEventListener(EVENT_MOUSE_DOWN, OnMouseDown);
 //MouseDown();

 eventMap[EVENT_MOUSE_DOWN] = OnMouseDown;

 eventMap[EVENT_MOUSE_DOWN]();

 //pEventHandler[0] = OnMouseDown;
 //pEventHandler[1] = OnMouseUp;


 //pEventHandler[0]();
 //pEventHandler[1]();

 return 0;
}


Posted by 시난

댓글을 달아 주세요