Transparent forms implemented by VC

Source: Internet
Author: User

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;
}

Related Article

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.