Respond to messages and custom messages in CB

Source: Internet
Author: User
Tags definition class definition

In Borland C++builder, you can also respond to messages as you would in Delphi, but it just looks a little bit more complicated. For messages that are already defined by the system, you can respond directly, whereas non-system messages can be customized as follows:

//The following code is written in the header file:
#define WM_MY_OPEN_CMDLINE_FILE (wm_user+1)//interprocess communication custom Messages
#define WM_MY_SEARCH_NODE ( Wm_user+2//Find custom messages for commands
Class Tsomeform:public Tform
{//Form class definition
//... Other code in the class
Protected:
//message response process
void __fastcall opencmdlinefile (tmessage messages);
void __fastcall Searchdocumentnode (tmessage message);
void __fastcall getwindowminmaxinfo (Twmgetminmaxinfo message);
//Implement the correct response for the message through the following macro definition
Begin_message_map
Message_handler (Wm_my_open_cmdline_file, Tmessage, Opencmdlinefile)
Message_handler (Wm_my_search_node, Tmessage, Searchdocumentnode)
Message_handler (WM_ Getminmaxinfo, Twmgetminmaxinfo, Getwindowminmaxinfo)
End_message_map (tform)
};//end class
------------- -------------------------------------------------------------------
//Below is the implementation code, written in the module file:
void __fastcall Tsomeform::opencmdlinefile (Tmessage message)
{//pass parameters directly through the messaging structure
LPSTR lpcmdline= (LPSTR) message.lparam;// Gets the parameter from the message
This->handlecmdlinefile (lpcmdline);/Handle LifeThe argument to the row
return;
}
--------------------------------------------------------------------------------
void __fastcall Tsomeform::searchdocumentnode (Tmessage message) The parameters in the
{//Response lookup messages
//message are not required here.
This->searchnode ();
return;
}
--------------------------------------------------------------------------------
void __fastcall Tsomeform::getwindowminmaxinfo (Twmgetminmaxinfo message)
{//Set the minimum size of the main window
Minmaxinfo *minmaxinfo= Message.minmaxinfo;
minmaxinfo->ptmintracksize.x=400;
minmaxinfo->ptmintracksize.y=300;
return;
}

Where: the definition of tmessage and Twmgetminmaxinfo types can be seen: C:\Program files\borland\cbuilder\inlucde\vcl\messages.hpp, and other message response methods are the same.

In addition, you can define a corresponding message structure for a custom message (such as: Tsearchnode_message), as to how to define the message structure, you can refer to the source code of Borland: C:\Program files\borland\cbuilder\ Inlucde\vcl\messages.hpp

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.