Use Win95 animation cursor

Source: Internet
Author: User

-In Windows 95, the system has a feature not available in Windows 3. X-supports animation cursor files. You can see the animation cursor files under the cursors subdirectory in the Windows 95 directory, all of which have the extension *. Ani. Using the corresponding animation cursor in a program can greatly improve the appearance of the program. This article describes how to use the animation cursor file attached to Windows 95 in your visual basic application.

Use an animated cursor file

---- To use the animation cursor attached to Windows 95 in a visual basic application, you need to use the following Windows application programming interface (API) functions:

  • Loadcursorformfile, used to load the cursor file from the disk;

  • Clipecursor, used to restrict the cursor within a fixed rectangle;

  • Getwindowrect is used to obtain the rectangular area. In the following example, it is the main form of the program;

  • Setclasslong is used to set and extract window data so that the cursor is displayed on the form;

  • Before exiting the application, you need to set the default cursor of the application back to execute the previous cursor. Therefore, you need to back up the previous cursor status before running the program, this function is used to complete this task;

  • Destroycursor: After the cursor is correctly displayed, you need to use this function to cancel the loaded cursor.

Sample program

---- The following example shows the appstart under the C:/Win95/cursors directory in the form area. ani animation cursor file. If your Windows 95 path is different, you need to modify the sample program to correctly display the animation cursor.

  1. Start a new project in Visual Basic and use the default method to create form1.

  2. Create a command button control on form1 and create command1 using the default method. Set its caption attribute to "show animation cursor ".

  3. Create the second command button control on form1 and use the default method to create command2. Set its caption attribute to "Restore the default cursor ".

  4. Create a new module and use the default method to create module1.bas. Add the following declaration, type, and constant statement to the General Declaration section of module1.bas:


    Option explicit
    Type rect
    Left as long
    Top as long
    Right as long
    Bottom as long
    End type
    Public const gcl_hcursor = (-12)
    Declare function clipcursor lib "USER32" (lprect as any) as long
    Declare function destroycursor lib "USER32" (byval hcursor as long) as long
    Declare function loadcursorfromfile lib "USER32" alias "loadcursorfromfilea"
    (Byval lpfilename as string) as long
    Declare function getwindowrect lib "USER32" (byval hwnd as long,
    Lprect as rect) as long
    Declare function setclasslong lib "USER32" alias "setclasslonga"
    (Byval hwnd as long, byval nindex as long, byval dwnewlong as long) as long
    Declare function getclasslong lib "USER32" alias "getclasslonga"
    (Byval hwnd as long, byval nindex as long) as long

    Note that the preceding statement must be written in one line.

  5. Add the following statement to the General Declaration section of form1:


    Option explicit
    Dim mhbasecursor as long
    Dim mhanicursor as long

  6. Add the following code to the form_load event of form1:


    Private sub form_load ()
    Dim lresult as long

    Mhbasecursor = getclasslong (Me. hwnd), gcl_hcursor)
    End sub

  7. Add the following code to the click event of command1:


    Private sub commandementclick ()
    Dim lresult as long
    Dim rt_formarea as rect

    Mhanicursor = loadcursorfromfile ("C:/Win95/cursors/appstart. Ani ")

    Lresult = setclasslong (Me. hwnd), gcl_hcursor, mhanicursor)

    Lresult = getwindowrect (Me. hwnd), rt_formarea)

    Lresult = clipcursor (rt_formarea)
    End sub

  8. Add the following code to the click event of command2:


    Private sub command2_click ()
    Dim lresult as long
    Dim rt_screenarea as rect

    Rt_screenarea.top = 0
    Rt_screenarea.left = 0
    Rt_screenarea.bottom = screen. Height/screen. twipsperpixelx
    Rt_screenarea.right = screen. width/screen. twipsperpixely
    Lresult = clipcursor (rt_screenarea)
    Lresult = setclasslong (Me. hwnd), gcl_hcursor, mhbasecursor)
    Lresult = destroycursor (mhanicursor)
    End sub

    ---- Press F5 to run the program. Click the "show animation cursor" command button, and the cursor becomes appstart within the range of the form. ani cursor, And the cursor is restricted within the range of the form. Click the Restore Default cursor command button to restore the cursor in the form to the default one. Note: before exiting the sample program, you must click the "Restore Default cursor" command. Otherwise, other operations cannot be performed correctly in the system.


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.