du94414 2014-04-11 01:20
浏览 113
已采纳

winapi:WM_PAINT内具有bRepaint TRUE的GetUpdateRect()不会清除绘制区域,但是WM_PAINT之外的InvalidateRect()可以吗?

My custom drawing area's WM_PAINT looks something like this:

// TRUE to clear the background
if (GetUpdateRect(hwnd, &r, TRUE) == 0)
    return; // no update rect; do nothing
dc = BeginPaint(hwnd, &ps);
// check return
// paint some RGBA image data with GDI+
EndPaint(hwnd, &ps);

(Disregard the sending a HDC to GDI+ for now.)

I use GetUpdateRect() here instead of getting the update rect from BeginPaint() because I always want to draw over a blank canvas, especially since I'm doing alpha-mixed drawing here. Furthermore, the docs for WM_PAINT say not to call BeginPaint() if GetUpdateRect() fails.

However, when my custom drawing area actually does this WM_PAINT, it isn't clearing the drawing area. I can tell because the alpha-enabled image is drawn on top of itself, resulting in darker colors.

In another part of my code, I respond to a keyboard event by calling InvalidateRect() to force an update of the whole area. If I change the equivalent of

InvalidateRect(hwnd, NULL, FALSE);

to

InvalidateRect(hwnd, NULL, TRUE);

the area does get cleared properly.

So what exactly AM I doing wrong here? Thanks.

(The actual code is this; it's written in Go. This is also why I am working with GDI+ directly. (I have yet to figure out how to do alpha-mixed stuff with regular GDI.))

  • 写回答

3条回答 默认 最新

  • douxiduan8344 2014-04-12 16:10
    关注

    Thanks to both of you. Stack Overflow will only let me award one check at a time though... And yep, after doing the clearing properly I got the flicker mentioned in the checked answer.

    Ultimately I decided to throw out what I have so far, especially at the advice of Treeki/Ninjifox, who suggested I use the AlphaBlend() function instead. Now, though, I have more problems... but that'll be for another question, with a standalone example program.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序