Problems encountered by using double-layer windows for shadow and transparency

Source: Internet
Author: User

In wnidows C ++ client development, the use of GDI + and PNG transparent or profiled images, combined with updatelayeredwindow double-layer windows, can achieve transparent, shadow, shaped effect. The principle is that the background window uses updatelayeredwindow to refresh the PNG image. The foreground window is used as the actual window to put some space, but the foreground window is actually transparent, so you can click to move the background window, then, when the background window is moved, the foreground window is moved.

1. When the product is about to be released immediately, the window is displayed on the XP system and cannot be clicked back when the window is minimized to the taskbar. Modifystyle (0, ws_minimizebox, 0 );

When onactive () is used, the problem cannot be discussed, but the problem has to be bypassed. Later I discovered the cause.

Void cbackdlg: onmove (int x, int y) {cdialog: onmove (x, y); crect rect; getwindowrect (rect ); // both XP and Windows 7 are normal. M_pchildwnd-> movewindow (rect. left, rect. top, rect. width (), rect. height (); // On the XP system, when the window returns to the taskbar, click the taskbar window to renew. But it works normally on win7. // M_pchildwnd-> setwindowpos (null, rect. Left, rect. Top, rect. Width (), rect. Height (), swp_showwindow );}

2. Set the position of the first startup window, and the second parameter of updatelayeredwindow. You can also set it in oninitdialog, but sometimes the effect

It does not seem very good.

BOOL CBackDlg: OnEraseBkgnd (CDC * pDC) {CRect rect; this-> GetClientRect (rect); if (! M_pBkImage) {m_pBkImage = new Image (_ T ("main_frame.png");} int wndW = rect. width (); int wndH = rect. height (); CDC memDC; CBitmap memBmp; memDC. createCompatibleDC (pDC); memBmp. createCompatibleBitmap (pDC, wndW, wndH); CBitmap * pOldBmp = memDC. selectObject (& memBmp); ModifyStyleEx (0, WS_EX_LAYERED); Graphics BMP Graphics (memDC. m_hDC); BMP graphics. setSmoothingMode (SmoothingModeAntiAlias); BMP graphics. dr AwImage (m_pBkImage, 0, 0, wndW, wndH); BLENDFUNCTION _ Blend; _ Blend. blendOp = 0; _ Blend. blendFlags = 0; _ Blend. alphaFormat = 1; _ Blend. sourceConstantAlpha = 255; int posX = (GetSystemMetrics (SM_CXSCREEN)-wndW)/2; int posY = (GetSystemMetrics (SM_CYSCREEN)-wndH)/2; // at this time, the mouse will penetrate the area where the Alpha value is 0 in the form. UpdateLayeredWindow (pDC, & CPoint (posX, posY), & CSize (wndW, wndH), & memDC, & CPoint (0, 0), 0, & _ Blend, ULW_ALPHA); BMP graphics. releaseHDC (memDC. m_hDC); memDC. selectObject (pOldBmp); memDC. deleteDC (); return TRUE ;}

3. the tray menu masking dialog box cannot be moved. Do not create a tray or menu dynamically.

4. Can single-layer windows achieve PNG shadow and transparency?

Of course it can be implemented. Unfortunately, all the controls in your window will not be displayed. After UpdateLayeredWindow is used, the window will no longer respond to the OnPaint and OnEraseBkgnd messages, which is Microsoft's disgusting situation, it means that you want to use UpdateLayeredWindow, so you can redraw all of them. I don't care. When you use spy ++, you can view the negative effects of QQ, Kingsoft's shadow window, And the WS_EX_LAYERED extension status. It seems that UpdateLayeredWindow is also used, so you don't know if they can implement it in a single layer. The knowledge is too limited and will be studied later.

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.