Reputation: 3462
I'm trying to create something like MsgProc
in Win32. When they declare the MsgProc
function they have the CALLBACK
type before it. So, all I'm trying to is create my own messsage function that calls my function to process the messages. It is basically the same thing when messages getting sent and processed. My question is how can i create the Same process?. An example would be great.
Upvotes: 3
Views: 2082
Reputation: 39496
Other than the classics function pointers and function objects you may be interested by the new C++0x lambdas.
Here's an example of passing a lambda to a timer function.
#include <windows.h>
#include <iostream>
#include <functional>
void onInterval(DWORD interval, std::function<void ()> callback) {
for (;;) {
Sleep(interval);
callback();
}
}
int main() {
onInterval(1000, []() {std::cout<<"Tick! ";});
}
Upvotes: 1
Reputation: 2665
If you can use Boost, I would definitely give Boost.Signals a shot, they provide the functionality you are looking for in a clean and safe way (Boost.Signals2 even in thread-safe way.)
Upvotes: 0
Reputation: 547
If you're in C++, just use a function pointer in your class:
http://www.newty.de/fpt/fpt.html
Upvotes: 0