About Boxes |
|
Description |
An About box is a dialog box that provides some quick information about the current application. It may show the copyright notice, the application version, and other pieces of information. There is no strict as to what an about box must contain. The person who creates an About box decides what to show on it, and many (non-professional) applications may not have an About box. In most applications, to access an About box, on the main menu, you would click Help and click the About option. |
As mentioned already, an About box is primarily a dialog box. To help you create one, Embarcadero C++Builder provides a convenient template. To use it, display the New Items dialog box. In the left list, click C++Builder Files. In the right list, click About Box:
|
Click OK. This would create a dialog box that you can then customize:
If you have a prototype message box that you are planning to use over and over again in your application, you can create it at once, implement it, then use it in different locations in your application. Such a common message box is created using the CreateMessageDialog() function. The CreateMessageDialog() function does not allow you to create a new message box. It provides a technique of creating a central dialog box that combines the arguments and flags of the other message boxes. The syntax of the CreateMessageDialog() function is: Forms::TForm* __fastcall CreateMessageDialog(const AnsiString Msg, TMsgDlgType IconType, TMsgDlgButtons ButtonType); This function takes three arguments similar to those of the MessageDlg() function. You construct it by specifying the string message, the icon type, and the button type. To create this dialog box, assign its construction to a dynamic form. To do this, you could create a local form in a function or event, but since a local dynamic control is accessible only in the event or function in which it is created, this would deceive the purpose of using the CreateMessageDialog() function. Therefore, declare an instance of the TForm class in the private or public sections of the unit or form that would use the message box: //---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TButton *Button1;
TButton *Button2;
TPanel *Panel1;
void __fastcall Button1Click(TObject *Sender);
void __fastcall Button2Click(TObject *Sender);
void __fastcall FormCreate(TObject *Sender);
void __fastcall Panel1Click(TObject *Sender);
private: // User declarations
TForm* Mine;
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
Next, use the new operator to specify the owner of the form: //---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
Mine = new TForm(this);
}
//---------------------------------------------------------------------------
To create the custom message box, assign the return value of the CreateMessageDialog() function by creating it. The message box can be as simple as a single string, an icon, and a button: //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { Mine = new TForm(this); Mine = CreateMessageDialog(L"Custom Dialog Box", mtWarning, TMsgDlgButtons() << mbYes); } //--------------------------------------------------------------------------- The message could also comport any of the available icons combined with any common buttons: //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { Mine = new TForm(this); Mine = CreateMessageDialog(L"Is this the best song or what?", mtInformation, TMsgDlgButtons() << mbYes << mbAbort << mbCancel << mbNo); } //--------------------------------------------------------------------------- With the message box created, you can call it from any section or control that needs it in your application: #include <vcl.h> #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm"TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { Mine = new TForm(this); Mine = CreateMessageDialog(L"Is this the best song or what?", mtInformation, TMsgDlgButtons() << mbYes << mbAbort << mbCancel << mbNo); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { Mine->ShowModal(); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button2Click(TObject *Sender) { Mine->ShowModal(); } //--------------------------------------------------------------------------- void __fastcall TForm1::Panel1Click(TObject *Sender) { Mine->ShowModal(); } //---------------------------------------------------------------------------
|
|
||
Home | Copyright © 2010-2016, FunctionX | |
|