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条)

报告相同问题?

悬赏问题

  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入