I am playing around with Event handling and I am trying to make my own menu in a Win32 console. I have an event pump
but I am getting a little confused when it comes to event model vs callback model and how I would implement them.
I have a basic skeleton program that I am using to write test programs. Perhaps my design is flawed.
Code:
//EventPump.cpp
#include"EventPump.h"
void EventPump(bool(*ProgramMain)(HANDLE &,INPUT_RECORD &,DWORD &) )
{
HANDLE hStdout=GetStdHandle(STD_OUTPUT_HANDLE);
HANDLE hStdin=GetStdHandle(STD_INPUT_HANDLE);
INPUT_RECORD input_record;
SetConsoleMode(hStdin,ENABLE_MOUSE_INPUT);
DWORD EventsInBuffer;
DWORD EventsRead;
do
{
GetNumberOfConsoleInputEvents(hStdin,&EventsInBuffer);
if(EventsInBuffer>=1)
{
ReadConsoleInput(hStdin,&input_record,1,&EventsRead);
}
}while(ProgramMain(hStdout,input_record,EventsInBuffer) );
}
Code:
//EventHandler.cpp
#include "EventHandler.h"
#include "KeyMappings.h"
extern void (*FunctionCallback[161])(void);
bool EventHandler(HANDLE hStdout,INPUT_RECORD input_record)
{
switch(input_record.EventType)
{
case EVENT:
switch(input_record.Event)
{
case
break;
}
Code:
//ProgramMain.cpp
#include ProgramMain.h
bool ProgramMain(HANDLE &hStdout,INPUT_RECORD &input_record,DWORD &EventsInBuffer)
{
//Functions to be executed each cycle go here
return EventHandler(hStdout,input_record);
}
Code:
//main.cpp
#include "EventPump.h"
#include "EventHandler.h"
#include "KeyMappings.h"
#include <windows.h>
#include "Menus.h"
void (*FunctionCallback[161])(void);//?? not sure if this is write?
int main(void)
{
for(int i=0;i<161;i++)
FunctionCallback[i]=FunctionNULL;
EventPump(ProgramMain);
return 0;
}
I believe this is the event model. What I am trying to figure out is how I would implement callback functions in a callback model? Would I have to change my design or would i just build on this?