求助:消息、消息...windows消息及BCB对其的处理 - C++ Builder / Windows SDK/API
最近,被windows消息搞的很头疼,希望各位大哥能耐心看完,并指导指导。
1、先说说Application->OnMessage 与消息映射MESSAGE_MAP,我在同一个窗口程序中,用Application->OnMessage和消息映射,对系统屏保消息SC_SCREENSAVE进行捕获,结果,Application->OnMessage比MESSAGE_MAP更快堆消息进行了响应。这么说,Application->OnMessage是不是比MESSAGE_MAP更快一步捕获到消息?
2、由于我写的程序用到OpenCV,在某个按钮事件中,有个视频捕获循序,调用到函数cvWaitKey(),搞的我很头疼(个人认为是这样东西引起的),他搞到Application->OnMessage失效了,完全捕获不到系统消息。(VC中的preTranslateMessage也同样没用了),但我用MESSAGE_MAP对系统消息进行处理,却有了反应...我就奇怪了..OnMessage不是比MESSAGE_MAP更快么?
网上说cvWaitKey()原型如下,(没源码可跟踪)
CV_IMPL intcvWaitKey( int delay ){ int time0 = GetTickCount(); for(;;) { CvWindow* window; MSG message; int is_processed = 0; if( (delay > 0 && abs((int)(GetTickCount() - time0)) >= delay) || hg_windows == 0 ) return -1; if( delay <= 0 ) GetMessage(&message, 0, 0, 0); else if( PeekMessage(&message, 0, 0, 0, PM_REMOVE) == FALSE ) { Sleep(1); continue; } for( window = hg_windows; window != 0 && is_processed == 0; window = window->next ) { if( window->hwnd == message.hwnd || window->frame == message.hwnd ) { is_processed = 1; switch(message.message) { case WM_DESTROY: case WM_CHAR: DispatchMessage(&message); return (int)message.wParam; case WM_KEYDOWN: TranslateMessage(&message); default: DispatchMessage(&message); is_processed = 1; break; } } } if( !is_processed ) { TranslateMessage(&message); DispatchMessage(&message); } }}