Transparent window display
Author: starsight
I have long wanted to write an article about my experience in this area. I have been very busy and I am not empty. However, this time I was asked to contact me by name, it would be hard to shrink my mind. in fact, I still have a lot of problems to solve, and I will also ask experts here. this article is published in V-Galaxy BBS, if you want to post please contact the author info@ministars.com1. windows 2000's GDI + extended set Windows 2000 extends the original GDI instruction set to directly provide efficient image processing commands such as alpha blending. in Win2000, there is a special window style ws_ex_layered which provides the possibility of transparent windows. win2000 also provides an animation window (...) one type of API directly supports window animation.
About the connection http://www.microsoft.com/hwdev/video/GDInext.htmhttp://x.wonder.ca/stevex/nthack/
2. since Windows does not provide a ready-made implementation method under Win95/NT, you have to do it yourself. in principle:. obtain the DC of the desktop, generate a compatible bitmap, send a wm_paint message, and get the desktop to bitmap. (like a screen capture) B. draw the window you want to open to another bitmapc. use these two images for alpha blending or other effects to generate the third image. d. finally, bitblt the image.
It is not difficult to say, but there are several technical problems. 1. How to copy the hidden window to the image? In principle, it is impossible. but you can do something in your own program. the wizard window I used in safeclean utilities2 needs to get the image and process it before it is displayed. I use wm_print messages, which are rarely used at ordinary times, but I can intercept windows with low Z-order values (hidden is not enough ). for example, if I want to switch from page 1 (P1) to page 2 (P2), I have to move P1 to the top of the screen before displaying a new window, display P2 again (blocked by P1), send the wm_print message to p2 to block the film, then perform the animation, and disable P1.
2. wm_print: wm_print is similar to wm_paint, but it can block the parts covered by other windows. however, not all Windows support wm_print, such as static control. They can only be painted in bitmap.
3. How to store the window below the program in bitmap? To implement a real transparent window like Win2000, you must store the window under your own program in the image. I am not sure whether it can be implemented. the technology I used is actually only suitable for making splash windows and static transparent windows like Kingsoft.
The code I used is listed below. It is incomplete because some other classes are distributed in different places. for reference only. for details about how to use alpha blending, refer to the bitmap section of www.codeguru.com and have good code. this time is very busy. The school has to take the test again. It's just a rough introduction. Please forgive me.
int CFadeWindow::FadeAndSwitchWindow(CWnd* pWndFrom, CWnd* pWndTo){CWnd* pDesktop = CWnd::GetDesktopWindow();
CWnd* pMain = AfxGetMainWnd();CClientDC dc(pMain);CRect rc;pWndFrom->GetWindowRect(rc);pMain->ScreenToClient(rc);
CDC *pDCFrom;pDCFrom=pWndFrom->GetDC ();m_dib1.PasteDC ( pDCFrom, 0, 0, rc.Width(), rc.Height());m_dib3.PasteDC ( pDCFrom, 0, 0, rc.Width(), rc.Height());pWndFrom->ReleaseDC ( pDCFrom );
CClientDC dcWndTo(pWndTo);CDC dcTo;dcTo.CreateCompatibleDC(&dcWndTo);CBitmap bmpTo;bmpTo.CreateCompatibleBitmap(&dcWndTo, rc.Width(), rc.Height());CBitmap * pOldbmp = dcTo.SelectObject(&bmpTo);SetWindowPos(pWndFrom->GetSafeHwnd(), HWND_TOP, 0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);pWndTo->ShowWindow(SW_SHOW);pWndTo->SendMessage(WM_PRINT, (WPARAM) dcTo.GetSafeHdc(), (LPARAM) PRF_CLIENT|PRF_CHILDREN|PRF_OWNED);m_dib2.PasteDC ( &dcTo, 0, 0, rc.Width(), rc.Height());dcTo.SelectObject(pOldbmp);
SetWindowPos(pWndTo->GetSafeHwnd(), HWND_TOP, 0,0,0,0,SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_SHOWWINDOW);SetWindowPos(pWndFrom->GetSafeHwnd(), NULL, 0,0,0,0,SWP_NOSIZE|SWP_NOMOVE|SWP_NOREDRAW|SWP_NOZORDER|SWP_HIDEWINDOW);
int index = 5;for (int i=0; i {m_dib3.Paste(&m_dib1);
m_dib3.Blend(&m_dib2, i*256/index);m_draw.DrawDib ( &m_dib3, dc.GetSafeHdc(), rc.left, rc.top,rc.Width(), rc.Height(), DDF_HALFTONE );
Sleep(10);}m_draw.DrawDib ( &m_dib2, dc.GetSafeHdc(), rc.left, rc.top,rc.Width(), rc.Height(), DDF_HALFTONE );return 1;}