BHandler
BHandleris a base class for objects that can receive and handle messages.- To handle messages, you subclass
BHandlerand override itsMessageReceived()function. - The
MessageReceived()function is called whenever a message is sent to the handler. - In the
MessageReceived()function, you can inspect the message and take appropriate action based on its contents.
BHandler class is defined at:
- Header file:
headers/os/app/Handler.h - src file:
src/kits/app/Handler.cpp
Example:
class MyHandler : public BHandler {
public:
MyHandler() {}
void MessageReceived(BMessage* message) {
switch (message->what) {
case 'HELW':
printf("Hello World!\n");
break;
default:
BHandler::MessageReceived(message);
break;
}
}
};
Sending Messages to the Handler:
- To send a message to a
BHandler, you create aBMessageobject and call theMessageReceived()function on the handler.
BMessage message('HELW');
myHandler->MessageReceived(&message);Basic functions of the BHandler class
1 Constructor
BHandler::BHandler(const char* name = NULL);
- Creates a new
BHandlerobject with the given name.
2 MessageReceived()
virtual void BHandler::MessageReceived(BMessage* message);
- This function is called whenever a message is received by the
BHandler. - Override this function in your subclasses to handle specific types of messages.



Join the discussion
Sign in with your account to post comments, reply to others, and participate in the conversation.
Login to Comment