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/