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.
|