GDI的小问题

ed9er 2001-03-08 03:52:00
case WM_LBUTTONDOWN:
InvalidateRect(hwnd, NULL, FALSE);
return 0;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
if (ps.fErase)
TextOut(hdc, 10, 10, "ab", 2);
EndPaint(hwnd, &ps);
return 0;
据MSDN说,InvlidateRect用FALSE的话,系统就不替我擦背景,然后当我从BeginPaint拿到ps后,ps.fErase应该就是TRUE,可为什么我的"ab"输不出来?
...全文
319 19 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
ed9er 2001-03-12
  • 打赏
  • 举报
回复
无聊,再说那个程序也不是我写的
招RD和QA 2001-03-11
  • 打赏
  • 举报
回复
我看见你写过一个写名字的代码,大概只有两行,(不过我看不懂)

不知道上面这个图需要几行代码?
ed9er 2001-03-11
  • 打赏
  • 举报
回复
??什么意思?
招RD和QA 2001-03-11
  • 打赏
  • 举报
回复
```````````````````````````````````````````````````````````````````````````````````````
```````````````````````````````````````````````````````````````````````````````````````
````````````````````````````````````````````````````````````````````````#####``````````
```````````````````````````###````````````````````````````````````````#########````````
``````````````````````##########``````````````````````````````####`#############```````
````````````###````````#########```````````````````````````````#########``######```````
``````````#######```````########``````````````````````````````#########``#######```````
`````````#########`````############`````````````````````````#########```#######````````
```````###########````#############````````````````````````#########``#######``````````
```````###########````########`####````````````````````````#######`#########```````````
``````````#######`````######``#####````````````````````````######`########`````````````
```````###```####````###```######``````````````````````````####```##########```````````
```````####``####````############`````````````````````````````````###########``````````
```````###`#####`````#########````````````````````````````````````###############``````
```````###``####`````######`##########`````````````````````````````################````
``````####``#####```###################````````````````````````####################````
``````#############`##############`#####````````````````````########################```
``````######################``####`#####``````````````````##########`````##########````
``````#######``#######```##############`````````````````##########````````####`````````
``````#####`##`########################`````````````````########``````````####`````````
``````###`####`##################``####``````````````````#####````````````####`````````
``````#######``#############``###``####``````````````````###``````````````####`````````
``###########``####`###``###``###``####``````````````````####````````````#####`````````
``########````#####`###``###`##########```````````````````#####``````````####``````````
```################``##```##``########``````````````````````######``````#####``````````
````##```#########```##``````#########```````````````````````################``````````
```````````######````````````###`####``````````````````````````#############```````````
````````````####`````````````###``###````````````````````````````##########````````````
````````````````````````````````````````````````````````````````````######`````````````
```````````````````````````````````````````````````````````````````````````````````````
```````````````````````````````````````````````````````````````````````````````````````
我也有东西要问你,写出上面这个图要几行代码?
ed9er 2001-03-10
  • 打赏
  • 举报
回复
是啊,好象就是这样了,只能说是好象
招RD和QA 2001-03-10
  • 打赏
  • 举报
回复
我也试了一下。
InalidateRect( ... )的最后一参数决定了在BeginPaint()的时候是否发送WM_ERASEBKGND消息。

而WNDCLASS的hbrBackground则决定了fErase值。

好像就是这样了??!!

ed9er 2001-03-10
  • 打赏
  • 举报
回复
我决定还是相信MSDN,就是说fErase的值只和wndclass的hbrBackground有关系,和InvalidateRect的最后一个参数没关系,Windows假定你知道自己在干什么,你既然把最后那个参数设为FALSE了,就说明你自己会去擦背景了,fErase只当hbr为NULL的时候为TRUE

呵呵,是不是就酱紫?我给分了哦?
2000 2001-03-09
  • 打赏
  • 举报
回复
别急着怀疑,在对话框建立之后把背景画刷设置为NULL(setclasslong),再试试看。
招RD和QA 2001-03-09
  • 打赏
  • 举报
回复
也就是说,不管InvalidateRect()的最后一个参数设为TRUE or FALSE,结果ps.fErase总是FALSE,:-),真TMD的奇怪。

通常我不会怀疑一本经典巨著的权威性,由于我使用的是pw2k server,所以我怀疑更可能是操作系统的问题。
招RD和QA 2001-03-09
  • 打赏
  • 举报
回复
你也把我弄糊涂了。

........
case WM_PAINT:
OutputDebugString( "WM_PAINT\r\n" );

HDC hdc;
hdc = BeginPaint(hWnd, &ps);

RECT rt;
GetClientRect(hWnd, &rt);
if( ps.fErase )
DrawText(hdc, szHello, strlen(szHello), &rt, DT_LEFT);
EndPaint(hWnd, &ps);

OutputDebugString( "WM_PAINT End\r\n" );
break;
case WM_LBUTTONDOWN:
RECT rtInvalid;
rtInvalid.left = rtInvalid.top = 0;
rtInvalid.right = rtInvalid.bottom = 100;

InvalidateRect( hWnd, &rtInvalid, TRUE );
OutputDebugString( "WM_LBUTTONDOWN\r\n" );
break;
case WM_ERASEBKGND:
OutputDebugString( "WM_ERASEBKGND\r\n" );
return DefWindowProc(hWnd, message, wParam, lParam);
....

我在InalidateRect()把最后一个参数设为TRUE, ps.fErase也是FALSE,why??

MSDN解释如下。

fErase
Specifies whether the background must be erased. This value is nonzero
if the application should erase the background. The application is
responsible for erasing the background if a window class is created
without a background brush. For more information, see the description
of the hbrBackground member of the WNDCLASS structure.

???????????????????????????????????
ed9er 2001-03-09
  • 打赏
  • 举报
回复
应该是Petzold错了
http://www.gamedev.net/community/forums/topic.asp?topic_id=42135
ed9er 2001-03-09
  • 打赏
  • 举报
回复
设了,不管我怎么折腾那个窗口,这句都走不到
我已经开始怀疑Petzold了……
2000 2001-03-09
  • 打赏
  • 举报
回复
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
if (ps.fErase)
TextOut(hdc, 10, 10, "b", 1);//在这里设一个断点,看看什么情况下调用。
EndPaint(hwnd, &ps);
return 0;
ed9er 2001-03-09
  • 打赏
  • 举报
回复
越来越糊涂,我稍微改了一下:

case WM_LBUTTONDOWN:
hdc = GetDC(hwnd);
TextOut(hdc, 10, 50, "a", 1);
ReleaseDC(hwnd, hdc);
InvalidateRect(hwnd, NULL, FALSE);
return 0;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
if (ps.fErase)
TextOut(hdc, 10, 10, "b", 1);
EndPaint(hwnd, &ps);
return 0;
还有一个WM_DESTROY,其他消息全部是DefWindowProc

单击以后有a没b,应该说明了invalidate引起的那次WM_PAINT里的BeginPaint没有删背景,也就是没send那个删背景的消息,(只要拖动窗口,a就没了),但为什么ps.fErase还是FALSE?天哪,我彻底晕了,究竟应该相信谁?是我哪一步做错了?
ed9er 2001-03-08
  • 打赏
  • 举报
回复
在第四章第二节:An Introduction to GDI,复制一段,查找就有了
我上面想错了,是,beginpaint里面是有send那个消息,回来以后ps.fErase应该是FALSE,不过……难道Petzold错了吗?
2000 2001-03-08
  • 打赏
  • 举报
回复
However, if your program invalidates a rectangle of the client area by calling InvalidateRect, the last argument of the function specifies whether you want the background erased. If this argument is FALSE (that is, 0), Windows will not erase the background and the fErase field of the PAINTSTRUCT structure will be TRUE (nonzero) after you call BeginPaint.

这段在哪儿?我没找到。
你的方法本身很成问题,“重画”可以由多种原因引起,而且在beginpaint的时候又可能会传送(send)WM_ERASEBKGND消息,复杂啊!
具体到由InvalidateRect(hwnd, NULL, FALSE)引发的WM_PAINT,我认为ps.fErase应该是FALSE,这可以从ps.fErase的解释中推测到。
ed9er 2001-03-08
  • 打赏
  • 举报
回复
刚才即将下班,急火攻心,口气不好,见谅

我觉得可能是petzold没讲清楚,使我漏了什么步骤
ed9er 2001-03-08
  • 打赏
  • 举报
回复
呵呵,看来你比我还不如

MSDN :

bErase
[in] Specifies whether the background within the update region is to be erased when the update region is processed. If this parameter is TRUE, the background is erased when the BeginPaint function is called. If this parameter is FALSE, the background remains unchanged.

fErase
Specifies whether the background must be erased. This value is nonzero if the application should erase the background. The application is responsible for erasing the background if a window class is created without a background brush. For more information, see the description of the hbrBackground member of the WNDCLASS structure.

Petzold:

However, if your program invalidates a rectangle of the client area by calling InvalidateRect, the last argument of the function specifies whether you want the background erased. If this argument is FALSE (that is, 0), Windows will not erase the background and the fErase field of the PAINTSTRUCT structure will be TRUE (nonzero) after you call BeginPaint.

另外,如果不处理WM_ERASEBKGND的话,擦除背景会发生在BeginPaint里

明明是我提问题我给分……怎么变成我在这跟别人说明问题了?:)
gamedragon 2001-03-08
  • 打赏
  • 举报
回复
如果你调用InvalidateRect(hwnd, NULL, FALSE),就是说不擦除背景,那么ps.fErase就是FALSE,怎么会调用你的TextOut呢?
而且擦背景是发送WM_ERASEBKGND消息时实现的,不是在WM_PAINT里实现的。不信你截获这个消息画幅图上去试试。

16,548

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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