ffi-wingui-core 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,33 +1,31 @@
1
1
  require 'ffi-wingui-core'
2
-
3
- exit if defined?(Ocra)
2
+ require 'ffi-wingui-core/ocra'
4
3
 
5
4
  include WinGUI
6
5
 
7
- APPNAME = L(File.basename(__FILE__, '.rbw'))
8
-
9
- CMD_ITEM1 = WM_APP + 1
10
- CTL_FOCUS = CMD_ITEM1 + 1
11
- CTL_BUTTON1 = CTL_FOCUS + 1
12
-
13
6
  WndExtra = Struct.new(
14
7
  :haccel,
15
8
  :hmf
16
- ).send(:include, Util::Id2RefTracking)
9
+ )
17
10
 
18
11
  def onCreate(hwnd,
19
12
  cs
20
13
  )
21
- xtra = WndExtra::REFS[GetWindowLong(hwnd, GWL_USERDATA)]
14
+ xtra = Util::Id2Ref[GetWindowLong(hwnd, GWL_USERDATA)]
15
+
16
+ hsys = GetSystemMenu(hwnd, 0)
17
+ InsertMenu(hsys, SC_CLOSE, MF_STRING, SYSID[:ITEM1], L("Item&1\tAlt+S"))
18
+ InsertMenu(hsys, SC_CLOSE, MF_SEPARATOR, 0, nil)
22
19
 
23
20
  hbar = CreateMenu()
24
21
  hmenu1 = CreatePopupMenu()
25
- AppendMenu(hmenu1, MF_STRING, CMD_ITEM1, L("Item&1\tAlt+I"))
26
- AppendMenu(hbar, MF_POPUP, hmenu1.to_i, L('Menu&1'))
22
+ InsertMenu(hmenu1, -1, MF_STRING, ID[:ITEM1], L("Item&1\tAlt+I"))
23
+ InsertMenu(hbar, -1, MF_POPUP, hmenu1.to_i, L('Menu&1'))
27
24
  SetMenu(hwnd, hbar)
28
25
 
29
26
  accels = [
30
- [FVIRTKEY | FALT, 'I'.ord, CMD_ITEM1]
27
+ [FVIRTKEY | FALT, 'S'.ord, SYSID[:ITEM1]],
28
+ [FVIRTKEY | FALT, 'I'.ord, ID[:ITEM1]]
31
29
  ]
32
30
 
33
31
  FFI::MemoryPointer.new(ACCEL, accels.count) { |paccels|
@@ -51,7 +49,7 @@ def onCreate(hwnd,
51
49
  0, L('Button'), L('&Button1'), WS_CHILD | WS_CLIPSIBLINGS |
52
50
  WS_VISIBLE | WS_TABSTOP,
53
51
  *DPIAwareXY(10, 10, 100, 25),
54
- hwnd, FFI::Pointer.new(CTL_BUTTON1), GetModuleHandle(nil), nil
52
+ hwnd, FFI::Pointer.new(ID[:BUTTON1]), GetModuleHandle(nil), nil
55
53
  )
56
54
 
57
55
  SendMessage(hbtn1, WM_SETFONT, xtra[:hmf].to_i, 1)
@@ -59,14 +57,14 @@ def onCreate(hwnd,
59
57
  CreateWindowEx(
60
58
  0, L('Static'), L(''), WS_CHILD | WS_CLIPSIBLINGS,
61
59
  0, 0, 0, 0,
62
- hwnd, FFI::Pointer.new(CTL_FOCUS), GetModuleHandle(nil), nil
60
+ hwnd, FFI::Pointer.new(ID[:FOCUS]), GetModuleHandle(nil), nil
63
61
  )
64
62
 
65
63
  0
66
64
  end
67
65
 
68
66
  def onDestroy(hwnd)
69
- xtra = WndExtra::REFS[GetWindowLong(hwnd, GWL_USERDATA)]
67
+ xtra = Util::Id2Ref[GetWindowLong(hwnd, GWL_USERDATA)]
70
68
 
71
69
  DestroyAcceleratorTable(xtra[:haccel])
72
70
  DeleteObject(xtra[:hmf])
@@ -78,7 +76,19 @@ def onActivate(hwnd,
78
76
  state, minimized,
79
77
  hother
80
78
  )
81
- SetFocus(GetDlgItem(hwnd, CTL_FOCUS)) if state != WA_INACTIVE
79
+ SetFocus(GetDlgItem(hwnd, ID[:FOCUS])) if state != WA_INACTIVE
80
+
81
+ 0
82
+ end
83
+
84
+ def onSysItem1(lParam,
85
+ hwnd
86
+ )
87
+ MessageBox(hwnd,
88
+ L(__method__.to_s),
89
+ APPNAME,
90
+ MB_ICONINFORMATION
91
+ )
82
92
 
83
93
  0
84
94
  end
@@ -101,8 +111,8 @@ def onItem1(verb,
101
111
  raise 'WM_COMMAND hctl must be NULL for menu/accelerator' unless
102
112
  hctl.null?
103
113
 
104
- EnableWindow(GetDlgItem(hwnd, CTL_BUTTON1), 1)
105
- EnableMenuItem(GetMenu(hwnd), CMD_ITEM1, MF_GRAYED)
114
+ EnableWindow(GetDlgItem(hwnd, ID[:BUTTON1]), 1)
115
+ EnableMenuItem(GetMenu(hwnd), ID[:ITEM1], MF_GRAYED)
106
116
 
107
117
  0
108
118
  end
@@ -124,7 +134,7 @@ def onButton1(verb,
124
134
  raise 'WM_COMMAND hctl must NOT be NULL for control' if
125
135
  hctl.null?
126
136
 
127
- EnableMenuItem(GetMenu(hwnd), CMD_ITEM1, MF_ENABLED)
137
+ EnableMenuItem(GetMenu(hwnd), ID[:ITEM1], MF_ENABLED)
128
138
  EnableWindow(hctl, 0)
129
139
 
130
140
  0
@@ -156,19 +166,28 @@ begin
156
166
  FFI::Pointer.new(lParam)
157
167
  )
158
168
 
169
+ when WM_SYSCOMMAND
170
+ id = wParam & 0xfff0
171
+
172
+ case id
173
+ when SYSID[:ITEM1]
174
+ onSysItem1(lParam, hwnd)
175
+ end
159
176
  when WM_COMMAND
160
177
  id, verb = LOWORD(wParam), HIWORD(wParam)
161
178
  hctl = FFI::Pointer.new(lParam)
162
179
 
163
180
  case id
164
- when CMD_ITEM1
181
+ when ID[:ITEM1]
165
182
  onItem1(verb, hctl, hwnd)
166
- when CTL_BUTTON1
183
+ when ID[:BUTTON1]
167
184
  onButton1(verb, hctl, hwnd)
168
185
  end
169
186
  end
170
187
 
171
188
  result || DefWindowProc(hwnd, uMsg, wParam, lParam)
189
+ rescue SystemExit => ex
190
+ PostQuitMessage(ex.status)
172
191
  rescue
173
192
  case MessageBox(hwnd,
174
193
  L(Util.FormatException($!)),
@@ -184,7 +203,7 @@ end
184
203
  }
185
204
 
186
205
  def main
187
- xtra = WndExtra.new
206
+ Util.Id2RefTrack(xtra = WndExtra.new)
188
207
 
189
208
  WNDCLASSEX.new { |wc|
190
209
  wc[:cbSize] = wc.size
@@ -1,6 +1,5 @@
1
1
  require 'ffi-wingui-core'
2
-
3
- exit if defined?(Ocra)
2
+ require 'ffi-wingui-core/ocra'
4
3
 
5
4
  include WinGUI
6
5
 
@@ -2,8 +2,7 @@ WINGUI_VISUAL_STYLES = false
2
2
  WINGUI_DPI_AWARE = false
3
3
 
4
4
  require 'ffi-wingui-core'
5
-
6
- exit if defined?(Ocra)
5
+ require 'ffi-wingui-core/ocra'
7
6
 
8
7
  include WinGUI
9
8
 
@@ -1,21 +1,20 @@
1
1
  require 'ffi-wingui-core'
2
-
3
- exit if defined?(Ocra)
2
+ require 'ffi-wingui-core/ocra'
4
3
 
5
4
  include WinGUI
6
5
 
7
- if respond_to?(:MessageBoxTimeout)
8
- MessageBoxTimeout(nil,
9
- L("Hello, world!\n\n(Disappearing in 3 seconds...)"),
10
- L('Hello'),
11
- MB_ICONINFORMATION,
12
- 0,
13
- 3000
14
- )
15
- else
6
+ unless respond_to?(:MessageBoxTimeout)
16
7
  MessageBox(nil,
17
8
  L('MessageBoxTimeout is not supported'),
18
9
  nil,
19
10
  MB_ICONERROR
20
- )
11
+ ); exit(-1)
21
12
  end
13
+
14
+ MessageBoxTimeout(nil,
15
+ L("Hello, world!\n\n(Disappearing in 3 seconds...)"),
16
+ L('Hello'),
17
+ MB_ICONINFORMATION,
18
+ 0,
19
+ 3000
20
+ )
@@ -0,0 +1,99 @@
1
+ require 'ffi-wingui-core'
2
+ require 'ffi-wingui-core/ocra'
3
+
4
+ include WinGUI
5
+
6
+ def onCreate(hwnd,
7
+ cs
8
+ )
9
+ SetLayeredWindowAttributes(hwnd, 0, 128, LWA_ALPHA)
10
+
11
+ 0
12
+ end
13
+
14
+ def onDestroy(hwnd)
15
+ PostQuitMessage(0); 0
16
+ end
17
+
18
+ WindowProc = FFI::Function.new(:long,
19
+ [:pointer, :uint, :uint, :long],
20
+ convention: :stdcall
21
+ ) { |hwnd, uMsg, wParam, lParam|
22
+ begin
23
+ result = case uMsg
24
+ when WM_CREATE
25
+ onCreate(hwnd, CREATESTRUCT.new(FFI::Pointer.new(lParam)))
26
+ when WM_DESTROY
27
+ onDestroy(hwnd)
28
+ end
29
+
30
+ result || DefWindowProc(hwnd, uMsg, wParam, lParam)
31
+ rescue SystemExit => ex
32
+ PostQuitMessage(ex.status)
33
+ rescue
34
+ case MessageBox(hwnd,
35
+ L(Util.FormatException($!)),
36
+ APPNAME,
37
+ MB_ABORTRETRYIGNORE | MB_ICONERROR
38
+ )
39
+ when IDABORT
40
+ PostQuitMessage(2)
41
+ when IDRETRY
42
+ retry
43
+ end
44
+ end
45
+ }
46
+
47
+ def main
48
+ WNDCLASSEX.new { |wc|
49
+ wc[:cbSize] = wc.size
50
+ wc[:lpfnWndProc] = WindowProc
51
+ wc[:hInstance] = GetModuleHandle(nil)
52
+ wc[:hIcon] = LoadIcon(nil, IDI_APPLICATION)
53
+ wc[:hCursor] = LoadCursor(nil, IDC_ARROW)
54
+ wc[:hbrBackground] = FFI::Pointer.new(
55
+ ((WINVER == WINXP) ? COLOR_MENUBAR : COLOR_MENU) + 1
56
+ )
57
+
58
+ PWSTR(APPNAME) { |className|
59
+ wc[:lpszClassName] = className
60
+
61
+ DetonateLastError(0, :RegisterClassEx,
62
+ wc
63
+ )
64
+ }
65
+ }
66
+
67
+ hwnd = CreateWindowEx(
68
+ WS_EX_LAYERED, APPNAME, APPNAME, WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
69
+ CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
70
+ nil, nil, GetModuleHandle(nil), nil
71
+ )
72
+
73
+ raise "CreateWindowEx failed (last error: #{GetLastError()})" if
74
+ hwnd.null? && GetLastError() != 0
75
+
76
+ exit(0) if hwnd.null?
77
+
78
+ ShowWindow(hwnd, SW_SHOWNORMAL)
79
+ UpdateWindow(hwnd)
80
+
81
+ MSG.new { |msg|
82
+ until DetonateLastError(-1, :GetMessage,
83
+ msg, nil, 0, 0
84
+ ) == 0
85
+ TranslateMessage(msg)
86
+ DispatchMessage(msg)
87
+ end
88
+
89
+ exit(msg[:wParam])
90
+ }
91
+ rescue
92
+ MessageBox(hwnd,
93
+ L(Util.FormatException($!)),
94
+ APPNAME,
95
+ MB_ICONERROR
96
+ ); exit(1)
97
+ end
98
+
99
+ main
@@ -1,11 +1,8 @@
1
1
  require 'ffi-wingui-core'
2
-
3
- exit if defined?(Ocra)
2
+ require 'ffi-wingui-core/ocra'
4
3
 
5
4
  include WinGUI
6
5
 
7
- APPNAME = L(File.basename(__FILE__, '.rbw'))
8
-
9
6
  def onCreate(hwnd,
10
7
  cs
11
8
  )
@@ -58,6 +55,8 @@ begin
58
55
  end
59
56
 
60
57
  result || DefWindowProc(hwnd, uMsg, wParam, lParam)
58
+ rescue SystemExit => ex
59
+ PostQuitMessage(ex.status)
61
60
  rescue
62
61
  case MessageBox(hwnd,
63
62
  L(Util.FormatException($!)),
@@ -1,11 +1,8 @@
1
1
  require 'ffi-wingui-core'
2
-
3
- exit if defined?(Ocra)
2
+ require 'ffi-wingui-core/ocra'
4
3
 
5
4
  include WinGUI
6
5
 
7
- APPNAME = L(File.basename(__FILE__, '.rbw'))
8
-
9
6
  def onNCCreate(hwnd,
10
7
  cs
11
8
  )
@@ -88,6 +85,8 @@ begin
88
85
  end
89
86
 
90
87
  result || DefWindowProc(hwnd, uMsg, wParam, lParam)
88
+ rescue SystemExit => ex
89
+ PostQuitMessage(ex.status)
91
90
  rescue
92
91
  case MessageBox(hwnd,
93
92
  L(Util.FormatException($!)),
@@ -1,65 +1,52 @@
1
1
  require 'ffi-wingui-core'
2
-
3
- exit if defined?(Ocra)
2
+ require 'ffi-wingui-core/ocra'
4
3
 
5
4
  include WinGUI
6
5
 
7
- APPNAME = L(File.basename(__FILE__, '.rbw'))
8
-
9
- CMD_ITEM1 = WM_APP + 1
10
- CMD_ITEM2 = CMD_ITEM1 + 1
11
- CMD_ITEM3 = CMD_ITEM2 + 1
12
- CMD_ITEM4 = CMD_ITEM3 + 1
13
- CMD_ITEM5 = CMD_ITEM4 + 1
14
- CMD_ITEM6 = CMD_ITEM5 + 1
15
- CMD_ITEM7 = CMD_ITEM6 + 1
16
- CMD_ITEM8 = CMD_ITEM7 + 1
17
- CMD_ITEM9 = CMD_ITEM8 + 1
18
-
19
6
  WndExtra = Struct.new(
20
7
  :dummy
21
- ).send(:include, Util::Id2RefTracking)
8
+ )
22
9
 
23
10
  def onCreate(hwnd,
24
11
  cs
25
12
  )
26
- xtra = WndExtra::REFS[GetWindowLong(hwnd, GWL_USERDATA)]
13
+ xtra = Util::Id2Ref[GetWindowLong(hwnd, GWL_USERDATA)]
27
14
 
28
15
  hbar = CreateMenu()
29
16
  hmenu1 = CreatePopupMenu()
30
- AppendMenu(hmenu1, MF_STRING, CMD_ITEM1, L('Item&1'))
31
- SetMenuDefaultItem(hmenu1, CMD_ITEM1, 0)
17
+ InsertMenu(hmenu1, -1, MF_STRING, ID[:ITEM1], L('Item&1'))
18
+ SetMenuDefaultItem(hmenu1, ID[:ITEM1], 0)
32
19
 
33
- AppendMenu(hmenu1, MF_STRING | MF_GRAYED, CMD_ITEM2, L('Item&2'))
34
- AppendMenu(hmenu1, MF_STRING | MF_CHECKED, CMD_ITEM3, L('Item&3'))
20
+ InsertMenu(hmenu1, -1, MF_STRING | MF_GRAYED, ID[:ITEM2], L('Item&2'))
21
+ InsertMenu(hmenu1, -1, MF_STRING | MF_CHECKED, ID[:ITEM3], L('Item&3'))
35
22
 
36
- AppendMenu(hmenu1, MF_SEPARATOR, 0, nil)
23
+ InsertMenu(hmenu1, -1, MF_SEPARATOR, 0, nil)
37
24
 
38
- AppendMenu(hmenu1, MF_STRING | MF_CHECKED | MFT_RADIOCHECK,
39
- CMD_ITEM4, L('Item&4'))
40
- AppendMenu(hmenu1, MF_STRING, CMD_ITEM5, L('Item&5'))
25
+ InsertMenu(hmenu1, -1, MF_STRING | MF_CHECKED | MFT_RADIOCHECK,
26
+ ID[:ITEM4], L('Item&4'))
27
+ InsertMenu(hmenu1, -1, MF_STRING, ID[:ITEM5], L('Item&5'))
41
28
 
42
- AppendMenu(hmenu1, MF_SEPARATOR, 0, nil)
29
+ InsertMenu(hmenu1, -1, MF_SEPARATOR, 0, nil)
43
30
 
44
31
  hmenu2 = CreatePopupMenu()
45
- AppendMenu(hmenu2, MF_STRING | MF_CHECKED | MFT_RADIOCHECK,
46
- CMD_ITEM6, L('Item&6'))
47
- AppendMenu(hmenu2, MF_STRING, CMD_ITEM7, L('Item&7'))
48
- AppendMenu(hmenu1, MF_POPUP, hmenu2.to_i, L('Menu&2'))
49
- AppendMenu(hbar, MF_POPUP, hmenu1.to_i, L('Menu&1'))
32
+ InsertMenu(hmenu2, -1, MF_STRING | MF_CHECKED | MFT_RADIOCHECK,
33
+ ID[:ITEM6], L('Item&6'))
34
+ InsertMenu(hmenu2, -1, MF_STRING, ID[:ITEM7], L('Item&7'))
35
+ InsertMenu(hmenu1, -1, MF_POPUP, hmenu2.to_i, L('Menu&2'))
36
+ InsertMenu(hbar, -1, MF_POPUP, hmenu1.to_i, L('Menu&1'))
50
37
 
51
- AppendMenu(hbar, MF_STRING, CMD_ITEM8, L('Item&8'))
38
+ InsertMenu(hbar, -1, MF_STRING, ID[:ITEM8], L('Item&8'))
52
39
 
53
40
  hmenu3 = CreatePopupMenu()
54
- AppendMenu(hmenu3, MF_STRING, CMD_ITEM9, L('Item&9'))
55
- AppendMenu(hbar, MF_POPUP | MF_RIGHTJUSTIFY, hmenu3.to_i, L('Menu&3'))
41
+ InsertMenu(hmenu3, -1, MF_STRING, ID[:ITEM9], L('Item&9'))
42
+ InsertMenu(hbar, -1, MF_POPUP | MF_RIGHTJUSTIFY, hmenu3.to_i, L('Menu&3'))
56
43
  SetMenu(hwnd, hbar)
57
44
 
58
45
  0
59
46
  end
60
47
 
61
48
  def onDestroy(hwnd)
62
- xtra = WndExtra::REFS[GetWindowLong(hwnd, GWL_USERDATA)]
49
+ xtra = Util::Id2Ref[GetWindowLong(hwnd, GWL_USERDATA)]
63
50
 
64
51
  PostQuitMessage(0); 0
65
52
  end
@@ -68,9 +55,9 @@ def onItem1(verb,
68
55
  hctl, hwnd
69
56
  )
70
57
  hbar = GetMenu(hwnd)
71
- i2grayed = (GetMenuState(hbar, CMD_ITEM2, 0) & MF_GRAYED) == MF_GRAYED
58
+ i2grayed = (GetMenuState(hbar, ID[:ITEM2], 0) & MF_GRAYED) == MF_GRAYED
72
59
 
73
- EnableMenuItem(hbar, CMD_ITEM2, (i2grayed) ? MF_ENABLED : MF_GRAYED)
60
+ EnableMenuItem(hbar, ID[:ITEM2], (i2grayed) ? MF_ENABLED : MF_GRAYED)
74
61
 
75
62
  0
76
63
  end
@@ -91,9 +78,9 @@ def onItem3(verb,
91
78
  hctl, hwnd
92
79
  )
93
80
  hbar = GetMenu(hwnd)
94
- i3checked = (GetMenuState(hbar, CMD_ITEM3, 0) & MF_CHECKED) == MF_CHECKED
81
+ i3checked = (GetMenuState(hbar, ID[:ITEM3], 0) & MF_CHECKED) == MF_CHECKED
95
82
 
96
- CheckMenuItem(hbar, CMD_ITEM3, (i3checked) ? MF_UNCHECKED : MF_CHECKED)
83
+ CheckMenuItem(hbar, ID[:ITEM3], (i3checked) ? MF_UNCHECKED : MF_CHECKED)
97
84
 
98
85
  0
99
86
  end
@@ -101,7 +88,7 @@ end
101
88
  def onItem4(verb,
102
89
  hctl, hwnd
103
90
  )
104
- CheckMenuRadioItem(GetMenu(hwnd), CMD_ITEM4, CMD_ITEM5, CMD_ITEM4, 0)
91
+ CheckMenuRadioItem(GetMenu(hwnd), ID[:ITEM4], ID[:ITEM5], ID[:ITEM4], 0)
105
92
 
106
93
  0
107
94
  end
@@ -109,7 +96,7 @@ end
109
96
  def onItem5(verb,
110
97
  hctl, hwnd
111
98
  )
112
- CheckMenuRadioItem(GetMenu(hwnd), CMD_ITEM4, CMD_ITEM5, CMD_ITEM5, 0)
99
+ CheckMenuRadioItem(GetMenu(hwnd), ID[:ITEM4], ID[:ITEM5], ID[:ITEM5], 0)
113
100
 
114
101
  0
115
102
  end
@@ -117,7 +104,7 @@ end
117
104
  def onItem6(verb,
118
105
  hctl, hwnd
119
106
  )
120
- CheckMenuRadioItem(GetMenu(hwnd), CMD_ITEM6, CMD_ITEM7, CMD_ITEM6, 0)
107
+ CheckMenuRadioItem(GetMenu(hwnd), ID[:ITEM6], ID[:ITEM7], ID[:ITEM6], 0)
121
108
 
122
109
  0
123
110
  end
@@ -125,7 +112,7 @@ end
125
112
  def onItem7(verb,
126
113
  hctl, hwnd
127
114
  )
128
- CheckMenuRadioItem(GetMenu(hwnd), CMD_ITEM6, CMD_ITEM7, CMD_ITEM7, 0)
115
+ CheckMenuRadioItem(GetMenu(hwnd), ID[:ITEM6], ID[:ITEM7], ID[:ITEM7], 0)
129
116
 
130
117
  0
131
118
  end
@@ -146,12 +133,12 @@ def onItem9(verb,
146
133
  hctl, hwnd
147
134
  )
148
135
  hbar = GetMenu(hwnd)
149
- i2grayed = (GetMenuState(hbar, CMD_ITEM2, 0) & MF_GRAYED) == MF_GRAYED
150
- i3checked = (GetMenuState(hbar, CMD_ITEM3, 0) & MF_CHECKED) == MF_CHECKED
151
- i4checked = (GetMenuState(hbar, CMD_ITEM4, 0) & MF_CHECKED) == MF_CHECKED
152
- i5checked = (GetMenuState(hbar, CMD_ITEM5, 0) & MF_CHECKED) == MF_CHECKED
153
- i6checked = (GetMenuState(hbar, CMD_ITEM6, 0) & MF_CHECKED) == MF_CHECKED
154
- i7checked = (GetMenuState(hbar, CMD_ITEM7, 0) & MF_CHECKED) == MF_CHECKED
136
+ i2grayed = (GetMenuState(hbar, ID[:ITEM2], 0) & MF_GRAYED) == MF_GRAYED
137
+ i3checked = (GetMenuState(hbar, ID[:ITEM3], 0) & MF_CHECKED) == MF_CHECKED
138
+ i4checked = (GetMenuState(hbar, ID[:ITEM4], 0) & MF_CHECKED) == MF_CHECKED
139
+ i5checked = (GetMenuState(hbar, ID[:ITEM5], 0) & MF_CHECKED) == MF_CHECKED
140
+ i6checked = (GetMenuState(hbar, ID[:ITEM6], 0) & MF_CHECKED) == MF_CHECKED
141
+ i7checked = (GetMenuState(hbar, ID[:ITEM7], 0) & MF_CHECKED) == MF_CHECKED
155
142
 
156
143
  MessageBox(hwnd,
157
144
  L("
@@ -194,28 +181,30 @@ begin
194
181
  hctl = FFI::Pointer.new(lParam)
195
182
 
196
183
  case id
197
- when CMD_ITEM1
184
+ when ID[:ITEM1]
198
185
  onItem1(verb, hctl, hwnd)
199
- when CMD_ITEM2
186
+ when ID[:ITEM2]
200
187
  onItem2(verb, hctl, hwnd)
201
- when CMD_ITEM3
188
+ when ID[:ITEM3]
202
189
  onItem3(verb, hctl, hwnd)
203
- when CMD_ITEM4
190
+ when ID[:ITEM4]
204
191
  onItem4(verb, hctl, hwnd)
205
- when CMD_ITEM5
192
+ when ID[:ITEM5]
206
193
  onItem5(verb, hctl, hwnd)
207
- when CMD_ITEM6
194
+ when ID[:ITEM6]
208
195
  onItem6(verb, hctl, hwnd)
209
- when CMD_ITEM7
196
+ when ID[:ITEM7]
210
197
  onItem7(verb, hctl, hwnd)
211
- when CMD_ITEM8
198
+ when ID[:ITEM8]
212
199
  onItem8(verb, hctl, hwnd)
213
- when CMD_ITEM9
200
+ when ID[:ITEM9]
214
201
  onItem9(verb, hctl, hwnd)
215
202
  end
216
203
  end
217
204
 
218
205
  result || DefWindowProc(hwnd, uMsg, wParam, lParam)
206
+ rescue SystemExit => ex
207
+ PostQuitMessage(ex.status)
219
208
  rescue
220
209
  case MessageBox(hwnd,
221
210
  L(Util.FormatException($!)),
@@ -231,7 +220,7 @@ end
231
220
  }
232
221
 
233
222
  def main
234
- xtra = WndExtra.new
223
+ Util.Id2RefTrack(xtra = WndExtra.new)
235
224
 
236
225
  WNDCLASSEX.new { |wc|
237
226
  wc[:cbSize] = wc.size