ProgressBar implements custom display progress values

zhaozj2021-02-16  51

Q: http://community.9cbs.net/expert/topicview.asp?id=3116178

The TProgressBar in the VCL class library is a package for Common Control. So if you want a custom schedule displayed ProgressBar, although you can inherit a full self-fulfillment from TCUSTOMControl, Subclass subcatenification ProgressBar's WindowProc is not a way to be taken.

#include

#pragma HDRSTOP

#include "unit1.h"

/ / -------------------------------------------------------------------------------------------- ---------------------------

#pragma package (smart_init)

#pragma resource "* .dfm"

TFORM1 * FORM1;

/ / -------------------------------------------------------------------------------------------- ---------------------------

__fastcall tform1 :: tform1 (tComponent * Owner)

: TFORM (OWNER)

{

FoldWndProc = progressbar1-> windowproc;

Progressbar1-> WindowProc = ProgressBarwndProc;

Progressbar1-> smooth = true;

}

/ / -------------------------------------------------------------------------------------------- ---------------------------

__fastcall tform1 :: ~ tform1 ()

{

PROGRESSBAR1-> WINDOWPROC = foldwndproc;

FoldWndProc = 0;

}

/ / -------------------------------------------------------------------------------------------- ---------------------------

Void __fastcall tform1 :: progressbarwndproc (tMessage & Message)

{

TProgressBar * progressbar = progressbar1;

Tcanvas * Canvas;

Graphics :: tbitmap * b;

Switch (Message.MSG)

{

Case WM_Paint:

{

Canvas = new tcanvas;

Try

{

Canvas-> Handle = getDC (ProgressBar-> Handle);

Try

{

// Erase Background

TRECT R = ProgressBar-> ClientRect;

Canvas-> Brush-> color = this-> color;

Canvas-> FillRect (r);

FoldWndProc (Message);

// Draw Text

B = New graphics :: tbitmap;

Try

{

B-> width = r.right - r.Left;

B-> Height = R.BOTTOM - R.TOP;

B-> canvas-> brush-> color = CLBLACK;

B-> Canvas-> FillRect (r);

B-> canvas-> font-> style = tfontstyles () <

B-> canvas-> font-> color = CLWHITE; ANSISTRING STR;

Str.SPrintf ("% DK /% DK", ProgressBar-> position, progressbar-> max);

DrawText (b-> canvas-> handle, str.c_str (), -1, & r, dt_noclip | dt_center);

Bitblt (canvas-> handle, 0, 0, b-> width, b-> height, b-> canvas-> handle, 0, 0, srcinvert);

}

__finally

{

Delete B;

}

}

__finally

{

ReleaseDC (ProgressBar-> Handle, Canvas-> Handle);

}

}

__finally

{

Delete Canvas;

}

}

Break;

DEFAULT:

FoldWndProc (Message);

}

}

/ / -------------------------------------------------------------------------------------------- ---------------------------

Void __fastcall tform1 :: button1click (Tobject * Sender)

{

ProgressBar1-> Position = 0;

While (ProgressBar1-> Position <100)

{

progressbar1-> position;

Sleep (50);

Application-> ProcessMess ();

}

}

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

New Post(0)