主题:如何获取被挡窗口完整图像!!求高手指点,急急急
hao1122
[专家分:140] 发布于 2009-07-29 03:31:00
A窗口 被 B窗口 挡住了
GetWindowDC 和 BitBlt 的方法只能获取 B 窗口的图像
请问如何才能获取 A 窗口的完整图像呢?? 被挡住部分的其中一点RGB值也行
谢谢!!!谢谢!!
4 楼
hao1122 [专家分:140] 发布于 2009-07-29 17:55:00
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/a12840781/archive/2009/06/30/4310681.aspx
问题出现:在写窗口弹出动画时需要获得隐藏窗口的图像,经过一番查找没找到好的办法
解决办法:利用WM_PRINT消息向DC里写入,剩下的标题栏什么的就好解决了
部分代码:
void __fastcall TWindowStunt::AnimateShow(TForm* pShowForm, TPoint ptStart,
DWORD dwTime, int nStunt)
{
TRect rcForm; // 用于保存窗口大小
HDC hFormMemDC; // 用于保存窗口截图
HBITMAP hFormMemBmp; // 用于保存窗口截图
HBITMAP hOldMemBmp; // 用于保存窗口截图
//截图
GetWindowRect(pShowForm->Handle, &rcForm);
HDC hFormDC = pShowForm->Canvas->Handle;
hFormMemDC = CreateCompatibleDC(hFormDC);
hFormMemBmp = CreateCompatibleBitmap(hFormDC, rcForm.Width(), rcForm.Height());
hOldMemBmp = SelectObject(hFormMemDC, hFormMemBmp);
////
Graphics::TBitmap* pFormImage = pShowForm->GetFormImage();
int nBorder = (pShowForm->Width - pFormImage->Width)/2;//边框高度
int nTitleBar = nBorder;
if (pShowForm->BorderStyle == bsNone)
{
// Nothing need to do.
}
else if (pShowForm->BorderStyle == bsToolWindow || pShowForm->BorderStyle == bsSizeToolWin)
{
nTitleBar += GetSystemMetrics(SM_CYSMCAPTION);
}
else
{
nTitleBar += GetSystemMetrics(SM_CYCAPTION);
}
BitBlt(hFormMemDC, nBorder, nTitleBar, pShowForm->Width, pShowForm->Height,
pFormImage->Canvas->Handle, 0, 0, SRCCOPY);
delete pFormImage;
////
SendMessage(pShowForm->Handle, WM_PRINT, (WPARAM)hFormMemDC, (LPARAM)PRF_NONCLIENT);
//绘图
if (0 == nStunt)
{
const int nCount = 20;
int nPrecision = 100;
double dbXPos = (ptStart.x - rcForm.left)*nPrecision/nCount;
double dbYPos = (ptStart.y - rcForm.top)*nPrecision/nCount;
////
//SetStretchBltMode(hTempDC, STRETCH_HALFTONE);
for (int nI=1; nI<=nCount; nI++)
{
BitBlt(m_hDesktopMemDC2, 0, 0, m_nScreenWidth, m_nScreenHeight,
m_hDesktopMemDC, 0, 0, SRCCOPY);
StretchBlt(m_hDesktopMemDC2,
ptStart.x - dbXPos*nI/nPrecision,
ptStart.y - nI*dbYPos/nPrecision,
rcForm.Width()*nPrecision/nCount*nI/nPrecision,
rcForm.Height()*nPrecision/nCount*nI/nPrecision,
hFormMemDC, 0, 0, rcForm.Width(), rcForm.Height(), SRCCOPY);
BitBlt(m_pFullScreen->Canvas->Handle, 0, 0, m_nScreenWidth, m_nScreenHeight,
m_hDesktopMemDC2, 0, 0, SRCCOPY);
DelayTime(dwTime/nCount);
}
////
BitBlt(m_hDesktopMemDC2, 0, 0, m_nScreenWidth, m_nScreenHeight,
m_hDesktopMemDC, 0, 0, SRCCOPY);
BitBlt(m_hDesktopMemDC2, rcForm.left, rcForm.top, rcForm.Width(), rcForm.Height(),
hFormMemDC, 0, 0, SRCCOPY);
BitBlt(m_pFullScreen->Canvas->Handle, 0, 0, m_nScreenWidth, m_nScreenHeight,
m_hDesktopMemDC2, 0, 0, SRCCOPY);
}
////
else if (1 == nStunt)
{
int num = rcForm.Width()/20;
for (int i=0; i<20; i++)
{
for (int j=0; j<num; j++)
{
BitBlt(m_pFullScreen->Canvas->Handle, rcForm.left + j*20+i, rcForm.top,
1, rcForm.Height(), hFormMemDC, j*20+i, 0, SRCCOPY);
}
DelayTime(dwTime/20);
}
}
else if (2 == nStunt)
{
}
////
m_pFullScreen->OnPaint = NULL;
m_pFullScreen->Hide();
//清理
SelectObject(hFormMemDC, hOldMemBmp);
DeleteObject(hFormMemBmp);
DeleteDC(hFormMemDC);
////
if (m_hDesktopMemBmp != NULL)
{
SelectObject(m_hDesktopMemDC, m_hOldMemBmp);
DeleteObject(m_hDesktopMemBmp);
m_hDesktopMemBmp = NULL;
}
if (m_hDesktopMemBmp2 != NULL)
{
SelectObject(m_hDesktopMemDC2, m_hOldMemBmp2);
DeleteObject(m_hDesktopMemBmp2);
m_hDesktopMemBmp2 = NULL;
}
if (m_hDesktopMemDC != NULL)
{
DeleteDC(m_hDesktopMemDC);
m_hDesktopMemDC = NULL;
}
if (m_hDesktopMemDC2 != NULL)
{
DeleteDC(m_hDesktopMemDC2);
m_hDesktopMemDC2 = NULL;
}
if (m_hDesktopDC != NULL)
{
ReleaseDC(NULL, m_hDesktopDC);
m_hDesktopDC = NULL;
}
}
有谁能帮忙 把上面的代码 转换为VB的 谢谢谢谢