PB in the use of APIs to achieve animation effects

Source: Internet
Author: User

First, the question of the proposed

PowerBuilder is an object-oriented development of large-scale database graphical front-end development tool, its outstanding performance is more and more popular with the development staff. However, the drawing aspect is not enough. The display of its pictures is mainly by the picture control to complete, because not like c++builder and other tools such as the canvas function, to achieve animation effects, the image control itself by the properties and methods to achieve, can only complete the basic, simple animation, and the effect is not ideal, easy to produce flicker phenomenon. In order to better realize the animation effect, we call the Windows API function, the result not only overcomes the flicker phenomenon, but also realizes the more complex animation function.

Second, design ideas

We know that the Windows Graphics device interface provides a screen and printer-independent interface for Windows applications, and the basic tool that Windows uses to provide device-agnostic for applications is the device description table (dc). To display the bitmap, add the bitmap to the Display Device description table. The program usually cannot draw directly on the device description table, using the CREATECOMPATIBLEDC function to create a Memory device Description table compatible with the specified device, and whenever the program uses a bitmap, the program first places the bitmap in the Memory Device description table and then copies it to the specified device description table.

So how do we use the above principles to implement the animation effects in PowerBuilder? Because bitmap images are displayed in PowerBuilder by the picture control, you can get the device description table for the image control by using the function GetDC that gets the device description table. Then, the bitmap in its compatible memory device description table can be copied to the Picture Equipment Description table by BitBlt and StretchBlt function, and the animation effect can be formed by the time delay.

Third, the Windows API functions involved

The Declaration of the API function under PowerBuilder is as follows:

1)function UINT GetDC (UINT hwnd) Library "C:\windows\system\user32.dll"//obtain a display device description sheet. The parameter HWND identifies the handle of the window that will draw. If successful, returns the device description table for the specified window, or null if it fails.

2)function long BitBlt (UINT hdcdest,int xdest,int ydest,int wdest,int hdest,uint hdcsrc,int xsrc,int ysrc,ulong dwrop) li Brary "C:\windows\system\gdi32.dll"//Transfer pictures from the source Device description table to the Destination Device description table. Parameter Hdcdest identifies the purpose of image transfer dc,xdest and Ydest identifies the location of the destination DC, wdest and Hdest identify the width and height of the image, hwndsrc identify the source of the image transfer dc,xsrc and YSRC identify the location of the source DC, Dwrop identifies image transfer mode. If the successful return value is 0, the failure return value is Non-zero.

3)function long stretchblt uint hddest,int xdest,int ydest,int wdest,int hdest,uint hdsrc,int xsrc,int ysrc,int wsrc,int Hsrc,ulong dwrop) Library "C:\windows\system\gdi32.dll"//enlarge, shrink, flip, and transfer the picture in the Source Device description table to the Target Device description table. The parameter meaning is the same as that in BitBlt, the WSRC and hsrc are the width and height of the source image.

The 4)function ulong ReleaseDC (ULONG Hwnd,ulong hdc) Library "C:\windows\system\user32.dll"//Will be released from the equipment description table obtained by GETDC. Parameter HWND Identification window, HDC identifies the device description table that RELEASEDC will release, returns 1 if the release succeeds, and returns 0 if the release fails.

5)function ULONG CreateCompatibleDC (ULONG hdc) Library "C:\windows\system\gdi32.dll"//Create a HDC compatible memory device description table. The parameter HDC identifies the device description table. If the creation succeeds, the Memory Device description table is returned, or null if the creation fails.

6)function ULONG DeleteDC (ULONG hdc) Library "C:\windows\system\gdi32.dll"//Will be released by the DC established by CreateCompatibleDC. Parameter HDC is a handle to the device description table. If successful, the return value is Non-zero, and if it fails, the return value is 0.

7)function ULONG SelectObject (ULONG hdc, ULONG hobject) Library "C:\windows\system\gdi32.dll"//Select an established object into the specified device description table. The parameter hdc identifies the handle to the DC, hobject the handle to the object. Returns the handle of the previous object of the same type in the DC.

8)function ULONG DeleteObject (ULONG hobject) Library "C:\windows\system\gdi32.dll"//delete a bitmap, color object. Parameter hobject is the handle of the object. If successful, the return value is Non-zero, and if it fails, the return value is 0.

9)function ULONG Loadimagea (ulong hintance, ref string Filename,uint utype,int width,int height,uint) Library "Fload Indows\system\user32.dll "//mount a bitmap, icon, cursor. The parameter is hintance as a handle to an instance containing an image, and if an OEM image is mounted, this parameter is set to 0,filename as the name or definition of the image, Utype for the type of the mount image, the width and the height are the widths and heights of the desired image when loaded. The fload is a sign for loading. If successful, the return value is the handle of the most recently mounted image, and if it fails, the return value is null.

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.