UpdateLayeredWindowIndirect到底该如何使用? 求大神

Just_bg 2014-01-21 09:20:18
void CBkDashboardDlg::DrawLeds(int index, BOOL bright)
{
CRect rcClient;
GetWindowRect(&rcClient);
CRect rc = m_rcLedsArry[index];
//ClientToScreen(rc);
//ClientToScreen(&rcClient);
HDC dc =::GetDC(m_hWnd);
CDC memDc;
memDc.CreateCompatibleDC(dc);
int nWidth = rcClient.Width();
int nHeight = rcClient.Height();
m_bmpInfo.bmiHeader.biWidth = nWidth; // bmp宽度,单位像素
m_bmpInfo.bmiHeader.biHeight = nHeight;
HBITMAP hBitMap =
::CreateDIBSection(
memDc,
&m_bmpInfo,
DIB_RGB_COLORS,
NULL,
NULL,
0);
HBITMAP hOldBmp = memDc.SelectBitmap(hBitMap);
Graphics graph(memDc.m_hDC);
int nImageIndex = bright?index+ICONS_NUM:index;
graph.DrawImage(m_pLedsImageArry[nImageIndex], 0, 0, nWidth, nHeight);

SIZE sz = {rcClient.Width(), rcClient.Height()};
// UpdateLayeredWindowIndirect
UPDATELAYEREDWINDOWINFO updateinfo = {0};
updateinfo.cbSize = sizeof(UPDATELAYEREDWINDOWINFO);
updateinfo.pptDst = &CPoint(rcClient.left, rcClient.top);
SIZE szz = {rcClient.Width(), rcClient.Height()};
updateinfo.psize = &szz;
updateinfo.hdcSrc = memDc.m_hDC;
//updateinfo.dwFlags = ULW_ALPHA;
updateinfo.hdcDst = dc;
updateinfo.pblend = &m_blend;
updateinfo.pptSrc = &CPoint(0, 0);
//ScreenToClient(rc);
RECT rcDirty = {rc.left, rc.top,rc.right, rc.bottom};
updateinfo.prcDirty = &rcDirty;
//UpdateLayeredWindow(m_hWnd, dc, &CPoint(rcClient.left, rcClient.top), &sz, memDc,
// &CPoint( rc.left, rc.top), 0, &m_blend, ULW_ALPHA);

UpdateLayeredWindowIndirect(m_hWnd, &updateinfo);
DWORD db = GetLastError();
if (hOldBmp)
memDc.SelectBitmap(hOldBmp);
DeleteObject(hBitMap);
graph.ReleaseHDC(memDc.m_hDC);
memDc.DeleteDC();
ReleaseDC(dc);
}
在分层窗口中说这个UpdateLayeredWindowIndirect函数可以局部更新但是我怎么搞都没办法啊,
...全文
828 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
向立天 2014-02-22
  • 打赏
  • 举报
回复
您好 我是本版版主 此帖已多日无人关注 请您及时结帖 如您认为问题没有解决可按无满意结帖处理 另外本版设置了疑难问题汇总帖 并已在版面置顶 相关规定其帖子中有说明 您可以根据规定提交您帖子的链接 如您目前不想结帖只需回帖说明 我们会删除此结帖通知 见此回复三日内无回应 我们将强制结帖 相关规定详见界面界面版关于版主结帖工作的具体办法
Just_bg 2014-01-21
  • 打赏
  • 举报
回复
大神速来啊,这个函数把我搞糊涂了, 网上关于这个函数使用说明几乎没有,只有看msdn
Just_bg 2014-01-21
  • 打赏
  • 举报
回复
大家来帮忙顶下, 等待大神来啊
Just_bg 2014-01-21
  • 打赏
  • 举报
回复
看了MSDN prcDirty Type: const RECT* The area to be updated. This parameter can be NULL. If it is non-NULL, only the area in this rectangle is updated from the source DC. 看这个参数这明显是说可以区域更新的 但是再看函数说明:UpdateLayeredWindowIndirect always updates the entire window. To update part of a window, use the traditional WM_PAINT and set the blend value using SetLayeredWindowAttributes. 我擦 , 这是说这个函数总是更新整个窗口。到底在分层窗口中这个函数能不能局部更新呢? 因为我的界面是透明分层窗口, 如果使用UpdateLayeredWindow 话会每次更新整个界面都要重画, 但是我界面比较复杂, 包悍很多图像及一些动态旋转的图片。所以刚初始化是我用UpdateLayeredWindow 画整个窗口,这个确实没问题,然后后面要改变某一个图标调用UpdateLayeredWindow 也是可以的,但是每次重画的话代价有点大。所以我想UpdateLayeredWindow 画整个界面用,用UpdateLayeredWindowIndirect来更新局部,比如改变某一个图标,这样效率会大大提高。万万没想到的是UpdateLayeredWindowIndirect 这个函数我看了MSDN,上面解释让我稀里糊涂,而且我写出来的代码也不能局部更新。求大神告知为什么? 这个函数到底杂用?

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧