Created
April 10, 2014 07:59
-
-
Save wyyqyl/10353869 to your computer and use it in GitHub Desktop.
Integrate boost::thread with Windows MSG
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <windows.h> | |
| #include <boost/thread/thread.hpp> | |
| LRESULT MsgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { | |
| LRESULT result = 0; | |
| switch (message) { | |
| case WM_TIMER: | |
| std::cout << "WM_TIMER" << std::endl; | |
| result = 1; | |
| break; | |
| default: | |
| break; | |
| } | |
| return result; | |
| } | |
| void ThreadFunc() { | |
| MSG msg; | |
| SetTimer(0, 0, 1000, 0); | |
| while (GetMessage(&msg, 0, 0, 0)) { | |
| MsgProc(msg.hwnd, msg.message, msg.wParam, msg.lParam); | |
| } | |
| } | |
| int main() { | |
| boost::thread t(ThreadFunc); | |
| DWORD id = GetThreadId(t.native_handle()); | |
| boost::this_thread::sleep(boost::posix_time::millisec(6000)); | |
| PostThreadMessage(id, WM_QUIT, 0, 0); | |
| t.join(); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment