peekmessage的问题

wzjall 2009-04-13 08:53:49
我用peekmessage 写了个函数来peek mouseup消息,但不知道为什么有时候会peek不到mouseup消息呢(只有一个客户的机器有这个问题,其他客户的机器是没这个问题的)

但实际上消息队列里面是肯定有mouseup消息的,因为我不调用peekmessage 的时候,我是能接收到mouseup消息的。

大家有遇到这种问题吗?
...全文
236 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
wzjall 2009-10-02
  • 打赏
  • 举报
回复
看来差不多要揭贴了
wzjall 2009-09-25
  • 打赏
  • 举报
回复
handle 肯定是对的,我的程序是在很多机器上跑的,只有一个机器有这个问题
nick_TS16949 2009-04-21
  • 打赏
  • 举报
回复
看下MSDN上关于PEEKMESSAGE的说明:

PeekMessage retrieves only messages associated with the window identified by the hWnd parameter or any of its children as specified by the IsChild function, and within the range of message values given by the wMsgFilterMin and wMsgFilterMax parameters. If hWnd is NULL, PeekMessage retrieves messages for any window that belongs to the current thread making the call. (PeekMessage does not retrieve messages for windows that belong to other threads.) If hWnd is –1, PeekMessage only returns messages with a hWnd value of NULL, as posted by the PostThreadMessage function. If wMsgFilterMin and wMsgFilterMax are both zero, PeekMessage returns all available messages (that is, no range filtering is performed).

The WM_KEYFIRST and WM_KEYLAST constants can be used as filter values to retrieve all keyboard messages; the WM_MOUSEFIRST and WM_MOUSELAST constants can be used to retrieve all mouse messages.

The PeekMessage function does not remove WM_PAINT messages from the queue. WM_PAINT messages remain in the queue until they are processed.

按照上面的说明做2个简单测试就可以,是不是HANDLE不对?
willflyz 2009-04-18
  • 打赏
  • 举报
回复
在窗体回调函数里面直接捕捉你要的消息,这种方式应该是最快的
wzjall 2009-04-18
  • 打赏
  • 举报
回复
上面的做法对于做滑块是可以,但是我写的这个函数还需要用来移动地图,要平滑的移动,因此要检测 mousemove
yihan7h 2009-04-15
  • 打赏
  • 举报
回复
你的意图是?父窗体在子控件上mouseup时do something?
如果是这样,可以自定义消息,在子控件的LBUTTONUP里头postmessage至父窗体
yihan7h 2009-04-15
  • 打赏
  • 举报
回复
while(!m_bIsup)
{
.......//滑动
}

LbuttonUp()
{
m_bIsup = true;
}
wzjall 2009-04-15
  • 打赏
  • 举报
回复
我是要做下拉滑块的效果,按下的时候,开始滑动,直到又up消息。
是在一个线程里面做的
beyondma 2009-04-14
  • 打赏
  • 举报
回复
这个真是很奇怪。不过你一以看一下那个WTL,一般预处理消息都不这么写了。pm_remove这个好像用的也不对。
xqhrs232 2009-04-14
  • 打赏
  • 举报
回复
peekmessage(hwnd,&msg,0,0,pm_remove);


是不是把这个消息从消息队列里面移走了?
morris88 2009-04-14
  • 打赏
  • 举报
回复
如何正确的使用PeekMessage()


HOWTO: How to Use PeekMessage() Correctly in Windows
SUMMARY
In the Windows environment, many applications use a PeekMessage() loop to perform background processing. Such applications must allow the Windows system to enter an idle state when their background processing is complete. Otherwise, system performance, "idle-time" system processes such as paging optimizations, and power management on battery-powered systems will be adversely affected.

While an application is in a PeekMessage() loop, the Windows system cannot go idle. Therefore, an application should not remain in a PeekMessage() loop after its background processing has completed.

NOTE: The PeekMessage method described in this article is only needed if your application is a 32-bit application for Windows and is, for some reason, unable to create threads and perform background processing.

MORE INFORMATION

Many Windows-based applications use PeekMessage() to retrieve messages while they are in the middle of a long process, such as printing, repaginating, or recalculating, that must be done "in the background." PeekMessage() is used in these situations because, unlike GetMessage(), it does not wait for a message to be placed in the queue before it returns.

An application should not call PeekMessage() unless it has background processing to do between the calls to PeekMessage(). When an application is waiting for an input event, it should call GetMessage() or WaitMessage().

Remaining in a PeekMessage() loop when there is no background work causes system performance problems. A program in a PeekMessage() loop continues to be rescheduled by the Windows scheduler, consuming CPU time and taking time away from other processes.

In enhanced mode, the Virtual Machine (VM) in which Windows is running will not appear to be idle as long as an application is calling the PeekMessage function. Therefore, the Windows VM will continue to receive a considerable fraction of CPU time.

Many power management methods employed on laptop and notebook computers are based on the system going idle when there is no processing to do. An application that remains in a PeekMessage() loop will make the system appear busy to power management software, resulting in excessive power consumption and shortening the time that the user can run the system.

In the future, the Windows system will make more and more use of idle time to do background processing, which is designed to optimize system performance. Applications that do not allow the system to go idle will adversely affect the performance of these techniques.

All these problems can be avoided by calling the PeekMessage() function only when there is background work to do, and calling GetMessage() or WaitMessage() when there is no background work to do.

For example, consider the following PeekMessage() loop. If there is no background processing to do, this loop will continue to run without waiting for messages, preventing the system from going idle and causing the negative effects described above.

// This PeekMessage loop will NOT let the system go idle.
for( ;; )
{
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
return TRUE;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
BackgroundProcessing();
}

This loop can be rewritten in two ways, as shown below. Both of the following PeekMessage() loops have two desirable properties:


• They process all input messages before performing background processing, providing good response to user input.
• The application "idles" (waits for an input message) when no background processing needs to be done.
morris88 2009-04-14
  • 打赏
  • 举报
回复
再创建一个子线程,你可以仔细考虑一下到底用主线程,还是子线程来等待...
wzjall 2009-04-14
  • 打赏
  • 举报
回复
还有其他办法可以比较流畅的拿到mouseup消息吗?
wzjall 2009-04-14
  • 打赏
  • 举报
回复
我用getmessage 是可以拿到mouseup消息的,但因为这个函数是等待的,这样我的程序就会不够流畅,大家还有好的办法吗?
wzjall 2009-04-13
  • 打赏
  • 举报
回复
是的,这只是大概代码
huabinsir 2009-04-13
  • 打赏
  • 举报
回复
消息是不是要转换一下.
wzjall 2009-04-13
  • 打赏
  • 举报
回复
peek ()
{
while(1)
{
peekmessage(hwnd,&msg,0,0,pm_remove);

if(msg.message==mousemove)
{
return 1;
}

if(msg.message==mouseup)
{
return 0;
}
}
代码就类似上面的,peek 函数是 在 mousedown 里面调用的 、
morris88 2009-04-13
  • 打赏
  • 举报
回复
那你的代码是怎么写的,贴出来大家看看,貌似才好分析问题...

19,502

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 嵌入开发(WinCE)
社区管理员
  • 嵌入开发(WinCE)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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