VB implements translucent or partial transparent forms

Source: Internet
Author: User
Tags transparent color


Windows has been out for more than N years. Let's first introduce the Unique API of windows !! Animatewindow is a new function that produces animation effects when a window is opened or closed. Because it is a new function, it cannot be found in API viewer and must be defined by yourself:

Public declare function setlayeredwindowattributes lib "USER32" (byval hwnd as long, byval crkey as long, byval balpha as byte, byval dwflags as long) as long

'The specific constants that can be used and their usage

Const lwa_alpha = & H2 'indicates that the form is set to a translucent style.
Const lwa_colorkey = & H1 'indicates that the transparent color in the form is not displayed.
 

Example

ProgramCode

Module1

Public declare function setlayeredwindowattributes lib "USER32" (byval hwnd as long, byval crkey as long, byval balpha as byte, byval dwflags as long) as long
Public const ws_ex_layered = & h80000
Public const gwl_exstyle = (-20)
Public const lwa_alpha = & H2
Public const lwa_colorkey = & H1
Public declare function getwindowlong lib "USER32" alias "getwindowlonga" (byval hwnd as long, byval nindex as long) as long
Public declare function setwindowlong lib "USER32" alias "setwindowlonga" (byval hwnd as long, byval nindex as long, byval dwnewlong as long) as long

Form1

Private sub form_load ()
Dim RTN as long

RTN = getwindowlong (Me. hwnd, gwl_exstyle) 'obtains the original style of the window.
RTN = RTN or ws_ex_layered: Add a new style ws_ex_layered to the form.
Setwindowlong me. hwnd, gwl_exstyle, rtn' assign the new style to the form

Setlayeredwindowattributes me. hwnd, 0,192, lwa_alpha

'Set the form to a translucent style. The second parameter indicates the transparency.
'Value range: 0--255. If it is 0, it is a fully transparent form.

End sub

Method 2

Setlayeredwindowattributes me. hwnd, & H0, 0, lwa_colorkey
'Indicates that the transparent color in the form is not displayed.
'And the second parameter indicates that the transparent color is black, and you can use the RGB function to specify the color value.

Download source code:

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.