OSDN Git Service

基本ファイルを追加
[winaudioj/sfwasapi.git] / sfwasapi / message_loop.h
1 #pragma once
2 /*
3   ==============================================================================
4
5    This file is part of the S.F.Tracker
6    Copyright 2005-7 by Satoshi Fujiwara.
7
8    S.F.Tracker can be redistributed and/or modified under the terms of the
9    GNU General Public License, as published by the Free Software Foundation;
10    either version 2 of the License, or (at your option) any later version.
11
12    S.F.Tracker is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with S.F.Tracker; if not, visit www.gnu.org/licenses or write to the
19    Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
20    Boston, MA 02111-1307 USA
21
22   ==============================================================================
23 */
24 /** @file
25  *  @brief 
26  *  @author S.F. (Satoshi Fujiwara)
27  */
28 namespace sf {
29         struct run_message_loop
30         {
31                 run_message_loop(){};
32                 inline WPARAM operator()()
33                 {
34                         MSG msg;
35                         while (GetMessage(&msg, NULL, 0, 0))
36                         {
37                                 TranslateMessage(&msg);
38                                 DispatchMessage(&msg);
39                         }
40       return msg.wParam;
41                 }
42
43                 ~run_message_loop(void){};
44         };
45
46         struct peek_message_loop
47         {
48                 typedef boost::function<void ()> func_type;
49                 explicit peek_message_loop(func_type func)  {func_ =  func;};
50                 inline WPARAM operator()()
51                 {
52                         MSG msg = {0};
53                         while( WM_QUIT != msg.message )
54                         {
55                                 if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
56                                 {
57                                         TranslateMessage( &msg );
58                                         DispatchMessage( &msg );
59                                 }
60                                 else
61                                 {
62                                         func_();  // Do some rendering
63                                 }
64                         }
65       return msg.wParam;
66                 };
67         private:
68                 func_type func_;
69         };
70 }