首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

win32 api 消息处理咨询,该怎么处理

2012-12-22 
win32 api 消息处理咨询static int num0.........case WM_TIMER:num+10SendMessage(hwnd,WM_PAINT,NUL

win32 api 消息处理咨询
static int num=0;
.........

case WM_TIMER:
num+=10;
SendMessage(hwnd,WM_PAINT,NULL,NULL);
return 0;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
GetClientRect(hwnd,&rect);
TextOut(hdc,0,num,TEXT("======"),6);
EndPaint(hwnd,&ps);
return 0;
这代码设置一个定时器,每次num+10;
然后更新TEXT位置,为什么无法实现?
num确实在增加,但是窗口就是不更新;
只有改变窗口大小的时候才会更新
[最优解释]
这3行代码其实没有用:
SendMessage(hwnd,WM_PAINT,NULL,NULL);
return 0;
case WM_PAINT:
这个函数最好把rect算出来更新,重绘整个窗口比较耗CPU,程序员一定要随时想着节省资源!
InvalidateRect(hwnd,NULL,TRUE);
[其他解释]

引用:
已经懂了,
我理解是如果客户区全部有效,那么WM_PAINT就不进行重绘(严格来说..是不是这样???);
所以WM_TIMER最后加上InvalidateRect(hwnd,NULL,TRUE);宣布窗口无效才可以;


http://msdn.microsoft.com/en-us/library/windows/desktop/dd145213(v=vs.85).aspx
The WM_PAINT message is generated by the system and should not be sent by an application. 
[其他解释]
已经懂了,
我理解是如果客户区全部有效,那么WM_PAINT就不进行重绘(严格来说..是不是这样???);
所以WM_TIMER最后加上InvalidateRect(hwnd,NULL,TRUE);宣布窗口无效才可以;

[其他解释]
SendMessage(hwnd,WM_PAINT,NULL,NULL);也就没用了,删了
[其他解释]
嗯,谢谢,刚开始学,很多都不懂,不过,那个TIMER的return一点都没用吗?
引用:
这3行代码其实没有用:
SendMessage(hwnd,WM_PAINT,NULL,NULL);
return 0;
case WM_PAINT:
这个函数最好把rect算出来更新,重绘整个窗口比较耗CPU,程序员一定要随时想着节省资源!
InvalidateRect(hwnd,NULL,TRUE);

[其他解释]
引用:
引用:已经懂了,
我理解是如果客户区全部有效,那么WM_PAINT就不进行重绘(严格来说..是不是这样???);
所以WM_TIMER最后加上InvalidateRect(hwnd,NULL,TRUE);宣布窗口无效才可以;

http://msdn.microsoft.com/en-us/library/windows/de……

3q,这句话我深深的记住了;
[其他解释]
引用:
static int num=0;
.........

case WM_TIMER:
num+=10;
SendMessage(hwnd,WM_PAINT,NULL,NULL);
return 0;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
GetClientRect(hwnd,&rect);
……

你发送信息的时候,有一个代刷新的窗口无效区域,如果你直接发送,这个区域不存在,所以刷新就无效。
你只要使用InvalidateRect函数,你指定的区域就会自动无效,windows就会指定发送重绘信息,前提是,函数的最后一个参数要为TRUE,告诉windows将无效区域进行重绘。

[其他解释]
引用:
引用:static int num=0;
.........

case WM_TIMER:
num+=10;
SendMessage(hwnd,WM_PAINT,NULL,NULL);
return 0;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
GetClie……

谢谢,不过我看的资料是说InvalidateRect最后一个参数是是否擦除原数据.不是是否重绘的;
[其他解释]
查MSDN是Windows程序员必须掌握的技能之一。
英语也是一门计算机语言的说。

InvalidateRect
The InvalidateRect function adds a rectangle to the specified window's update region. The update region represents the portion of the window's client area that must be redrawn. 



BOOL InvalidateRect(
  HWND hWnd,  // handle of window with changed update region
  CONST RECT *lpRect,
              // address of rectangle coordinates
  BOOL bErase // erase-background flag
);
 
Parameters
hWnd 
Handle to the window whose update region has changed. If this parameter is NULL, the system invalidates and redraws all windows, and sends theWM_ERASEBKGND and WM_NCPAINT messages to the window procedure before the function returns. 
lpRect 
Pointer to a RECT structure that contains the client coordinates of the rectangle to be added to the update region. If this parameter is NULL, the entire client area is added to the update region. 
bErase 
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. 
Return Values
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. 

Windows NT: To get extended error information, callGetLastError.

Remarks
The invalidated areas accumulate in the update region until the region is processed when the next WM_PAINT message occurs or until the region is validated by using the ValidateRect or ValidateRgn function. 

The system sends a WM_PAINT message to a window whenever its update region is not empty and there are no other messages in the application queue for that window. 

If the bErase parameter is TRUE for any part of the update region, the background is erased in the entire region, not just in the given part. 


[其他解释]

引用:
引用:引用:static int num=0;
.........

case WM_TIMER:
num+=10;
SendMessage(hwnd,WM_PAINT,NULL,NULL);
return 0;
case WM_PAINT:
hdc=BeginPaint(hwnd,……

说的对,最后的参数是是否擦除源数据,一旦这个地方指定TRUE,更新区域的背景就会清除重新绘制,但一般情况下,通过WM_PAINT刷新的窗口都是整个区域重绘。
[其他解释]
该回复于2012-12-08 09:42:07被管理员删除
[其他解释]
case WM_TIMER:
 num+=10;
InvalidateRect(指定区域)

热点排行