Transparent window display
Author: StarSight
I have long wanted to write an experience in this area, I have been free, but this time I look for me, I will not shrink my head again.
In fact, I still have a lot of problems and have not been solved, and I will ask the master here.
This article is published in V-Galaxy BBS, if you want to pay, please contact the author
INFO@ministars.com
1. Windows 2000 GDI Expansion Set
The original GDI instruction set is expanded inside Windows 2000, which will directly provide efficient image processing instructions such as Alpha Blending. There is a special window style WS_EX_LAYERED to provide transparent windows in Win2000. Win2000 also provides animatewindow (... A type of API, directly supporting window animation.
Connection
http://www.microsoft.com/hwdev/Video/gdinext.htm
http://x.wonder.ca/stevex/nthack/
2. Implementation method under Win95 / NT
Since Windows does not provide ready-made, you have to do it yourself. In principle it is:
a. Get the DC of the desktop, generate a compatible Bitmap, send a WM_PAINT message, take the desktop to Bitmap. (like a screen capture)
b. Draw yourself to another bitmap
c. Do Alpha Blending, or other effects, generate the third picture with these two pictures.
d. Finally, put the picture bitblt
It is not difficult to say, but there are several problems in technology.
1. How do I copy Hidden's window to the image?
In principle, I can't do it. But I can do some hands and feet in my program. I use the Wizard window in Safeclean Utilities2, I need to get the image before displaying, do it again. I use the WM_PRINT message, usually It is very few, but you can intercept the Z-Order window (Hidden is still not working). For example, I want to turn it from Page 1 (P1) to the second page (P2), I have to display a new window Previously, the P1 was moved to the top, and then the P2 was displayed (blocked by P1), and the WM_PRINT message was sent to P2, and the animation was turned off, and P1 was turned off.
2. WM_PRINT problem
WM_PRINT is actually similar to WM_Paint, but can block the part covered by other windows. But not all windows support WM_PRINT, such as Static Control, can only draw them in Bitmap.
3. How to store the window below Bitmap?
To achieve the real iconent window of the win2000, you must have to exist in the window below your program. If I can implement it, I don't know.
I use the technology that only is only suitable for Splash Window and a static transparent window like Jinshan.
The code I use is below, because some other classes are involved, are distributed in different places, so it is not complete. For reference only. You can see the Bitmap section of www.codeguru.com, there is a good code This time is very busy, the school must start the exam, just a rough introduction, please understand.
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.CREATECOMPATIPLEDC (& DCWNDTO);
CBITMAP BMPTO;
BMPTO.CREATECOMPATIBEBITMAP (& 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;
}