you can use the setlayeredwindowattribut es function provided by windows to set transparency and opacity key values.
bool setlayeredwindowattribut ES (
hwnd, // hierarchical window handle
colorref crkey, // Color Key value
byte balpha, // specifies the degree of opacity. 0 indicates full transparency, 255 indicates full opacity
DWORD dwflags // The Action
);
dwflags value:
lwa_colorkey uses crkey as the transparency value
lwa_alpha uses balpha as the opacity value of the window
This function only supports ws_popup style forms, and does not support ws_child style forms.
Refer:
Setwindowlong (m_draw.m_hwnd, gwl_exstyle, getwindowlong (m_draw.m_hwnd, gwl_exstyle) | ws_ex_layered );
: Setlayeredwindowattributes (m_draw.m_hwnd, 0,128, lwa_alpha );
Specific implementation:
Create a dialog boxProgram, Add a slide and a text box above, use the Class Wizard to add an association variable m_slide for the slide, and add a corresponding function onreleasedcaptureslider1.
CodeAs follows:
Add the following code to the oninitdialog () function:
// Set the size and position of the form to be immutable
: Setwindowpos (m_hwnd, hwnd_topmost, 0, 0, 0, swp_nosize | swp_nomove );
M_slide.setrange (10,255 ); // Set the slider range
M_slide.setpos (128 ); // Set the Initial Sliding position
Setwindowlong (this-> getsafehwnd (), gwl_exstyle, getwindowlong (this-> getsafehwnd (), gwl_exstyle) ^ 0x80000 );
Hinstance hinst = loadlibrary ("user32.dll"); // displays the loaded DLL
If (hinst)
{
Typedef bool (winapi * myfunc) (hwnd, colorref, byte, DWORD );
Myfunc fun = NULL;
// Get setlayeredwindowattribut Es function pointer, which controls transparency
Fun = (myfunc) getprocaddress (hinst, "setlayeredwindowattribut Es ");
If (fun)
Fun (this-> getsafehwnd (), 0,128, 2 );
Freelibrary (hinst );
}
In onreleasedcaptureslider1Add the following code to the function:
Void ctranswindlg: onreleasedcaptureslider1 (Nmhdr * pnmhdr, lresult * presult)
{
// Todo: add your control notification handler code here
Byte eff = (byte) m_slide.getpos (); // get the slider position
Hinstance hinst = loadlibrary ("user32.dll"); // displays the loaded DLL
If (hinst)
{
Typedef bool (winapi * myfunc) (hwnd, colorref, byte, DWORD );
Myfunc fun = NULL;
// Get setlayeredwindowattribut Es function pointer, which controls transparency
Fun = (myfunc) getprocaddress (hinst, "setlayeredwindowattribut Es ");
If (fun)
Fun (this-> getsafehwnd (), 0, Eff, 2 );
Freelibrary (hinst );
}
Cstring STR;
Str. Format ("% d", 100 * eff/255 );
Getdlgitem (idc_edit1)-> setwindowtext (STR );
* Presult = 0;
}