Progress bar made by Pb

Source: Internet
Author: User
Tags transparent color textout

 

PowerBuilder is recognized as one of the best Database Front-end development tools. However, PB is monotonous in user interface processing for a long time. The most obvious example is, all window controls do not support transparent colors, that is, transparent. In versions earlier than PowerBuilder 7, the progress bar is not provided, so most programmers always use two Rectangle controls in the program to program the progress. In this way, the Progress percentage in the progress bar is lost. If a static text is added as the percentage, the percentage of the progress bar cannot overlap with the progress bar because the statictext control has no transparent color, you have to place a statictext control outside the progress bar to display the progress, which wastes space and is not beautiful.

I have also seen the solution on the Internet. It mainly utilizes the features that can be transparently processed by controls in the data window. However, I always feel that the data window is a heavy-duty control, if you need to occupy a large amount of system resources, can you use other simpler methods to solve the above problems?

The key to the above problems lies in the transparency of the text output background. We know that Windows provides a large number of underlying API functions for upper-layer applications to call, text output is the most basic, so Windows must be able to solve the problem of transparent text background output. Find the API help carefully and find the relevant functions, so the problem is solved.

The main statements and main program sections of object implementation are listed below:

Create a new visual Custom User object uo_progressbar, and place two rectangular controls (Rectangle) in it, named r_back and r_front respectively. The instance variables are defined as follows:

Ulong iul_ihDC // Save the DC handle of the Custom User object
Real ir_step // The step value calculated based on the object width
Integer ii_x, ii_y
// The text output location calculated based on the object width and height

Declare Local external functions as follows:

Function ulong GetDC (ulong hWnd) Library "USER32.DLL"

Function boolean TextOut (ulong hdcr, integer stx,
Integer sty, ref string lpString, long nCount)
Library "GDI32.DLL" Alias for "TextOutA"

Function int SetBkMode (ulong hdcr, integer mode)
Library "GDI32.DLL"

Enter the following code in the constructor event of the object:

Integer li_width, li_height
// Calculate the width and height based on the object change box
Choose case this. BorderStyle
CASE StyleLowered !, StyleRaised!
Li_width = this. width-PixelsToUnits (4, XPixelsToUnits !)
Li_height = this. height-PixelsToUnits (4, YPixelsToUnits !)
CASE StyleBox !, StyleShadowBox!
Li_width = this. width-PixelsToUnits (2, XPixelsToUnits !)
Li_height = this. height-PixelsToUnits (2, XPixelsToUnits !)
CASE Else
Li_width = this. width
Li_height = this. height
END CHOOSE

R_back.width = li_width
R_front.height = li_height
R_front.width = 0
R_back.height = li_height
// Calculate the percentage text output position so that it is centered horizontally and vertically.
Ii_x = UnitsToPixels (li_width, XUnitsToPixels !) /2-16
Ii_y = (UnitsToPixels (li_height, YUnitsToPixels !) -16)/2
Ir_step = li_width/100 // calculate the step value
Iul_ihDC = GetDC (handle (this ))
// Obtain the DC handle of the object for API call
SetBkMode (iul_ihdc, 1) // set the text output background color to transparent

Return 0
Write a function for the object: of_setposition,
// Function: display the progress of Parameter Changes
// Parameter: integer ai_percent
// Return: None
String ls_msg
Integer li_x
If ai_percent <= 100 and ai_percent <0 then SetRedraw (FALSE) li_x = "ai_percent * ir_step" r_back.x = "li_x" r_front.width = "li_x" ls_msg = "string (" ai_percent) + "%" SetRedraw (True) TextOut (iul_ihdc, ii_x, ii_y,
Ls_msg, len (ls_msg) End If

Of course, you can also write a function to change the foreground color and text color in the progress bar.

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: info-contact@alibabacloud.com 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.