Search code examples
c++events

How to handle an event in Windows C++


How would I setup a custom event and event handler in Windows C++?

An analog for what I want to accomplish would be something similar to what this is doing in nodejs:

//in main execution context:

var app = require('myapp');

app.on('ready', function(){
    //An event handler for the ready event
})

var i = 10;
foo(i);
//... do other stuff 

================================================
//in a different execution context:

app.doStuff();
app.emit("ready");

What is the Windows C++ mechanism for setting and event handler and continuing execution?


Solution

  • Event handler is an abstract concept that exists somehow is all general purpose programming languages.

    C++ is no exception. For C++ under windows you can define a custom event, a source that will raise this event, and a receiver or an event listener/handler.

    Check the sample code here

    https://learn.microsoft.com/en-us/cpp/cpp/event-handling-in-native-cpp