Windows interface Programming (2) semitransparent forms

Source: Internet
Author: User
Tags function prototype transparent color

The previous "Windows interface programming first bitmap background and bit drawing brush" introduces the background of the dialog box by Wm_ctlcolordlg message and the use of the bit drawing brush. This article describes how to dynamically adjust the transparency of a form.

Adjust form transparency You can use SetWindowLong to add a ws_ex_layered property to a form and then use it to setlayeredwindowattributes the transparency of the specified form. This allows you to dynamically adjust the transparency of the form while the program is running.

The following SetWindowLong and SetLayeredWindowAttributes functions are described first.

SetWindowLong can be used to set some of the properties of a window, with the following function prototypes:

Longsetwindowlong (

Hwndhwnd,

int nindex,

Longdwnewlong

);

The first parameter represents a window handle.

The second parameter represents which value to set, such as Gwl_style indicates that the style of the window will be set, this parameter can also take gwl_exstyle,gwl_wndproc,dwl_dlgproc,gwl_hinstance,gwl_userdata and so on.

The third parameter represents the value to set.

For example, to set the dialog box can also adjust the window size, you can use:

Set dialog box size to adjust

SetWindowLong (Hdlg, Gwl_style, GetWindowLong (hdlg, Gwl_style) | Ws_sizebox);

The SetLayeredWindowAttributes is explained on MSDN as follows:

The SetLayeredWindowAttributes function sets the opacity and transparency color key of a layered window.

Its function prototype is:

Boolsetlayeredwindowattributes (

Hwndhwnd,

Colorrefcrkey,

Bytebalpha,

Dworddwflags

);

The first parameter represents a window handle.

The second parameter represents a transparent color.

The third parameter represents transparency.

The fourth parameter represents what functionality the function will accomplish, set to Lwa_colorkey to specify a transparent color for the window, set to Lwa_alpha that will adjust the transparency of the window, and both functions can be set.

The program code will also use the slider control, which can have the following actions:

1. Set the range of slider changes by SendMessage + Tbm_setrange.

2. Set the current position of the slider by SendMessage + tbm_setpos.

3. The current position of the slider is obtained by SendMessage + Tbm_getpos.

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/VC_NET/

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.