CPoint ptWnd;
GetCursorPos(&ptWnd);
CWnd* pWnd = WindowFromPoint(ptWnd);
pWnd->SetForegroundWindow();
CDC* pDc = pWnd->GetDC();
int nBpp = pDc->GetDeviceCaps(BITSPIXEL);
int tmpPos = 0;
int n = 0;
CImage img;
CRect rc;
pWnd->GetClientRect(&rc);
img.Create(rc.Width(), rc.Height(), nBpp);
while (true)
{
keybd_event(VK_NEXT, 0, 0, 0);
keybd_event(VK_NEXT, 0, KEYEVENTF_KEYUP, 0);
Sleep(500);
SCROLLINFO si = {};
si.cbSize = sizeof(si);
si.fMask = SIF_ALL;
pWnd->GetScrollInfo(SB_VERT, &si);
if (tmpPos == si.nPos && tmpPos != 0)
{
break;
}
n += 1;
CImage newImg;
CImage tempImg;
newImg.Create(rc.Width(), rc.Height(), nBpp);
HDC hdc = newImg.GetDC();
::BitBlt(hdc, 0, 0, rc.Width(), rc.Height(), pDc->m_hDC, 0, 0, SRCCOPY);
if (n == 1)
{
HDC newhdc = img.GetDC();
::BitBlt(newhdc, 0, 0, rc.Width(), rc.Height(), hdc, 0, 0, SRCCOPY);
img.ReleaseDC();
}
else
{
tempImg.Create(rc.Width(), rc.Height() * (n - 1), nBpp);
HDC newhdc = img.GetDC();
HDC newHdc = tempImg.GetDC();
::BitBlt(newHdc, 0, 0, rc.Width(), rc.Height() * (n - 1), newhdc, 0, 0, SRCCOPY);
img.ReleaseDC();
img.Destroy();
img.Create(rc.Width(), rc.Height() * n, nBpp);
newhdc = img.GetDC();
::BitBlt(newhdc, 0, 0, rc.Width(), rc.Height() * (n - 1), newHdc, 0, 0, SRCCOPY);
::BitBlt(newhdc, 0, rc.Height() * (n - 1), rc.Width(), rc.Height(), hdc, 0, 0, SRCCOPY);
img.ReleaseDC();
tempImg.ReleaseDC();
}
tmpPos = si.nPos;
newImg.ReleaseDC();
}
img.Save(L"1.png");