I saw a lot of screens intercepted on the Internet, I believe that everyone has seen a lot. Every progress in humans is always based on others, I have to do how to dynamically display a window on another window.
The method is simple, the core algorithm is to complete the DC displaying another window to a window DC. For the convenience of the reuse, I specially put it into a function written by myself:
BOOL CSHOW_WINDOWDCVIEW :: Show_Windowdc (WND * PWNDDEST / * WND Pointer * /,
CWND * PWNDSRC / * Source window * /)
{
// Of course, the regular point has to judge it iskindof ("cwnd"), I am lazy here.
IF (PWNDDEST == Null || PWNDSRC == Null) Return False;
CRECT SRCRECT;
PWNDSRC-> GetWindowRect (& srcRect);
// Memory device description table
HDC HSRCDC, HMEMDC;
// bit map handle
Hbitmap hbitmap, holdbitmap;
// bitmap width and height
INT NWIDTH, NHEIGHT;
PWNDSRC-> Invalidate ();
HSRCDC = PWNDSRC-> getdc () -> m_hdc;
// Create a memory device description table compatible with the source window device description table
HMEMDC = CreateCompaTibleDC (HSRCDC);
NWIDTH = SRCRECT.WIDTH ();
NHEIGHT = SrcRect.height ();
// Create a bitmap compatible with the source window device description table
Hbitmap = CreateCompaPatibleBitmap (HSRCDC, NWIDTH, NHEIGHT);
/ / Put the new bitmap in the memory device descriptor table
Holdbitmap = (hbitmap) SelectObject (HMEMDC, HBitmap);
/ / Copy the screen device description table to the memory device descriptor table
Bitblt (HMEMDC, 0, 0, NWIDTH, NHEIGHT, HSRCDC, 0, 0, SRCCPY);
// Get the handle of a bitmap
Hbitmap = (hbitmap) SelectObject (HMEMDC, Holdbitmap);
CRECT DESTRECT;
GetWindowRect (& DESTRECT);
CDC DCMEM;
// Create a bitmap compatible with the target window device description table
DcMem.createCompatibleDC (getDC ());
Hbitmap Poldbitmap = (Hbitmap) SelectObject (DcMem.m_HDC, HBitmap);
GetDC () -> Stretchblt (0,0,
DestRect.width (),
DestRect.height (),
& DCMEM, 0, 0,
NWIDTH, NHEIGHT,
SRCCopy); // Display bitmap
// after the work
Deletedc (HSRCDC);
Deletedc (HMEMDC);
DcMem.selectObject (Poldbitmap);
DcMem.deletedc ();
Return True;
} With this function of support, other implementations are simple. To achieve dynamic acquisition of a window of DC as long as a timer is added
Settimer (1,100, null);
Place a refresh statement in the timer.
Invalidate ();
In addition, in order to eliminate unnecessary flashes, it is necessary to overload the WM_RASEBKGND message, as long as the corresponding OneRaseBkGnd (CDC * PDC) adds return true, the other is not, and finally add: CWND * Source = FINDWINDOW ("GeminiWindowClass", NULL); / / Search window
Search hereinaler search for my Realone window
BOOL RST = show_windowdc (this, source);
For the beauty of the program, I will drop the menu, toolbar, and status bar, and can refer to my source program. The program is running as follows: Snapshot Conclusion The program is of course many problems. For example, I can only find a specific window, not flexible, I introduce one article, "How to write a class SPY search window program", I believe it can solve this problem. When the program is running, it is necessary to ensure that the source window is visible, otherwise, it is not possible to display properly. Also borrow this opportunity, I hope that everyone can have a better idea can be present here, the program is pronounced under XP V6.0.