Develop animation DLL with C ++ Builder

zhaozj2021-02-17  37

In the Windows98 environment, I have a copy of the document. When I find a long exercise, Windows will display a small moving painting, indicating that it is in progress. Operation, the static image of the dead plate is not less than color. Then, when we drive your own software, can you also show a way of this way? The author opened a moving DLL capable enough to use the multi-thread programming, the PB-called DLL function can pay the control power to PB, not Transfer of the infusion system.

I. Code and Compiling Section

Create an empty white DLL item in C Builder.

Create an empty white Form, modify its properties:

Borderstyle = BSDIALOG

Bordericons subtypons are False

Formstyle = fsstayontop

Position = poscreencenter

Name = statusform

Add a Win32 animate control on the Form, and modify its properties as

Align = altop

Add a Standard's button -_cancel to the Formel, add the Timer Control Timer1, set the scheduled interval time bits 250, and the reclaimed request for the settlement.

---- Due to the PB application system and the moving window body code division belongs to two threads, the window of the PB thread is directly closed to the window, otherwise It will lead the system to operate unfair, and this is used to use the PB thread to set off the mark, and the moving thread uses the TIMER control timing inspection mark, once the closed mark is detected. Zhi, turn off the window, clear the thread mark, and end the end of the end.

---- 5. The following is given the code and coded principle:

---- (1) DLL body code:

/ * DLL body code

* Defining DLL public variables

* G_commonavi to animate control

Dynamic painting type index

* GI_CANCELED button_cancel

The button is not selected

* GI_AVITYPE to display the type of animation,

Differential input by DLL output

* GI_REQUESTCLOSE Please ask the moving thread closing mark

* GI_WINDOWACTIVE moving window

* LPSWINTITE Diagram of the title of the window

Differential input by DLL output

* /

Tcommonavi g_commonavi [] = {

Avinone, AvifindFolder,

AvifindFile, AvifindComputer,

AvicopyFiles, AvicopyFile,

Avirecyclefile, Aviemptyrecycle,

Avideletefile

}

INT GI_CANCELED = 0, GI_AVITYPE = 0;

INT GI_REQUESTCLOSE = 0, GI_WINDOWACTIVE = 0;

Char lpswintitle [256];

HWND HWNDPARENT = NULL;

/ * Defining DLL output function * /

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 ();

/ * Defining thread TFORMTHREAD: * /

Class TFormThread: Public TTHREAD {

Public: // user declarations

__fastcall tformthread (bool createSuspend);

Void __fastcall execute (void);

}

__fastcall tformthread ::

TFORMTHREAD (Bool CreateSuspend):

TTHREAD (CreateSuspend) {

}

/ * Move the thread execution code,

The timer control of the moving window will turn off,

The cleaning of the window body is running in the launch of the end

* /

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;

}

/ * Defining a thread instance pointer * /

TFORMTHREAD * FORMTHREAD;

/ * Output function code real estate

* DLLLENTRYPOINT 32-bit DLL entry

* ShowStatusWindow display Dynamics window,

It creates a thread to create a window,

Avoiding MODAL attributes of the window

Return to the call when the control is not possible

* GetStatus gets "pick-up" state,

That is, the user has the "pick-up" button.

* CloseStatusWindow closes the window,

* /

__Declspec (DLLEXPORT) INT WINAPI DLLENTRYPOINT

Hinstance Hinst, Unsigned Long Reason, Void *) {

Return 1;

}

__Declspec (DLLEXPORT) INT Pascal ShowStatusWindow

(int aviitype, lpstr wintitle, long hwnd) {

HWndparent = (hwnd) hwnd;

MEMSET (LPSWINTILE, 0, SIZEOF (LPSWINTILE));

STRNCPY (LPSWINTILE, WINTITLE, SIZEOF (LPSWIN TITLE) -1);

IF (AvityPe> 0 & Avitype <= 8) gi_avitype = "aviitype;" formthread = "new" tFormthread (TRUE); formthread -> priority = tpnormal;

FormthRead -> Resume ();

}

__Declspec (DLLEXPORT) INT Pascal GetStatus

(intloy_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 Window 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;

}

// Take the button does not directly turn off the window.

And refer to the settlement of the consolidation, for the support

Void __fastcall tstatusform :: Button_CancelClick

(TOBJECT * Sender)

{

GI_CANCELED = 1;

// MODALRESULT = MRCANCEL;

}

// Start the animation, in the FormCreate event

Void __fastcall tstatusform :: formcreate

(TOBJECT * Sender)

{

Animate1 -> Commonavi = g_commonavi [GI_AVI

TYPE];

Animate1 -> Active = true;

}

Extern Int gi_requestclose;

// Timer event detects the end of the end flag

Void __fastcall tstatusform :: Timer1Timer

(TOBJECT * Sender)

{

IF (GI_RequestClose) {

ModalResult = MROK;

}

}

V6. Settings Edition: Open the Project Options dialog box, remove the Use Dynamic RTL flag in the Linker property page, clear the Build With runtime packages in the packages property page. This only wants a single DLL to run, without having to install some moving connection running time libraries. Second, use a moving DLL

---- 1. Definition:

// Declare -> Global External Functions

Function Long ShowStatusWindow

(Long Avitype, String Wintitle, Long HWND)

& Library "statwin.dll" alias for

"Show StatusWindow"

Function Long getcancelstatus

(Long Closewindow) & Library

"Statwin.dll" alias for "getstatus"

Function Long CloseStatusWindow () &

Library "statwin.dll" alias for

"ClosestatusWindow"

---- 2. Pixel:

Long ll_endtime

// Display find a document folder

ShowstatusWindow (2)

SetPointer (HOURGLASS!)

LL_ENDTIME = CPU () 10 * 1000

DO

IF getcancelstatus (0) = 1 THEN

exit

END IF

// Do what you want to do

Loop Until CPU ()> LL_ENDTIME

ClosestatusWindow ()

转载请注明原文地址:https://www.9cbs.com/read-29891.html

New Post(0)