Practical programming-develop an animation DLL using C ++ Builder

Source: Internet
Author: User
Practical programming-C ++ Builder development of animation DLL-general Linux technology-Linux programming and kernel information, the following is a detailed description. When copying files and searching for files in Windows 98, Windows displays a small animation indicating ongoing operations, compared with a rigid static image, it adds a lot of colors. When we develop our own software, can we also display such an animation prompt? The author developed an animation DLL that can be called under PB. Due to multi-threaded programming, the DLL function called by PB can promptly return the control to PB without affecting the operation of the application system.

I. Code and compilation options

Create a blank DLL project in C ++ Builder.

Create a blank Form and modify its attributes:

BorderStyle = bsDialog
The sub-attributes of BorderIcons are both False.
FormStyle = fsStayOnTop
Position = poScreenCenter
Name = StatusForm

Add an Animate control under Win32 to Form, and modify its attribute to Align = alTop.

Add a Button control Button_Cancel under Standard on the Form, add Timer control Timer1 under System, set the scheduled Interval time to 250, and quickly respond to the user's cancellation request.

Because the PB Application System and the animation form code belong to two threads respectively, you cannot use the PB thread to directly close the window of the animation form thread. Otherwise, the system may run abnormally, therefore, the flag is set to close with PB threads, while the animation thread uses the Timer control to regularly check the logo. Once the flag is detected, the window is closed, the thread mark is cleared, and the animation thread is ended.

The encoding and encoding principles are as follows:

(1) DLL subject code:

/* DLL main body code
* Fixed the volume of public DLL changes
* G_CommonAVI controls the animation.
Animation-type cable reference
* Gi_Canceled Button_Cancel
Whether the button is selected
* Gi_AVIType: Specifies the animation type to be displayed,
Input the number of DLL input functions as the parameter
* Gi_RequestClose: please find the mark of the dynamic draw line mark.
* Gi_WindowActive animation window
* LpsWinTitle: the title of the animation window,
Input the number of DLL input functions as the parameter

TCommonAVI g_CommonAVI [] = {
AviNone, aviFindFolder,
AviFindFile, aviFindComputer,
AviCopyFiles, aviCopyFile,
AviRecycleFile, aviEmptyRecycle,
Int gi_Canceled = 0, gi_AVIType = 0;
Int gi_RequestClose = 0, gi_WindowActive = 0;
Char lpsWinTitle [256];
HWND hWndParent = NULL;

/* Specify the number of exported DLL letters */
Extern "C" _ declspec (dllexport) int pascal Dll
? EntryPoint (HINSTANCE hinst, unsigned
Long reason, void *);
Extern "C" _ declspec (dllexport) int pascal
ShowStatus Window
(Int AVIType, LPSTR WinTitle, long hWnd );
Extern "C" _ declspec (dllexport)
Int pascal GetStatus (int ai_CloseWin );
Extern "C" _ declspec (dllexport)
Int pascal CloseStatusWindow ();

/* Fixed thread TformThread :*/
Class TFormThread: public TThread {
Public: // User declarations
_ Fastcall TFormThread (bool createsuincluded );
Void _ fastcall Execute (void );
_ Fastcall TFormThread ::
TFormThread (bool createsu0000ded ):
TThread (createsuincluded ){
/* Specifies the generation code of the animation thread,
The timer controller of the animation window will close it,
Clear the window and save it to the running line after marking
Void _ fastcall TFormThread: Execute (void ){
Gi_WindowActive = 1;
StatusForm = new TStatusForm (NULL );

StatusForm-> Caption = lpsWinTitle;
StatusForm-> ShowModal ();
Gi_WindowActive = 0;
Delete StatusForm;
Gi_RequestClose = 0;
/* Define a thread instance needle */
TFormThread * FormThread;
/* Input the function code generation (Real-Time Division)
* DllEntryPoint 32-bit DLL inbound
* ShowStatusWindow: displays the animation window,
It creates a window port by creating a thread,
Avoid using the MODAL attribute of the window Port
When the control system right is not available, the system will return it to the caller.
* GetStatus gets the "cancel" status,
That is, if the user does not select "cancel", press the button.
* CloseStatusWindow: Close the animation window,
_ Declspec (dllexport) int WINAPI DllEntryPoint
(HINSTANCE hinst, unsigned long reason, void *)
Return 1;

_ Declspec (dllexport) int pascal ShowStatusWindow
(Int AVIType, LPSTR WinTitle, long hWnd ){
HWndParent = (HWND) hWnd;
Memset (lpsWinTitle, 0, sizeof (lpsWinTitle ));
Strncpy (lpsWinTitle, WinTitle, sizeof (lpsWin Title)-1 );
If (AVIType> 0 & AVIType <= 8) gi_AVIType = "AVIType ;"
FormThread = "new" TFormThread (true );
FormThread-> Priority = tpNormal;
FormThread-> Resume ();

_ Declspec (dllexport) int pascal GetStatus
(Int ai_CloseWin ){
If (gi_Canceled)
If (gi_WindowActive ){
Gi_RequestClose = 1;
While (gi_RequestClose );

Return gi_Canceled;

_ Declspec (dllexport) int pascal CloseStatusWindow (){
If (gi_WindowActive ){
Gi_RequestClose = 1;
While (gi_RequestClose );

Return gi_Canceled;

(2) Code of the form StatusForm:

TStatusForm * StatusForm;
Extern int gi_Canceled;
Extern int gi_AVIType;
Extern TCommonAVI g_CommonAVI [];
_ Fastcall TStatusForm: TStatusForm
(HWND ParentWindow)
: TForm (ParentWindow)
Gi_Canceled = 0;
// Remove or press the button and close the window directly,
It indicates that the configuration is used to retrieve and describe the logo, which can be viewed by callers.
Void _ fastcall TStatusForm: Button_CancelClick
(TObject * Sender)
Gi_Canceled = 1;
// ModalResult = mrCancel;
// Stimulate the animation, In the FORMCREATE event
Void _ fastcall TStatusForm: FormCreate
(TObject * Sender)
Animate1-> CommonAVI = g_CommonAVI [gi_AVI
Animate1-> Active = true;
Extern int gi_RequestClose;
// Fixed timer event check to close the window
Void _ fastcall TStatusForm: Timer1Timer
(TObject * Sender)
If (gi_RequestClose ){
ModalResult = mrOk;

Set compilation Options: Open the Project Options dialog box, clear the Use Dynamic RTL flag on the Linker property page, and clear Build with runtime Packages on the packages property page. In this way, a single DLL can be run without having to install some dynamic connection runtime libraries.

Ii. Use animated DLL

1. Definition:

// Declare-> Global External Functions
FUNCTION Long ShowStatusWindow
(Long AVIType, String WinTitle, long hWnd)
"Show StatusWindow"

FUNCTION Long GetCancelStatus
(Long CloseWindow) & LIBRARY
"STATWIN. DLL" alias for "GetStatus"

FUNCTION Long CloseStatusWindow ()&

2. call:

Long ll_EndTime
// Display and search for text clips
ShowStatusWindow (2)
Setpointer (HourGlass !)

Ll_EndTime = Cpu () + 10*1000
If GetCancelStatus (0) = 1 then
End if
// Do what you want to do
Loop until cpu ()> ll_EndTime

CloseStatusWindow ()
Related Article

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: 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.