Archived

This topic is now archived and is closed to further replies.

simeygrimey

callback functions

Recommended Posts

the most common call back funtion is the windows messenger handler function. you pass the address of the function that you wrote to windows and windows calls that function back as it needs to. a simple windows messenger handler looks something like this.


LRESULT CALLBACK WndProc(HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_SIZE:
GetWindowRect(hWnd, &windowRect);
return 0;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
} // WndProc



windows calls this function whenever there is a message in the queue and handles the message depending on your switch case statements. any messages that you did not handle you can pass to the default message handler function.

Share this post


Link to post
Share on other sites
Note that callbacks are a C thing; avoid using them in C++, except to maintain compatibility with C interfaces (such as the windows API). A better solution in C++ is virtual subclasses used as interfaces; check any decent OOP textbook for examples of this.


How appropriate. You fight like a cow.

Share this post


Link to post
Share on other sites
http://www.function-pointer.org

it is a nice site and has helped me with my callback problem
take a look.

http://www.function-pointer.org/CCPP/callback/callback.html#chapter3

Lazzar

if god gave us the source code, we could change the world!

Share this post


Link to post
Share on other sites