source: trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/Application.ab@ 575

Last change on this file since 575 was 575, checked in by イグトランス (egtra), 16 years ago

ウィンドウ作成関数を親用のCreateFormと子用のCreateに分離。

File size: 2.4 KB
Line 
1'Classes/ActiveBasic/Windows/UI/Application.ab
2
3#require <Classes/ActiveBasic/Windows/UI/Form.ab>
4
5Namespace ActiveBasic
6Namespace Windows
7Namespace UI
8
9Delegate Function MessageFilter(m As *MSG) As Boolean
10
11/*!
12@date 2008/07/13
13@brief アプリケーション全体に関わるようなこと……、主にメッセージループを管理するクラス。
14@todo メッセージフィルタとマルチスレッド対応
15@author Egtra
16*/
17Class Application
18Public
19 /*!
20 @brief メッセージループを回す
21 @date 2008/07/13
22 @param[in] form メインウィンドウ
23 @author Egtra
24 */
25 Static Sub Run(form As Form)
26 If IsNothing(form) = False Then
27 form.Show(SW_SHOW)
28 form.Update()
29 form.AddMessageEvent(WM_DESTROY, AddressOf(OnMainFormClosed))
30 End If
31
32 Dim m As MSG
33 Do
34 Dim ret = GetMessage(m, 0, 0, 0)
35 If ret = 0 Or ret = -1 Then
36 Exit Do
37 End If
38 dispatchMessage(m)
39 Loop
40
41 End Sub
42
43 /*!
44 @brief メインウィンドウなしでメッセージループを回す
45 @date 2008/07/13
46 @author Egtra
47 */
48 Static Sub Run()
49 Run(Nothing)
50 End Sub
51
52 /*!
53 @brief メッセージループを終わらせる。
54 @date 2008/07/13
55 @author Egtra
56 */
57 Static Sub ExitThread()
58 PostQuitMessage(0)
59 End Sub
60
61 /*!
62 @brief メッセージキューに溜まったメッセージを処理する。
63 @date 2008/07/18
64 @author Egtra
65 ここのコードから改変。
66 http://www.activebasic.com/forum/viewtopic.php?t=426
67 */
68 Static Sub DoEvents()
69 Dim msg As MSG
70 While PeekMessage(msg, 0, 0, 0, PM_REMOVE) <> FALSE
71 Select Case msg.message
72 Case WM_QUIT
73 PostQuitMessage(0) 'Run()で捕まえてくれるようPostしなおす。
74 Case Else
75 dispatchMessage(msg)
76 End Select
77 Wend
78 End Sub
79/*
80 Static Sub AddMessageFilter(mf As MessageFilter)
81 If IsNothing(filter) Then
82 filter = New System.Collections.Generic.List<MessageFilter>
83 End If
84 filter.Add(mf)
85 End Sub
86
87 Static Sub RemoveMessageFilter(mf As MessageFilter)
88 filter.Remove(mf)
89 End Sub
90*/
91#include "ApplicationEvent.sbp"
92
93Private
94 Static Sub OnMainFormClosed(sender As Object, e As Args)
95 OnThreadExit(Args.Empty)
96 ExitThread()
97 End Sub
98
99 Static Sub dispatchMessage(ByRef m As MSG)
100/* If IsNothing(filter) = False Then
101 For Each f In filter
102 Next
103 End If
104*/ TranslateMessage(m)
105 DispatchMessage(m)
106 End Sub
107
108' Static filter As System.Collections.Generic.List<MessageFilter>
109End Class
110
111End Namespace 'UI
112End Namespace 'Widnows
113End Namespace 'ActiveBasic
Note: See TracBrowser for help on using the repository browser.