- Timestamp:
- Jul 17, 2008, 11:20:10 PM (16 years ago)
- Location:
- trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI
- Files:
-
- 3 added
- 1 deleted
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/Application.ab
r547 r551 58 58 59 59 Private 60 Static Sub OnMainFormClosed(sender As Object, e As EventArgs)60 Static Sub OnMainFormClosed(sender As Object, e As Args) 61 61 ExitThread() 62 62 End Sub -
trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/Control.ab
r547 r551 14 14 Inherits WindowHandle 15 15 Public 16 /*! 17 @brief Destroyイベントよりも後に呼ばれるDestroyイベントデリゲート 18 @date 2008/07/16 19 */ 20 finalDestroy As ActiveBasic.Windows.UI.Handler 16 21 17 22 Sub Control() … … 34 39 Private 35 40 Static Function FromHWndCore(hwnd As HWND) As Control 36 If _System_GetClassLongPtr(hwnd, GCW_ATOM) = atom Then 37 Dim gchValue = GetProp(hwnd, PropertyInstance As ULONG_PTR As PCTSTR) As ULONG_PTR 38 If gchValue <> 0 Then 39 Dim gch = System.Runtime.InteropServices.GCHandle.FromIntPtr(gchValue) 40 FromHWndCore = gch.Target As Control 41 Exit Function 42 End If 41 Dim gchValue = GetProp(hwnd, PropertyInstance As ULONG_PTR As PCTSTR) As ULONG_PTR 42 If gchValue <> 0 Then 43 Dim gch = System.Runtime.InteropServices.GCHandle.FromIntPtr(gchValue) 44 FromHWndCore = gch.Target As Control 45 Exit Function 43 46 End If 44 47 End Function … … 55 58 56 59 Public 57 Sub Create( )60 Sub Create(parent = Nothing As Control, style = 0 As DWord, exStyle = 0 As DWord, hmenu = 0 As HMENU) 58 61 Dim cs As CREATESTRUCT 59 cs.hInstance = hInstance 60 cs.lpszClass = (atom As ULONG_PTR) As LPCTSTR 62 With cs 63 .dwExStyle = exStyle 64 .lpszClass = (atom As ULONG_PTR) As LPCTSTR 65 .lpszName = 0 66 .style = style Or WS_CHILD Or WS_VISIBLE 67 .x = CW_USEDEFAULT 68 .y = CW_USEDEFAULT 69 .cx = CW_USEDEFAULT 70 .cy = CW_USEDEFAULT 71 If IsNothing(parent) Then 72 .hwndParent = 0 73 Else 74 .hwndParent = parent As HWND 75 .style Or= WS_CHILD 76 End If 77 .hMenu = hmenu 78 .hInstance = hInstance 79 End With 61 80 GetCreateStruct(cs) 62 createImpl(cs) 63 End Sub 64 81 createImpl(cs, parent) 82 End Sub 83 84 Sub Create(parent As Control, style As DWord, exStyle As DWord, id As Long) 85 Create(parent, style, exStyle, id As HMENU) 86 End Sub 65 87 Protected 66 88 Abstract Sub GetCreateStruct(ByRef cs As CREATESTRUCT) 67 89 68 Sub createImpl(ByRef cs As CREATESTRUCT )90 Sub createImpl(ByRef cs As CREATESTRUCT, parent As Control) 69 91 Imports System.Runtime.InteropServices 70 92 … … 75 97 76 98 With cs 77 Dim hwnd = CreateWindowEx(.dwExStyle, .lpszClass, .lpszName, .style, 99 'よそのクラスの場合、WndProcFirst内のhwndの代入が行われないため、ここでも行っておく。 100 hwnd = CreateWindowEx(.dwExStyle, .lpszClass, .lpszName, .style, 78 101 .x, .y, .cx, .cy, .hwndParent, .hMenu, .hInstance, .lpCreateParams) 79 102 If hwnd = 0 Then 80 103 ActiveBasic.Windows.ThrowByWindowsError(GetLastError()) 81 104 End If 105 106 If IsNothing(FromHWndCore(hwnd)) <> False Then 107 AssociateHWnd(gch, hwnd) 108 TlsSetValue(tlsIndex, 0) 109 End If 82 110 End With 111 112 If IsNothing(parent) = False Then 113 RegisterUnassociateHWnd(parent) 114 End If 83 115 End Sub 84 116 … … 88 120 Public 89 121 Virtual Function WndProc(msg As DWord, wp As WPARAM, lp As LPARAM) As LRESULT 90 Dim h = Nothing As Message EventHandler122 Dim h = Nothing As MessageHandler 91 123 Dim b = messageMap.TryGetValue(Hex$(msg), h) 92 124 If b Then 93 125 If Not IsNothing(h) Then 94 Dim a = New Message EventArgs(hwnd, msg, wp, lp)126 Dim a = New MessageArgs(hwnd, msg, wp, lp) 95 127 h(This, a) 96 128 WndProc = a.LResult … … 106 138 107 139 Private 108 Static Function makeKeysFormMsg(e As Message EventArgs) As Keys140 Static Function makeKeysFormMsg(e As MessageArgs) As Keys 109 141 Dim t As DWord 110 142 t = e.WParam And Keys.KeyCode … … 115 147 End Function 116 148 117 Static Function makeMouseEventFromMsg(e As Message EventArgs) As MouseEventArgs149 Static Function makeMouseEventFromMsg(e As MessageArgs) As MouseArgs 118 150 Dim wp = e.WParam 119 151 Dim lp = e.LParam 120 makeMouseEventFromMsg = New Mouse EventArgs(LOWORD(wp) As MouseButtons, 1, GET_X_LPARAM(lp), GET_Y_LPARAM(lp), 0)152 makeMouseEventFromMsg = New MouseArgs(LOWORD(wp) As MouseButtons, 1, GET_X_LPARAM(lp), GET_Y_LPARAM(lp), 0) 121 153 End Function 122 154 … … 128 160 Sub StartWndProc() 129 161 AddMessageEvent(WM_ERASEBKGND, AddressOf(OnEraseBackground)) 130 Dim md = New Message EventHandler(AddressOf(OnMouseDownBase))162 Dim md = New MessageHandler(AddressOf(OnMouseDownBase)) 131 163 AddMessageEvent(WM_LBUTTONDOWN, md) 132 164 AddMessageEvent(WM_RBUTTONDOWN, md) 133 165 AddMessageEvent(WM_MBUTTONDOWN, md) 134 166 AddMessageEvent(WM_XBUTTONDOWN, md) 135 Dim mu = New Message EventHandler(AddressOf(OnMouseUpBase))167 Dim mu = New MessageHandler(AddressOf(OnMouseUpBase)) 136 168 AddMessageEvent(WM_LBUTTONUP, mu) 137 169 AddMessageEvent(WM_RBUTTONUP, mu) 138 170 AddMessageEvent(WM_MBUTTONUP, mu) 139 171 AddMessageEvent(WM_XBUTTONUP, mu) 140 Dim mb = New Message EventHandler(AddressOf(OnMouseDblClkBase))172 Dim mb = New MessageHandler(AddressOf(OnMouseDblClkBase)) 141 173 AddMessageEvent(WM_LBUTTONDBLCLK, mu) 142 174 AddMessageEvent(WM_RBUTTONDBLCLK, mu) … … 148 180 AddMessageEvent(WM_PAINT, AddressOf(OnPaintBase)) 149 181 AddMessageEvent(WM_KEYDOWN, AddressOf(OnKeyDownBase)) 150 'AddMessageEvent(WM_CHAR, AddressOf(OnChar))182 AddMessageEvent(WM_CHAR, AddressOf(OnChar)) 151 183 AddMessageEvent(WM_CREATE, AddressOf(OnCreateBase)) 152 184 End Sub 153 185 154 Sub OnEraseBackground(sender As Object, e As Message EventArgs)186 Sub OnEraseBackground(sender As Object, e As MessageArgs) 155 187 Dim rc = ClientRect 156 188 FillRect(e.WParam As HDC, rc, (COLOR_3DFACE + 1) As HBRUSH) … … 158 190 End Sub 159 191 160 Sub OnMouseDownBase(sender As Object, e As Message EventArgs)192 Sub OnMouseDownBase(sender As Object, e As MessageArgs) 161 193 OnMouseDown(makeMouseEventFromMsg(e)) 162 194 End Sub 163 195 164 Sub OnMouseUpBase(sender As Object, e As Message EventArgs)196 Sub OnMouseUpBase(sender As Object, e As MessageArgs) 165 197 Dim me = makeMouseEventFromMsg(e) 166 198 If doubleClickFired = False Then 167 ' OnClick(System. EventArgs.Empty)199 ' OnClick(System.Args.Empty) 168 200 OnMouseClick(me) 169 201 doubleClickFired = False … … 172 204 End Sub 173 205 174 Sub OnMouseDblClkBase(sender As Object, e As Message EventArgs)206 Sub OnMouseDblClkBase(sender As Object, e As MessageArgs) 175 207 Dim me = makeMouseEventFromMsg(e) 176 208 doubleClickFired = True 177 209 OnMouseDown(me) 178 ' OnDoubleClick(System. EventArgs.Empty)210 ' OnDoubleClick(System.Args.Empty) 179 211 OnMouseDoubleClick(me) 180 212 End Sub 181 213 182 Sub OnMouseMoveBase(sender As Object, e As Message EventArgs)214 Sub OnMouseMoveBase(sender As Object, e As MessageArgs) 183 215 Dim me = makeMouseEventFromMsg(e) 184 216 If mouseEntered Then … … 190 222 End Sub 191 223 192 Sub OnMouseLeaveBase(sender As Object, e As Message EventArgs)224 Sub OnMouseLeaveBase(sender As Object, e As MessageArgs) 193 225 Dim me = makeMouseEventFromMsg(e) 194 226 OnMouseLeave(me) … … 196 228 End Sub 197 229 198 Sub OnPaintBase(sender As Object, e As Message EventArgs)230 Sub OnPaintBase(sender As Object, e As MessageArgs) 199 231 Dim ps As PAINTSTRUCT 200 232 BeginPaint(ps) 201 233 Try 202 OnPaintDC(New PaintDC EventArgs(ps.hdc, ps.rcPaint))234 OnPaintDC(New PaintDCArgs(ps.hdc, ps.rcPaint)) 203 235 Finally 204 236 EndPaint(ps) … … 206 238 End Sub 207 239 208 Sub OnKeyDownBase(sender As Object, e As MessageEventArgs) 209 OnKeyDown(New KeyEventArgs(makeKeysFormMsg(e))) 210 End Sub 211 212 Sub OnKeyUpBase(sender As Object, e As MessageEventArgs) 213 OnKeyUp(New KeyEventArgs(makeKeysFormMsg(e))) 214 End Sub 215 216 ' コメントアウト解除のときはStartWndProcのコメントアウト解除も忘れないこと 217 ' Sub OnChar(sender As Object, e As MessageEventArgs) 218 ' OnKeyPress(New KeyPressEventArgs(e.WParam As Char)) 219 ' End Sub 220 221 Sub OnCreateBase(sender As Object, e As MessageEventArgs) 222 OnCreate(New CreateEventArgs(e.LParam As *CREATESTRUCT)) 223 End Sub 224 225 messageMap As System.Collections.Generic.Dictionary<Object /*DWord*/, MessageEventHandler> 240 Sub OnKeyDownBase(sender As Object, e As MessageArgs) 241 OnKeyDown(New KeyArgs(makeKeysFormMsg(e))) 242 End Sub 243 244 Sub OnKeyUpBase(sender As Object, e As MessageArgs) 245 OnKeyUp(New KeyArgs(makeKeysFormMsg(e))) 246 End Sub 247 248 Sub OnChar(sender As Object, e As MessageArgs) 249 OnKeyPress(New KeyPressArgs(e.WParam As Char)) 250 End Sub 251 252 Sub OnCreateBase(sender As Object, e As MessageArgs) 253 ' OnCreate(New CreateArgs(e.LParam As *CREATESTRUCT)) 254 End Sub 255 256 messageMap As System.Collections.Generic.Dictionary<Object /*DWord*/, MessageHandler> 226 257 227 258 Public … … 230 261 @date 2007/12/04 231 262 */ 232 Sub AddMessageEvent(message As DWord, h As Message EventHandler)263 Sub AddMessageEvent(message As DWord, h As MessageHandler) 233 264 If Not IsNothing(h) Then 234 265 If IsNothing(messageMap) Then 235 messageMap = New System.Collections.Generic.Dictionary<Object, Message EventHandler>266 messageMap = New System.Collections.Generic.Dictionary<Object, MessageHandler> 236 267 End If 237 268 Dim msg = Hex$(message) 238 Dim m = Nothing As Message EventHandler269 Dim m = Nothing As MessageHandler 239 270 If messageMap.TryGetValue(msg, m) Then 240 271 messageMap.Item[msg] = m + h … … 249 280 @date 2007/12/04 250 281 */ 251 Sub RemoveMessageEvent(message As DWord, a As Message EventHandler)282 Sub RemoveMessageEvent(message As DWord, a As MessageHandler) 252 283 If Not IsNothing(a) Then 253 284 If Not IsNothing(messageMap) Then … … 302 333 ' ウィンドウが作られて最初にWndProcFirstが呼ばれたとき 303 334 304 If IsNothing(rThis)Then335 If AssociateHWnd(gch, hwnd) = False Then 305 336 Goto *InstanceIsNotFound 306 337 End If 307 rThis.hwnd = hwnd 308 rThis.Prop[PropertyInstance] = gchValue As HANDLE 338 End If 339 If msg = WM_NCDESTROY Then 340 rThis.UnassociateHWnd() 341 End If 342 If msg = WM_DESTROY And IsNothing(rThis.finalDestroy) = False Then 343 Dim f = rThis.finalDestroy 344 f(rThis, Args.Empty) 345 ' finalDestroy(This, Args.Empty) 309 346 End If 310 347 WndProcFirst = rThis.WndProc(msg, wp, lp) 311 If msg = WM_NCDESTROY Then312 Dim gchValue = rThis.Prop(PropertyInstance) As ULONG_PTR313 If gchValue <> 0 Then314 GCHandle.FromIntPtr(gchValue).Free()315 End If316 End If317 318 348 Exit Function 319 349 … … 322 352 WndProcFirst = DefWindowProc(hwnd, msg, wp, lp) 323 353 End Function 354 355 /*! 356 @brief Controlインスタンスとウィンドウハンドルを結び付ける。 357 @param[in] 結び付けられるControlインスタンスを格納したGCHandle 358 @param[in] hwnd 結び付けるウィンドウハンドル 359 @date 2008/07/16 360 これを実行することで、UnassociateHWndされるまでControlがGC対象にならなくなる。 361 */ 362 Static Function AssociateHWnd(gch As System.Runtime.InteropServices.GCHandle, hwnd As HWND) As Boolean 363 Imports System.Runtime.InteropServices 364 Dim rThis = gch.Target As Control 365 If IsNothing(rThis) Then 366 Exit Function 367 End If 368 rThis.hwnd = hwnd 369 rThis.Prop[PropertyInstance] = GCHandle.ToIntPtr(gch) As HANDLE 370 End Function 371 372 /*! 373 @brief オーナーの破棄時にこのControlインスタンスとウィンドウハンドルの結び付けを解除するよう登録する。 374 @param[in] owner 結び付けの解除を連動させるControl 375 @date 2008/07/16 376 ownerのFinalDestoryでこのControlとHWNDとの結び付けを解除する。 377 */ 378 Sub RegisterUnassociateHWnd(owner As Control) 379 If IsNothing(owner) = False Then 380 Dim e = New Handler(AddressOf(UnassociateHWndOnEvent)) 381 If IsNothing(finalDestroy) Then 382 owner.finalDestroy = e 383 Else 384 owner.finalDestroy += e 385 End If 386 End If 387 End Sub 388 389 Sub UnassociateHWndOnEvent(sender As Object, e As Args) 390 UnassociateHWnd() 391 End Sub 392 393 Sub UnassociateHWnd() 394 Imports System.Runtime.InteropServices 395 Dim gchValue = Prop(PropertyInstance) As ULONG_PTR 396 If gchValue <> 0 Then 397 GCHandle.FromIntPtr(gchValue).Free() 398 End If 399 End Sub 324 400 325 401 ' Static Const WM_CONTROL_INVOKE = WM_USER + 0 As DWord -
trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/ControlEvent.sbp
r545 r551 1 1 Public 2 Sub AddPaintDC(h As PaintDC EventHandler)2 Sub AddPaintDC(h As PaintDCHandler) 3 3 If IsNothing(paintDC) Then 4 4 paintDC = h … … 7 7 End If 8 8 End Sub 9 Sub RemovePaintDC(h As PaintDC EventHandler)9 Sub RemovePaintDC(h As PaintDCHandler) 10 10 If Not IsNothing(paintDC) Then 11 11 paintDC -= h 12 12 End If 13 13 End Sub 14 Pr ivate15 Sub OnPaintDC(e As PaintDC EventArgs)14 Protected 15 Sub OnPaintDC(e As PaintDCArgs) 16 16 If Not IsNothing(paintDC) Then 17 17 paintDC(This, e) … … 19 19 End Sub 20 20 Private 21 paintDC As PaintDCEventHandler 22 23 Public 24 Sub AddMouseEnter(h As MouseEventHandler) 21 paintDC As PaintDCHandler 22 23 Public 24 Sub AddClick(h As Handler) 25 If IsNothing(click) Then 26 click = h 27 Else 28 click += h 29 End If 30 End Sub 31 Sub RemoveClick(h As Handler) 32 If Not IsNothing(click) Then 33 click -= h 34 End If 35 End Sub 36 Protected 37 Sub OnClick(e As Args) 38 If Not IsNothing(click) Then 39 click(This, e) 40 End If 41 End Sub 42 Private 43 click As Handler 44 45 Public 46 Sub AddDoubleClick(h As Handler) 47 If IsNothing(doubleClick) Then 48 doubleClick = h 49 Else 50 doubleClick += h 51 End If 52 End Sub 53 Sub RemoveDoubleClick(h As Handler) 54 If Not IsNothing(doubleClick) Then 55 doubleClick -= h 56 End If 57 End Sub 58 Protected 59 Sub OnDoubleClick(e As Args) 60 If Not IsNothing(doubleClick) Then 61 doubleClick(This, e) 62 End If 63 End Sub 64 Private 65 doubleClick As Handler 66 67 Public 68 Sub AddMove(h As Handler) 69 If IsNothing(move) Then 70 move = h 71 Else 72 move += h 73 End If 74 End Sub 75 Sub RemoveMove(h As Handler) 76 If Not IsNothing(move) Then 77 move -= h 78 End If 79 End Sub 80 Protected 81 Sub OnMove(e As Args) 82 If Not IsNothing(move) Then 83 move(This, e) 84 End If 85 End Sub 86 Private 87 move As Handler 88 89 Public 90 Sub AddMouseEnter(h As MouseHandler) 25 91 If IsNothing(mouseEnter) Then 26 92 mouseEnter = h … … 29 95 End If 30 96 End Sub 31 Sub RemoveMouseEnter(h As Mouse EventHandler)97 Sub RemoveMouseEnter(h As MouseHandler) 32 98 If Not IsNothing(mouseEnter) Then 33 99 mouseEnter -= h 34 100 End If 35 101 End Sub 36 Pr ivate37 Sub OnMouseEnter(e As Mouse EventArgs)102 Protected 103 Sub OnMouseEnter(e As MouseArgs) 38 104 If Not IsNothing(mouseEnter) Then 39 105 mouseEnter(This, e) … … 41 107 End Sub 42 108 Private 43 mouseEnter As Mouse EventHandler44 45 Public 46 Sub AddMouseMove(h As Mouse EventHandler)109 mouseEnter As MouseHandler 110 111 Public 112 Sub AddMouseMove(h As MouseHandler) 47 113 If IsNothing(mouseMove) Then 48 114 mouseMove = h … … 51 117 End If 52 118 End Sub 53 Sub RemoveMouseMove(h As Mouse EventHandler)119 Sub RemoveMouseMove(h As MouseHandler) 54 120 If Not IsNothing(mouseMove) Then 55 121 mouseMove -= h 56 122 End If 57 123 End Sub 58 Pr ivate59 Sub OnMouseMove(e As Mouse EventArgs)124 Protected 125 Sub OnMouseMove(e As MouseArgs) 60 126 If Not IsNothing(mouseMove) Then 61 127 mouseMove(This, e) … … 63 129 End Sub 64 130 Private 65 mouseMove As Mouse EventHandler66 67 Public 68 Sub AddMouseHover(h As Mouse EventHandler)131 mouseMove As MouseHandler 132 133 Public 134 Sub AddMouseHover(h As MouseHandler) 69 135 If IsNothing(mouseHover) Then 70 136 mouseHover = h … … 73 139 End If 74 140 End Sub 75 Sub RemoveMouseHover(h As Mouse EventHandler)141 Sub RemoveMouseHover(h As MouseHandler) 76 142 If Not IsNothing(mouseHover) Then 77 143 mouseHover -= h 78 144 End If 79 145 End Sub 80 Pr ivate81 Sub OnMouseHover(e As Mouse EventArgs)146 Protected 147 Sub OnMouseHover(e As MouseArgs) 82 148 If Not IsNothing(mouseHover) Then 83 149 mouseHover(This, e) … … 85 151 End Sub 86 152 Private 87 mouseHover As Mouse EventHandler88 89 Public 90 Sub AddMouseLeave(h As Mouse EventHandler)153 mouseHover As MouseHandler 154 155 Public 156 Sub AddMouseLeave(h As MouseHandler) 91 157 If IsNothing(mouseLeave) Then 92 158 mouseLeave = h … … 95 161 End If 96 162 End Sub 97 Sub RemoveMouseLeave(h As Mouse EventHandler)163 Sub RemoveMouseLeave(h As MouseHandler) 98 164 If Not IsNothing(mouseLeave) Then 99 165 mouseLeave -= h 100 166 End If 101 167 End Sub 102 Pr ivate103 Sub OnMouseLeave(e As Mouse EventArgs)168 Protected 169 Sub OnMouseLeave(e As MouseArgs) 104 170 If Not IsNothing(mouseLeave) Then 105 171 mouseLeave(This, e) … … 107 173 End Sub 108 174 Private 109 mouseLeave As Mouse EventHandler110 111 Public 112 Sub AddMouseDown(h As Mouse EventHandler)175 mouseLeave As MouseHandler 176 177 Public 178 Sub AddMouseDown(h As MouseHandler) 113 179 If IsNothing(mouseDown) Then 114 180 mouseDown = h … … 117 183 End If 118 184 End Sub 119 Sub RemoveMouseDown(h As Mouse EventHandler)185 Sub RemoveMouseDown(h As MouseHandler) 120 186 If Not IsNothing(mouseDown) Then 121 187 mouseDown -= h 122 188 End If 123 189 End Sub 124 Pr ivate125 Sub OnMouseDown(e As Mouse EventArgs)190 Protected 191 Sub OnMouseDown(e As MouseArgs) 126 192 If Not IsNothing(mouseDown) Then 127 193 mouseDown(This, e) … … 129 195 End Sub 130 196 Private 131 mouseDown As Mouse EventHandler132 133 Public 134 Sub AddMouseClick(h As Mouse EventHandler)197 mouseDown As MouseHandler 198 199 Public 200 Sub AddMouseClick(h As MouseHandler) 135 201 If IsNothing(mouseClick) Then 136 202 mouseClick = h … … 139 205 End If 140 206 End Sub 141 Sub RemoveMouseClick(h As Mouse EventHandler)207 Sub RemoveMouseClick(h As MouseHandler) 142 208 If Not IsNothing(mouseClick) Then 143 209 mouseClick -= h 144 210 End If 145 211 End Sub 146 Pr ivate147 Sub OnMouseClick(e As Mouse EventArgs)212 Protected 213 Sub OnMouseClick(e As MouseArgs) 148 214 If Not IsNothing(mouseClick) Then 149 215 mouseClick(This, e) … … 151 217 End Sub 152 218 Private 153 mouseClick As Mouse EventHandler154 155 Public 156 Sub AddMouseDoubleClick(h As Mouse EventHandler)219 mouseClick As MouseHandler 220 221 Public 222 Sub AddMouseDoubleClick(h As MouseHandler) 157 223 If IsNothing(mouseDoubleClick) Then 158 224 mouseDoubleClick = h … … 161 227 End If 162 228 End Sub 163 Sub RemoveMouseDoubleClick(h As Mouse EventHandler)229 Sub RemoveMouseDoubleClick(h As MouseHandler) 164 230 If Not IsNothing(mouseDoubleClick) Then 165 231 mouseDoubleClick -= h 166 232 End If 167 233 End Sub 168 Pr ivate169 Sub OnMouseDoubleClick(e As Mouse EventArgs)234 Protected 235 Sub OnMouseDoubleClick(e As MouseArgs) 170 236 If Not IsNothing(mouseDoubleClick) Then 171 237 mouseDoubleClick(This, e) … … 173 239 End Sub 174 240 Private 175 mouseDoubleClick As Mouse EventHandler176 177 Public 178 Sub AddMouseUp(h As Mouse EventHandler)241 mouseDoubleClick As MouseHandler 242 243 Public 244 Sub AddMouseUp(h As MouseHandler) 179 245 If IsNothing(mouseUp) Then 180 246 mouseUp = h … … 183 249 End If 184 250 End Sub 185 Sub RemoveMouseUp(h As Mouse EventHandler)251 Sub RemoveMouseUp(h As MouseHandler) 186 252 If Not IsNothing(mouseUp) Then 187 253 mouseUp -= h 188 254 End If 189 255 End Sub 190 Pr ivate191 Sub OnMouseUp(e As Mouse EventArgs)256 Protected 257 Sub OnMouseUp(e As MouseArgs) 192 258 If Not IsNothing(mouseUp) Then 193 259 mouseUp(This, e) … … 195 261 End Sub 196 262 Private 197 mouseUp As Mouse EventHandler198 199 Public 200 Sub AddKeyDown(h As Key EventHandler)263 mouseUp As MouseHandler 264 265 Public 266 Sub AddKeyDown(h As KeyHandler) 201 267 If IsNothing(keyDown) Then 202 268 keyDown = h … … 205 271 End If 206 272 End Sub 207 Sub RemoveKeyDown(h As Key EventHandler)273 Sub RemoveKeyDown(h As KeyHandler) 208 274 If Not IsNothing(keyDown) Then 209 275 keyDown -= h 210 276 End If 211 277 End Sub 212 Pr ivate213 Sub OnKeyDown(e As Key EventArgs)278 Protected 279 Sub OnKeyDown(e As KeyArgs) 214 280 If Not IsNothing(keyDown) Then 215 281 keyDown(This, e) … … 217 283 End Sub 218 284 Private 219 keyDown As Key EventHandler220 221 Public 222 Sub AddKeyUp(h As Key EventHandler)285 keyDown As KeyHandler 286 287 Public 288 Sub AddKeyUp(h As KeyHandler) 223 289 If IsNothing(keyUp) Then 224 290 keyUp = h … … 227 293 End If 228 294 End Sub 229 Sub RemoveKeyUp(h As Key EventHandler)295 Sub RemoveKeyUp(h As KeyHandler) 230 296 If Not IsNothing(keyUp) Then 231 297 keyUp -= h 232 298 End If 233 299 End Sub 234 Pr ivate235 Sub OnKeyUp(e As Key EventArgs)300 Protected 301 Sub OnKeyUp(e As KeyArgs) 236 302 If Not IsNothing(keyUp) Then 237 303 keyUp(This, e) … … 239 305 End Sub 240 306 Private 241 keyUp As KeyEventHandler 242 243 Public 244 Sub AddCreate(h As CreateEventHandler) 307 keyUp As KeyHandler 308 309 Public 310 Sub AddKeyPress(h As KeyPressHandler) 311 If IsNothing(keyPress) Then 312 keyPress = h 313 Else 314 keyPress += h 315 End If 316 End Sub 317 Sub RemoveKeyPress(h As KeyPressHandler) 318 If Not IsNothing(keyPress) Then 319 keyPress -= h 320 End If 321 End Sub 322 Protected 323 Sub OnKeyPress(e As KeyPressArgs) 324 If Not IsNothing(keyPress) Then 325 keyPress(This, e) 326 End If 327 End Sub 328 Private 329 keyPress As KeyPressHandler 330 /* 331 Public 332 Sub AddCreate(h As CreateHandler) 245 333 If IsNothing(create) Then 246 334 create = h … … 249 337 End If 250 338 End Sub 251 Sub RemoveCreate(h As Create EventHandler)339 Sub RemoveCreate(h As CreateHandler) 252 340 If Not IsNothing(create) Then 253 341 create -= h 254 342 End If 255 343 End Sub 256 Pr ivate257 Sub OnCreate(e As Create EventArgs)344 Protected 345 Sub OnCreate(e As CreateArgs) 258 346 If Not IsNothing(create) Then 259 347 create(This, e) … … 261 349 End Sub 262 350 Private 263 create As CreateEventHandler 264 351 create As CreateHandler 352 353 Public 354 Sub AddDestroy(h As Handler) 355 If IsNothing(destroy) Then 356 destroy = h 357 Else 358 destroy += h 359 End If 360 End Sub 361 Sub RemoveDestroy(h As Handler) 362 If Not IsNothing(destroy) Then 363 destroy -= h 364 End If 365 End Sub 366 Protected 367 Sub OnDestroy(e As Args) 368 If Not IsNothing(destroy) Then 369 destroy(This, e) 370 End If 371 End Sub 372 Private 373 destroy As Handler 374 */ -
trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/ControlEventList.txt
r545 r551 1 PaintDC PaintDC Eventウィンドウの描画が必要なときに呼び出されます。2 'Click Eventクリックされたときに呼び出されます。3 'DoubleClick Eventダブルクリックされたときに呼び出されます。4 'EnableChanged Event有効状態が変化したときに呼び出されます。5 'Move Eventウィンドウが移動したときに呼び出されます。6 'Resize Eventウィンドウの大きさが変化したときに呼び出されます。7 'VisibleChanged Eventウィンドウの表示状態が変化したときに呼び出されます。8 'SetFocus Eventフォーカスを得たときに呼び出されます。9 'KillFocus Eventフォーカスを失ったときに呼び出されます。10 MouseEnter Mouse Eventマウスカーソルがコントロールに入ってくると呼び出されます。11 MouseMove Mouse Eventマウスカーソルがコントロール上で移動すると呼び出されます12 MouseHover Mouse Eventマウスカーソルがコントロール上で静止すると呼び出されます。13 MouseLeave Mouse Eventマウスカーソルがコントロールから出て行くと呼び出されます。14 MouseDown Mouse Eventマウスボタンが押されたときに呼び出されます。15 MouseClick Mouse Eventマウスでクリックされたときに呼び出されます。16 MouseDoubleClick Mouse Eventマウスでダブルクリックされたときに呼び出されます。17 MouseUp Mouse Eventマウスボタンが離されたときに呼び出されます。18 'MouseWheel Mouse Eventマウスホイールが回されたときに呼び出されます。19 KeyDown Key Eventキーが押されたときに呼ばれます。20 KeyUp Key Eventキーが離されたときに呼ばれます。21 'なぜかコンパイルエラーを起こすのでコメントアウト KeyPress KeyPressEventキーが押されて文字が打たれたときに呼ばれます。22 Create Create Eventウィンドウが作成されたときに呼ばれます。23 'Destroy Eventウィンドウが破棄されるときに呼ばれます。1 PaintDC PaintDC ウィンドウの描画が必要なときに呼び出されます。 2 Click クリックされたときに呼び出されます。 3 DoubleClick ダブルクリックされたときに呼び出されます。 4 'EnableChanged 有効状態が変化したときに呼び出されます。 5 Move ウィンドウが移動したときに呼び出されます。 6 'Resize ウィンドウの大きさが変化したときに呼び出されます。 7 'VisibleChanged ウィンドウの表示状態が変化したときに呼び出されます。 8 'SetFocus フォーカスを得たときに呼び出されます。 9 'KillFocus フォーカスを失ったときに呼び出されます。 10 MouseEnter Mouse マウスカーソルがコントロールに入ってくると呼び出されます。 11 MouseMove Mouse マウスカーソルがコントロール上で移動すると呼び出されます 12 MouseHover Mouse マウスカーソルがコントロール上で静止すると呼び出されます。 13 MouseLeave Mouse マウスカーソルがコントロールから出て行くと呼び出されます。 14 MouseDown Mouse マウスボタンが押されたときに呼び出されます。 15 MouseClick Mouse マウスでクリックされたときに呼び出されます。 16 MouseDoubleClick Mouse マウスでダブルクリックされたときに呼び出されます。 17 MouseUp Mouse マウスボタンが離されたときに呼び出されます。 18 'MouseWheel Mouse マウスホイールが回されたときに呼び出されます。 19 KeyDown Key キーが押されたときに呼ばれます。 20 KeyUp Key キーが離されたときに呼ばれます。 21 KeyPress KeyPress キーが押されて文字が打たれたときに呼ばれます。 22 Create Create ウィンドウが作成されたときに呼ばれます。 23 Destroy ウィンドウが破棄されるときに呼ばれます。 -
trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/EventArgs.ab
r547 r551 1 1 /** 2 @file Include/Classes/ActiveBasic/Windows/UI/ EventArgs.ab2 @file Include/Classes/ActiveBasic/Windows/UI/Args.ab 3 3 @brief イベントハンドラ関連 4 4 */ … … 8 8 Namespace UI 9 9 10 'TypeDef EventArgs = System.EventArgs 11 'TypeDef EventHandler = System.EventHandler 12 Class EventArgs 13 Public 14 Static Empty = Nothing As EventArgs 15 End Class 16 Delegate Sub EventHandler(sender As Object, e As EventArgs) 17 18 Class MessageEventArgs 19 Inherits EventArgs 20 Public 21 Sub MessageEventArgs(hwndSrc As HWND, message As DWord, wParam As WPARAM, lParam As LPARAM) 10 TypeDef Args = System.EventArgs 11 'TypeDef Handler = System.EventHandler 12 Delegate Sub Handler(sender As Object, e As Args) 13 14 Class MessageArgs 15 Inherits Args 16 Public 17 Sub MessageArgs(hwndSrc As HWND, message As DWord, wParam As WPARAM, lParam As LPARAM) 22 18 msg = message 23 19 ' hwnd = hwndSrc … … 58 54 End Class 59 55 60 Delegate Sub Message EventHandler(sender As Object, e As MessageEventArgs)61 62 Class PaintDC EventArgs63 Inherits EventArgs64 Public 65 Sub PaintDC EventArgs(hdcTarget As HDC, ByRef rect As RECT)56 Delegate Sub MessageHandler(sender As Object, e As MessageArgs) 57 58 Class PaintDCArgs 59 Inherits Args 60 Public 61 Sub PaintDCArgs(hdcTarget As HDC, ByRef rect As RECT) 66 62 hdc = hdcTarget 67 63 rc = rect … … 81 77 End Class 82 78 83 Delegate Sub PaintDC EventHandler(sender As Object, e As PaintDCEventArgs)84 85 Class PaintDCHandled EventArgs86 Inherits PaintDC EventArgs87 Public 88 Sub PaintDCHandled EventArgs(hdcTarget As HDC, ByRef rect As RECT)89 PaintDC EventArgs(hdcTarget, rect)79 Delegate Sub PaintDCHandler(sender As Object, e As PaintDCArgs) 80 81 Class PaintDCHandledArgs 82 Inherits PaintDCArgs 83 Public 84 Sub PaintDCHandledArgs(hdcTarget As HDC, ByRef rect As RECT) 85 PaintDCArgs(hdcTarget, rect) 90 86 End Sub 91 87 … … 102 98 End Class 103 99 104 TypeDef PaintDCBackGround EventArgs = PaintDCHandledEventArgs100 TypeDef PaintDCBackGroundArgs = PaintDCHandledArgs 105 101 106 102 Enum MouseButtons … … 116 112 End Enum 117 113 118 Class Mouse EventArgs119 Inherits EventArgs120 Public 121 Sub Mouse EventArgs(button As MouseButtons, clicks As Long, x As Long, y As Long, delta As Long)114 Class MouseArgs 115 Inherits Args 116 Public 117 Sub MouseArgs(button As MouseButtons, clicks As Long, x As Long, y As Long, delta As Long) 122 118 This.button = button 123 119 This.clicks = clicks 124 120 This.pt = New System.Drawing.Point(x, y) 125 OutputDebugString(ToTCStr(Hex$(y) + " " + Hex$(pt.Y) + " " + Ex" mea\r\n"))126 121 This.delta = delta 127 122 End Sub … … 158 153 End Class 159 154 160 Delegate Sub Mouse EventHandler(sender As Object, e As MouseEventArgs)161 162 Class KeyPress EventArgs163 Inherits EventArgs164 Public 165 Sub KeyPress EventArgs(keyChar As Char)155 Delegate Sub MouseHandler(sender As Object, e As MouseArgs) 156 157 Class KeyPressArgs 158 Inherits Args 159 Public 160 Sub KeyPressArgs(keyChar As Char) 166 161 key = keyChar 167 162 End Sub … … 187 182 End Class 188 183 189 Delegate Sub KeyPress EventHandler(sender As Object, e As KeyPressEventArgs)184 Delegate Sub KeyPressHandler(sender As Object, e As KeyPressArgs) 190 185 191 186 Enum Keys … … 384 379 End Enum 385 380 386 Class Key EventArgs387 Inherits EventArgs388 Public 389 Sub Key EventArgs(keyData As Keys)381 Class KeyArgs 382 Inherits Args 383 Public 384 Sub KeyArgs(keyData As Keys) 390 385 key = keyData 391 386 End Sub … … 436 431 End Class 437 432 438 Delegate Sub Key EventHandler(sender As Object, e As KeyEventArgs)439 440 Class Create EventArgs441 Inherits EventArgs442 Public 443 Sub Create EventArgs(pCreateStruct As *CREATESTRUCT)433 Delegate Sub KeyHandler(sender As Object, e As KeyArgs) 434 435 Class CreateArgs 436 Inherits Args 437 Public 438 Sub CreateArgs(pCreateStruct As *CREATESTRUCT) 444 439 pcs = pCreateStruct 445 440 End Sub … … 494 489 End Class 495 490 496 Delegate Sub Create EventHandler(sender As Object, e As CreateEventArgs)497 498 Class FormClosing EventArgs499 Inherits EventArgs500 Public 501 Sub FormClosing EventArgs()491 Delegate Sub CreateHandler(sender As Object, e As CreateArgs) 492 493 Class FormClosingArgs 494 Inherits Args 495 Public 496 Sub FormClosingArgs() 502 497 c = False 503 498 End Sub … … 514 509 End Class 515 510 516 Delegate Sub FormClosing EventHandler(sender As Object, e As FormClosingEventArgs)511 Delegate Sub FormClosingHandler(sender As Object, e As FormClosingArgs) 517 512 518 513 End Namespace 'UI -
trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/Form.ab
r547 r551 2 2 3 3 #require <Classes/ActiveBasic/Windows/UI/Control.ab> 4 #require <Classes/ActiveBasic/Windows/UI/Button.ab> 4 5 5 6 Namespace ActiveBasic … … 12 13 @author Egtra 13 14 */ 15 14 16 Class Form 15 17 Inherits Control 18 Public 19 Sub Form() 20 AddMessageEvent(WM_COMMAND, AddressOf (OnCommand)) 21 End Sub 22 16 23 Protected 17 24 Override Sub GetCreateStruct(ByRef cs As CREATESTRUCT) 18 With cs 19 .lpCreateParams = 0 20 '.hInstance 21 .hMenu = 0 22 .hwndParent = 0 23 .cy = CW_USEDEFAULT 24 .cx = CW_USEDEFAULT 25 .y = CW_USEDEFAULT 26 .x = CW_USEDEFAULT 27 .style = WS_OVERLAPPEDWINDOW 28 .lpszName = "" 29 '.lpszClass 30 .dwExStyle = 0 31 End With 25 cs.style = WS_OVERLAPPEDWINDOW 32 26 End Sub 27 28 Sub OnCommand(sender As Object, e As MessageArgs) 29 Dim id = e.WParam And &hffff 'LOWORD(e.WParam) 30 Dim cmd = (e.WParam >> 16) And &hffff 'HIWORD(e.WParam) 31 Dim hwnd = e.LParam As HWND 32 If cmd = BN_CLICKED And hwnd <> 0 Then 33 Dim c = Control.FromHWnd(hwnd) 34 If IsNothing(c) = False Then 35 Dim b = c As Button 36 b.RaiseClick() 37 End If 38 End If 39 End Sub 40 33 41 #include "FormEvent.sbp" 34 42 End Class … … 42 50 43 51 #require <Classes/ActiveBasic/Windows/UI/Application.ab> 52 #require <Classes/ActiveBasic/Windows/UI/Button.ab> 44 53 45 54 Imports ActiveBasic.Windows.UI … … 48 57 Control.Initialize(GetModuleHandle(0)) 49 58 59 Sub Paint(sender As Object, e As PaintDCArgs) 60 TextOut(e.Handle, 10, 10, "Hello world!", 12) 61 End Sub 62 50 63 Class MyForm 51 64 Inherits Form 52 65 Public 53 66 Sub MyForm() 54 Dim f = This 55 AddMessageEvent(WM_DESTROY, AddressOf (f.Destory)) 56 AddPaintDC(AddressOf (f.Paint)) 57 AddMouseClick(AddressOf (f.Mouse)) 58 s = "" 67 AddPaintDC(AddressOf (Paint)) 68 AddMouseClick(AddressOf (Mouse)) 69 s = "aaa" 59 70 End Sub 60 71 61 Sub Destory(sender As Object, e As EventArgs) 62 OutputDebugString(Ex"Destory\r\n") 63 PostQuitMessage(0) 72 ' Sub Paint(sender As Object, e As PaintDCArgs) 73 ' TextOut(e.Handle, 10, 10, ToTCStr(s), s.Length) 74 ' End Sub 75 76 Sub Mouse(sender As Object, e As MouseArgs) 77 Invalidate() 64 78 End Sub 65 79 66 Sub Paint(sender As Object, e As PaintDCEventArgs) 67 TextOut(e.Handle, 10, 10, ToTCStr(s), s.Length) 68 End Sub 69 70 Sub Mouse(sender As Object, e As MouseEventArgs) 71 Dim sb = New System.Text.StringBuilder 72 sb.Append("X = ").Append(e.X).Append(", Y = ").Append(e.Y) 73 s = sb.ToString 74 OutputDebugString(ToTCStr(s + " " + Hex$(ObjPtr(e)) + Ex"\r\n")) 75 Invalidate() 80 Sub OnClick(sender As Object, e As Args) 81 OutputDebugString(Ex"====OnClick====\r\n") 76 82 End Sub 77 83 … … 81 87 Dim f = New MyForm 82 88 f.Create() 89 f.Text = "Hello" 90 91 Dim b = New Button 92 b.Create(f) 93 b.Move(50, 50, 100, 100) 94 b.Text = "Ok" 95 b.AddClick(AddressOf(f.OnClick)) 96 83 97 Application.Run(f) 84 98 f = Nothing … … 89 103 90 104 End 91 -
trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/FormEvent.sbp
r545 r551 1 1 Public 2 Sub AddQueryClose(h As FormClosing EventHandler)2 Sub AddQueryClose(h As FormClosingHandler) 3 3 If IsNothing(queryClose) Then 4 4 queryClose = h … … 7 7 End If 8 8 End Sub 9 Sub RemoveQueryClose(h As FormClosing EventHandler)9 Sub RemoveQueryClose(h As FormClosingHandler) 10 10 If Not IsNothing(queryClose) Then 11 11 queryClose -= h 12 12 End If 13 13 End Sub 14 Pr ivate15 Sub OnQueryClose(e As FormClosing EventArgs)14 Protected 15 Sub OnQueryClose(e As FormClosingArgs) 16 16 If Not IsNothing(queryClose) Then 17 17 queryClose(This, e) … … 19 19 End Sub 20 20 Private 21 queryClose As FormClosing EventHandler21 queryClose As FormClosingHandler 22 22 -
trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/FormEventList.txt
r547 r551 4 4 'f QueryClose WM_CLOSE 5 5 'f Timer WM_TIMER 6 'Activate Eventウィンドウがアクティブになったときに呼ばれます。7 'Deactivate Eventウィンドウがアクティブでなくなったときに呼ばれます。8 QueryClose FormClosing Eventウィンドウが閉じられようとしているときに呼ばれます。6 'Activate ウィンドウがアクティブになったときに呼ばれます。 7 'Deactivate ウィンドウがアクティブでなくなったときに呼ばれます。 8 QueryClose FormClosing ウィンドウが閉じられようとしているときに呼ばれます。 -
trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/MakeControlEventHandler.ab
r545 r551 40 40 out.WriteLine(Ex"\t\tEnd If") 41 41 out.WriteLine(Ex"\tEnd Sub") 42 out.WriteLine("Pr ivate")42 out.WriteLine("Protected") 43 43 ' out.WriteLine(Ex"\t/*!") 44 44 ' out.WriteLine(Ex"\t@brief " & comment) … … 79 79 MakeControlEvent("Control") 80 80 MakeControlEvent("Form") 81 MakeControlEvent("Application") 81 82 End
Note:
See TracChangeset
for help on using the changeset viewer.