Creating Partially Translucent/Transparent Windows in VB (2)

Introduction

In Part 1, we talked about translucent/transparent windows and we mentioned 'holes' and color. We will see how to make holes in a window in this part.

The steps are the same as in translucency (see Part 1). The only difference is in the parameters to the SetLayeredWindowAttributes function.

As we said, SetLayeredWindowAttributes is responsible for translucency. It can also make 'holes' in a window.

Public Declare Function SetLayeredWindowAttributes Lib "user32" _
   (ByVal hwnd As Long, ByVal color As Long, ByVal bAlpha As Byte, _
    ByVal alpha As Long) As Boolean

hwnd: Handle to layered window. ex Me.hwnd.

color: Color used to make areas of a window completely transparent.

bAlpha: Value between 0 (transparent) and 255 (opaque) for alpha blend function.

Flag: Value between 1 and 3. 1 for color, 2 for alpha, and 3 for both of them together.

Example:

SetLayeredWindowAttributes Me.hwnd, RGB(0, 255, 0), 0, 1

Setting color to a value, and setting flag to 1 will cause anything having our color value to become a 'hole.'

So, if we set color to RGB(0,255,0) and then we put a control with color value RGB(0, 255, 0), the portion of the window that the control occupies will become a 'hole' and we can see whatever's behind it.

Let's try it.

I will use a slightly modified version of the SetTranslucent function from Part 1. I'm going to add two parameters to it: Color and Flag. Here's the new SetTranslucent function:

Sub SetTranslucent(ThehWnd As Long, color As Long, nTrans _
                   As Integer, flag As Byte)
On Error GoTo ErrorRtn

   'SetWindowLong and SetLayeredWindowAttributes are API functions;
   'see MSDN for details
   Dim attrib As Long
   attrib = GetWindowLong(ThehWnd, GWL_EXSTYLE)
   SetWindowLong ThehWnd, GWL_EXSTYLE, attrib Or WS_EX_LAYERED
   'anything with color value color will completely disappear if
   'flag = 1 or flag = 3
      SetLayeredWindowAttributes ThehWnd, color, nTrans, flag
   Exit Sub
ErrorRtn:
MsgBox Err.Description & " Source : " & Err.Source

End Sub

That's all there is to it.

Download the project, source, and executable all in one ZIP file.



Downloads

Comments

  • Cheap Oakley Dart wholesale shop

    Posted by xtiadxeof on 07/02/2013 11:47pm

    Womens Oakley Sunglasses ,Oakley sunglasses are instantly recognizable as a result of many unique Oakley model weapons the letter "O" word, this signature Oakley's trademark symbol is different from other designer sunglasses brand. She wore beautiful, jane is not the only one. When individuals are looking for (celebrities), to view just what latest trends, they wear is a huge support and recognition. Regardless if you are inside a family, skating within the beach, or maybe nursing your hangover, cheap Oakley sunglasses to share your perfect accessories. OAkLey FLAk JAcket ,The amalgamation of Oakley shade selection can be quite large, including all the various exquisite design. Oakley's main objective should be to give to them the chance of the chance for several types of range is fully satisfied. Oakley is usually a serious movement, a lively personality behind the focus of sunglasses. Oakley complex technical and brutal character, towards selling point of sportsmen and women. You might find a line of fashionable and classy sunglasses, and if so, you must be glad to learn the website is the best spot to find designer sunglasses. Bulky sunglasses cover most of the division of ??the eye, you'll be able to adjust the straight slender jaw and cheekbones and become the primary choice after you buy. fake oakley sunglasses ,Oakley sunglasses selling world wide, are traditionally used in popular sunglasses, Oakley sunglasses, fashion, sport and health, to keep the strong sunlight, and faraway from you. In fact, every one through the Oakley sunglasses provide 100% UVA and UVB protection. Even non-colored fashion Oakley sunglasses provide you with the same UVA and UVB protection. Besides the design of high-speed and quality of the expansion of high-protection framework. Fake ray bans ,In a nutshell, they even make Oakley sunglasses through the entire mid-summer day, four seasons in the thin air in the beach or boating or skiing. Polarized Oakley sunglasses, discount import high-quality polarized lenses, and a big impact, reduce glare, eliminate reflected light, scattered light is a bit more gentle, clear. sac longchamp pliage ,Our primary concise explaination optical procedures, to further improve the vision of individual high-quality, will reduce the visual distortion inside the lens, therefore you employ a clearer perspective. Whether you intend to get yourself a dvd accessories plus the future of the festival, or just to keep in the vehicle with a sunny day, you can't beat the style and quality they have got. I was thinking, wallets and handbags include the most well-known ladies, but now I'm sure I've got to change my thoughts soon view the the different parts of the title is crazy sunglasses retailer of girls.

    Reply
  • not working, problem on my computer

    Posted by pushu on 03/18/2005 07:54am

    this program does not work on my computer and shows an error code saying: cant find DLL entry point setlayeredwindowattribute in user32 source - translucent windows what is the problem and how may i rectify it? PHS

    • GetLayeredWindowAttribute

      Posted by Laszlo Goch on 10/06/2012 05:52am

      You are trying to call the setlayeredwindowattribute function which does not exist. Try SetLayeredWindowAttributes. Notice the capital letters and the plural "s" at the end.

      Reply
    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Java developers know that testing code changes can be a huge pain, and waiting for an application to redeploy after a code fix can take an eternity. Wouldn't it be great if you could see your code changes immediately, fine-tune, debug, explore and deploy code without waiting for ages? In this white paper, find out how that's possible with a Java plugin that drastically changes the way you develop, test and run Java applications. Discover the advantages of this plugin, and the changes you can expect to see …

  • As a development and deployment platform, RHEL offers an efficient, scalable, and robust operating environment with certified security and flexible deployment options in physical and virtualized environments. To assess and quantify the business benefits of RHEL, IDC recently conducted in-depth interviews with IT staff members of 21 companies using RHEL servers. The organizations represent a broad range of industries and have an average of 22,700 employees. RHEL servers accounted for 23% of the servers …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds