我正在开发一款Windows Visual C++应用程序,该程序将监视消息泵以便检测各种事件。以下是我的主cpp文件的框架:
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nCmdShow) {
HWND hwnd;
WNDCLASSEX wincl;
// register WindowProcedure() as message callback function
wincl.lpfnWndProc = WindowProcedure;
// assign other properties...
if (!RegisterClassEx (&wincl))
return 0;
// create main window
hwnd = CreateWindowEx ( ... );
// infinite message loop
while (GetMessage (&messages, NULL, 0, 0)) {
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return 0;
}
以下是回调函数的框架:
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
switch(message) {
case WM_CLIPBOARDUPDATE:
// handle the update here
}
}
我的简单问题是回调函数是否保证按照顺序开始和结束,或者它们可能会与一些重叠的并行执行?换句话说,两个对回调函数的调用是否可能并行执行,可能导致竞争条件?或者Windows是否保证每条消息按照串行方式处理,一次处理一个?欢迎提供任何文档或参考资料。