Create a dialog box with transparent effect in VC

Source: Internet
Author: User

1. Create a dialog box-based MFC exe

2. In the oninitdialog function of the dialog box, set the extended attribute of the dialog box to ws_ex_layered.

Const ws_ex_layered = 0x80000;

: Setwindowlong (getsafehwnd (), gwl_exstyle,
Getwindowlong (getsafehwnd (), gwl_exstyle) | ws_ex_layered );

3. In the oninitdialog function of the dialog box, set the dialog box to transparent.

Hinstance hinst;

Const lwa_colorkey = 0x00001;
Const lwa_alpha = 0x00002;

Typedef bool (winapi * fsetlayeredwindowattributes) (hwnd, colorref, byte, DWORD );
Fsetlayeredwindowattributes setlayeredwindowattributes;

Hinst = loadlibrary ("user32.dll ");

Setlayeredwindowattributes = (fsetlayeredwindowattributes)
Getprocaddress (hinst, "setlayeredwindowattributes ");

Setlayeredwindowattributes (getsafehwnd (), RGB (150, 0), lwa_alpha );

Freelibrary (hinst );

Note: This method is applicable only to Windows and later platforms. 

Supplement:
There is another way to make the dialog box transparent and easier, but I also tried it on my computer in addition to my own computer. The effect is not good at all, in this case, open the dialog box resource in VC, right-click the dialog box Editor, select Properties, select extented style, and select transparent. This effect is not obvious on my computer, but you can try it.

 

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.