📄 refermain.cpp
字号:
LoadToolButtonImage( ImageListDisableButtons, "res\\last_d.bmp" );
LoadToolButtonImage( ImageListButtons, "res\\prev_n.bmp" );
LoadToolButtonImage( ImageListHotButtons, "res\\prev_h.bmp" );
LoadToolButtonImage( ImageListDisableButtons, "res\\prev_d.bmp" );
LoadToolButtonImage( ImageListButtons, "res\\next_n.bmp" );
LoadToolButtonImage( ImageListHotButtons, "res\\next_h.bmp" );
LoadToolButtonImage( ImageListDisableButtons, "res\\next_d.bmp" );
// Yor can do this like that:
// pBitmapButton = new Graphics::TBitmap;
// pBitmapButton->LoadFromFile( "res\\last_n.bmp" );
// ImageListButtons->Add( pBitmapButton, NULL );
// if( pBitmapButton != NULL )
// {
// delete pBitmapButton;
// pBitmapButton = NULL;
// }
// pBitmapButton = new Graphics::TBitmap;
// pBitmapButton->LoadFromFile( "res\\last_h.bmp" );
//// NEVER WORK! I DON'T FIND ANY HELP ON HInstance!
//// int nThisInstance = FindHInstance( Application );
//// int nResInstance = FindResourceHInstance( nThisInstance );
//// pBitmapButton->LoadFromResourceName( nResInstance, "BITMAP_LAST_H" );
// ImageListHotButtons->Add( pBitmapButton, NULL );
//// NEVER WORK TOO! I DON'T KNOW WHY!
//// ImageListHotButtons->ResourceLoad( rtBitmap, "BITMAP_LAST_H", NULL );
// if( pBitmapButton != NULL )
// {
// delete pBitmapButton;
// pBitmapButton = NULL;
// }
// pBitmapButton = new Graphics::TBitmap;
// pBitmapButton->LoadFromFile( "res\\last_h.bmp" );
// ImageListDisableButtons->Add( pBitmapButton, NULL );
// if( pBitmapButton != NULL )
// {
// delete pBitmapButton;
// pBitmapButton = NULL;
// }
}
//---------------------------------------------------------------------------
bool __fastcall TMainFormRefer::LoadToolButtonImage( TImageList *pDest, AnsiString asSrc )
{
// C++Builder includes a large set of built-in exception classes for
// automatically handling divide-by-zero errors, file I/O errors,
// invalid typecasts, and many other exception conditions.
// All VCL exception classes descend from one root object called Exception.
// Exception encapsulates the fundamental properties and methods for
// all exceptions and provides a consistent interface for applications
// to handle exceptions.
// You can pass exceptions to a catch block that takes a parameter of
// type Exception. Use the following syntax to catch VCL exceptions:
//
// catch (const exception_class &exception_variable)
//
// You specify the exception class that you want to catch and
// provide a variable by which to refer to the exception.
// Following is an example of how to throw a VCL exception:
//
// void __fastcall TForm1::ThrowException(TObject *Sender)
// {
// try
// {
// throw Exception("VCL components?");
// }
// catch(const Exception &E)
// {
// ShowMessage(AnsiString(E.ClassName())+ E.Message);
// }
// }
//
// The throw statement in the previous example creates an instance of
// the Exception class and calls its constructor. All exceptions
// descended from Exception have a message that can be displayed,
// passed through constructors, and retrieved through the Message property.
//
// Selected VCL exception classes are described below.
//
// EAbort Stops a sequence of events without displaying an error message dialog box.
// EAccessViolation Checks for invalid memory access errors.
// EBitsError Prevents invalid attempts to access a Boolean array.
// EComponentError Signals an invalid attempt to register or rename a component.
// EConvertError Indicates string or object conversion errors.
// EDatabaseError Specifies a database access error.
// EDBEditError Catches data incompatible with a specified mask.
// EDivByZero Catches integer divide-by-zero errors.
// EExternalException Signifies an unrecognized exception code.
// EInOutError Represents a file I/O error.
// EIntOverflow Specifies integer calculations whose results are too large for the allocated register.
// EInvalidCast Checks for illegal typecasting.
// EInvalidGraphic Indicates an attempt to work with an unrecognized graphic file format.
// EInvalidOperation Occurs when invalid operations are attempted on a component.
// EInvalidPointer Results from invalid pointer operations.
// EMenuError Involves a problem with menu item.
// EOleCtrlError Detects problems with linking to ActiveX controls.
// EOleError Specifies OLE automation errors.
// EPrinterError Signals a printing error.
// EPropertyError Occurs on unsuccessful attempts to set the value of a property.
// ERangeError Indicates an integer value that is too large for the declared type to which it is assigned.
// ERegistryException Specifies registry errors.
// EStackOverflow Occurs when the stack grows into the final guard page.
// EZeroDivide Catches floating-point divide-by-zero errors.
//
//
// EInOutError is thrown when an operating-system file input/output error
// occurs, provided I/O checking is enabled.
// To enable or disable I/O checking, choose Project|Options and
// select the Pascal tab.
// The resulting error code is returned in the local ErrorCode variable,
// which can take the following values.
// 2 File not found.
// 3 Invalid file name.
// 4 Too many open files.
// 5 Access denied.
// 100 EOF.
// 101 Disk full.
// 106 Invalid input.
// If an I/O error occurs when I/O checking is disabled,
// the application must call the IOResult function to clear the error.
//
// Message contains the text string to display in the exception dialog box
// when the exception is raised.
//
// __property System::AnsiString Message = {read=FMessage, write=FMessage};
//
// Description:
// Message stores the error-message string to display when the exception
// is raised. All Exception constructors expect a string parameter to
// store in Message. Message text can be hard-coded as a parameter to
// an Exception constructor, created as dynamic parameter, or loaded from
// a resource file as a static or dynamically formatted parameter.
//
Graphics::TBitmap *pBitmapButton;
// Try to allocate memory for bitmap graphics.
// If fails, that is, insufficient memory can result in that
// no memory is allocated. An excepts will occur.
// User can choose to continue to run or terminate the application.
try
{
pBitmapButton = new Graphics::TBitmap;
// Try to load bitmap from files.
// If the file does NOT exist or graphic format is INVALID,
// two excepts, EInOutError and EInvalidGraphic will occur.
// User can choose to continue to run or terminate the application.
try
{
pBitmapButton->LoadFromFile( asSrc );
pDest->Add( pBitmapButton, NULL );
}
catch( const EFOpenError& e ) // Not EInOutError
// __except( const EInOutError &e )
{
//--------------------------------------------------------------------
// NOTE:
// Use member function, <destination>->Assign(<source>), to copy the type of
// property of a component to another, DO NOT use "<destination> = <source>,
// which will be never work properly, since the destination type is TBitmap,
// while the source type is TPicture.
// If you use type-casting, (TBitmap *)<source>, an error will occurs.
pBitmapButton->Assign( ImageNaked->Picture );
pDest->Add( pBitmapButton, NULL );
if( pBitmapButton != NULL ) // Release the memory
{
delete pBitmapButton;
pBitmapButton = NULL;
}
AnsiString asEInformation = e.Message + const_cast< char * >( MI_CONTINUE );
int nButton = Application->MessageBox(
asEInformation.c_str(),
AnsiString( e.ClassName() ).c_str(),
MB_YESNO + MB_ICONSTOP + MB_DEFBUTTON2 );
if( nButton == IDYES )
return false;
if( nButton == IDNO )
Application->Terminate();
}
catch( const EInvalidGraphic& e )
{
pBitmapButton->Assign( ImageNaked->Picture );
pDest->Add( pBitmapButton, NULL );
if( pBitmapButton != NULL ) // Release the memory
{
delete pBitmapButton;
pBitmapButton = NULL;
}
AnsiString asEInformation = e.Message + const_cast< char * >( MI_CONTINUE );
int nButton = Application->MessageBox(
asEInformation.c_str(),
AnsiString(e.ClassName()).c_str(),
MB_YESNO + MB_ICONSTOP + MB_DEFBUTTON2 );
if( nButton == IDYES )
return false;
if( nButton == IDNO )
Application->Terminate();
}
}
catch ( ... )
{
//
// const_cast< T > (arg)
//
// Description
//
// Use the const_cast operator to add or remove the const or volatile
// modifier from a type.
// In the statement, const_cast< T > (arg), T and arg must be of
// the same type except for const and volatile modifiers.
// The cast is resolved at compile time. The result is of type T.
// Any number of const or volatile modifiers can be added or removed
// with a single const_cast expression.
//
// A pointer to const can be converted to a pointer to non-const that
// is in all other respects an identical type. If successful,
// the resulting pointer refers to the original object.
//
// A const object or a reference to const cast results in a non-const
// object or reference that is otherwise an identical type.
//
// The const_cast operator performs similar typecasts on the volatile
// modifier. A pointer to volatile object can be cast to a pointer to
// non-volatile object without otherwise changing the type of the object.
// The result is a pointer to the original object. A volatile-type object
// or a reference to volatile-type can be converted into an identical
// non-volatile type.
// AnsiString asInformation = AnsiString( const_cast< char * >( MI_NOMEMORY ) );
Application->MessageBox(
// asInformation.c_str(),
AnsiString( const_cast< char * >( MI_NOMEMORY ) ).c_str(),
const_cast< char * >( MT_FATALERROR ),
MB_OK + MB_ICONERROR );
Application->Terminate();
}
return true;
//-----------------------------------------------------------------------
// Application->MessageBox and Windows MessageBox Help
//-----------------------------------------------------------------------
// Specifies a set of bit flags that determine the contents and behavior
// of the dialog box. This parameter can be a combination of flags from
// the following groups of flags.
// Specify one of the following flags to indicate the buttons contained
// in the message box:
// Flag Meaning
// MB_ABORTRETRYIGNORE The message box contains three push buttons: Abort, Retry, and Ignore.
// MB_OK The message box contains one push button: OK. This is the default.
// MB_OKCANCEL The message box contains two push buttons: OK and Cancel.
// MB_RETRYCANCEL The message box contains two push buttons: Retry and Cancel.
// MB_YESNO The message box contains two push buttons: Yes and No.
// MB_YESNOCANCEL The message box contains three push buttons: Yes, No, and Cancel.
// Specify one of the following flags to display an icon in the message box:
// Flag
// MB_ICONEXCLAMATION, MB_ICONWARNING
// An exclamation-point icon appears in the message box.
// MB_ICONINFORMATION, MB_ICONASTERISK
// An icon consisting of a lowercase letter i in a circle appears in
// the message box.
// MB_ICONQUESTION
// A question-mark icon appears in the message box.
// MB_ICONSTOP, MB_ICONERROR, MB_ICONHAND
// A stop-sign icon appears in the message box.
// Specify one of the following flags to indicate the default button:
// Flag Meaning
// MB_DEFBUTTON1 The first button is the default button.
// MB_DEFBUTTON1 is the default unless MB_DEFBUTTON2,
// MB_DEFBUTTON3, or MB_DEFBUTTON4 is specified.
// MB_DEFBUTTON2 The second button is the default button.
// MB_DEFBUTTON3 The third button is the default button.
// MB_DEFBUTTON4 The fourth button is the default button.
// Specify one of the following flags to indicate the modality of
// the dialog box:
// Flag Meaning
// MB_APPLMODAL The user must respond to the message box before continuing work in the window identified by the hWnd parameter. However, the user can move to the windows of other applications and work in those windows. Depending on the hierarchy of windows in the application, the user may be able to move to other windows within the application. All child windows of the parent of the message box are automatically disabled, but popup windows are not.MB_APPLMODAL is the default if neither MB_SYSTEMMODAL nor MB_TASKMODAL is specified.
// MB_SYSTEMMODAL Same as MB_APPLMODAL except that the message box has the WS_EX_TOPMOST style. Use system-modal message boxes to notify the user of serious, potentially damaging errors that require immediate attention (for example, running out of memory). This flag has no effect on the user's ability to interact with windows other than those associated with hWnd.
// MB_TASKMODAL Same as MB_APPLMODAL except that all the top-level windows belonging to the current task are disabled if the hWnd parameter is NULL. Use this flag when the calling application or library does not have a window handle available but still needs to prevent input to other windows in the current application without suspending other applications.
// In addition, you can specify the following flags:
// MB_DEFAULT_DESKTOP_ONLY
// The desktop currently receiving input must be a default desktop;
// otherwise, the function fails. A default desktop is one an application
// runs on after the user has logged on.
// MB_HELP
// Adds a Help button to the message box. Choosing the Help button or
// pressing F1 generates a Help event.
// MB_RIGHT
// The text is right-justified.
// MB_RTLREADING
// Displays message and caption text using right-to-left reading order
// on Hebrew and Arabic systems.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -