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

关于消息队列解决方法

2013-11-21 
关于消息队列opengl里有个PeekMessage函数是从消息队列中获取消息,那么怎么确定某个语句表达的信息是不是

关于消息队列
opengl里有个PeekMessage函数是从消息队列中获取消息,那么怎么确定某个语句表达的信息是不是进入了消息队列? opengl
[解决办法]

引用:
我想表达的大致就是这个问题。比如有个关于旋转的代码,
PeekMessage(&msg,hwnd,NULL,NULL,PM_REMOVE);//是否待处理消息

if(msg.message == WM_QUIT)//如果收到一个退出消息
{
done = true;
}

else
{
glClear(GL_COLOR_BUFFER_BIT 
[解决办法]
 GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

angle += 0.1f;
if(angle >= 360.0f)
angle = 0.0f;
glTranslatef(0.0f,0.0f,-5.0f);
glRotatef(angle,0.0f,0.0f,1.0f);

glColor3f(1.0f,0.0f,0.0f);
glBegin(GL_TRIANGLES);
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(1.0f,0.0f,0.0f);
glVertex3f(1.0f,1.0f,0.0f);
glEnd();

SwapBuffers(g_HDC);

//将虚拟消息翻译成字符消息并放入消息队列中预留PeekMessage()读取
TranslateMessage(&msg);
//将其参数所指定的消息分发回系统并被处理
DispatchMessage(&msg);
这个为什么会循环执行angle += 0.1f;也就是说为什么会一直实现旋转?这条语句作为信息进入了消息阵列吗


据我对LZ意图的理解,LZ要做以下几件事,才可能达到LZ想要的效果。罗列如下:
1. 修改消息循环逻辑
while(TRUE)
{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if (msg.message == WM_QUIT)
{
break;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}


2. 自定义窗口消息 WM_USER 。譬如定义消息
#define WM_ROTATE (WM_USER + 0)
然后调用 SendMessage() 或者 PostMessage() 将消息置于消息队列。

3. 将消息处理代码从消息循环逻辑里面移到消息回调函数里面,大概如下:
xxx MessageProcessCallBack(...)
{
    if (WM_ROTATE消息)
    {
        /* 旋转视图 */
    }
}

[解决办法]
使用Spy++软件。

或者:
Setting a Breakpoint on a Message Received by a Windows Function
You can set message breakpoints to stop the debugger when a particular WndProc function message is received.
Note   Message breakpoints work only on x86- or Pentium-based systems.
To set a breakpoint on a message 
1.From the Edit menu, click Breakpoints. 
The Breakpoints dialog box appears.
2.Click the Messages tab.
3.In the Break At WndProc text box, type the name of the Windows function. 
If you are setting a breakpoint during a debug session, the list contains the exported functions in your project. 
4.In the Set One Breakpoint For Each Message To Watch list box, select the message.
5.To set another breakpoint, press ENTER, and then repeat steps 3 and 4. 
The Breakpoints list displays the currently active breakpoints.
6.Click OK to set the breakpoints. 
Note If you interrupt execution while Windows or other system code is running, the results can be unpredictable.

热点排行