- Timestamp:
- Jul 13, 2008, 11:54:55 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/Control.ab
r545 r547 12 12 13 13 Class Control 14 Inherits WindowHandle 14 15 Public 16 15 17 Sub Control() 16 18 End Sub … … 25 27 Static Function FromHWnd(hwnd As HWND) As Control 26 28 FromHWnd = Nothing 27 If IsWindow(hwnd) Then29 If _System_IsWindow(hwnd) Then 28 30 FromHWnd = FromHWndCore(hwnd) 29 31 End If … … 32 34 Private 33 35 Static Function FromHWndCore(hwnd As HWND) As Control 34 If GetClassLongPtr(hwnd, GCW_ATOM) = atom Then36 If _System_GetClassLongPtr(hwnd, GCW_ATOM) = atom Then 35 37 Dim gchValue = GetProp(hwnd, PropertyInstance As ULONG_PTR As PCTSTR) As ULONG_PTR 36 38 If gchValue <> 0 Then … … 44 46 '-------------------------------- 45 47 ' ウィンドウ作成 46 /* 47 Function Create( 48 parent As HWND, 49 rect As RECT, 50 name As String, 51 style As DWord, 52 exStyle = 0 As DWord, 53 menu = 0 As HMENU) As HWND 54 */ 48 ' Function Create( 49 ' parent As HWND, 50 ' rect As RECT, 51 ' name As String, 52 ' style As DWord, 53 ' exStyle = 0 As DWord, 54 ' menu = 0 As HMENU) As HWND 55 55 56 56 Public 57 Function Create() As Boolean57 Sub Create() 58 58 Dim cs As CREATESTRUCT 59 59 cs.hInstance = hInstance 60 60 cs.lpszClass = (atom As ULONG_PTR) As LPCTSTR 61 61 GetCreateStruct(cs) 62 Create =createImpl(cs)63 End Function62 createImpl(cs) 63 End Sub 64 64 65 65 Protected 66 66 Abstract Sub GetCreateStruct(ByRef cs As CREATESTRUCT) 67 67 68 Function createImpl(ByRef cs As CREATESTRUCT) As Boolean68 Sub createImpl(ByRef cs As CREATESTRUCT) 69 69 Imports System.Runtime.InteropServices 70 70 … … 77 77 Dim hwnd = CreateWindowEx(.dwExStyle, .lpszClass, .lpszName, .style, 78 78 .x, .y, .cx, .cy, .hwndParent, .hMenu, .hInstance, .lpCreateParams) 79 createImpl = hwnd <> 0 79 If hwnd = 0 Then 80 ActiveBasic.Windows.ThrowByWindowsError(GetLastError()) 81 End If 80 82 End With 81 End Function83 End Sub 82 84 83 85 '-------------------------------- … … 125 127 */ 126 128 Sub StartWndProc() 127 Dim t = This '#177対策 128 AddMessageEvent(WM_ERASEBKGND, AddressOf(t.OnEraseBackground)) 129 Dim md = New MessageEventHandler(AddressOf(t.OnMouseDownBase)) 129 AddMessageEvent(WM_ERASEBKGND, AddressOf(OnEraseBackground)) 130 Dim md = New MessageEventHandler(AddressOf(OnMouseDownBase)) 130 131 AddMessageEvent(WM_LBUTTONDOWN, md) 131 132 AddMessageEvent(WM_RBUTTONDOWN, md) 132 133 AddMessageEvent(WM_MBUTTONDOWN, md) 133 134 AddMessageEvent(WM_XBUTTONDOWN, md) 134 Dim mu = New MessageEventHandler(AddressOf( t.OnMouseUpBase))135 Dim mu = New MessageEventHandler(AddressOf(OnMouseUpBase)) 135 136 AddMessageEvent(WM_LBUTTONUP, mu) 136 137 AddMessageEvent(WM_RBUTTONUP, mu) 137 138 AddMessageEvent(WM_MBUTTONUP, mu) 138 139 AddMessageEvent(WM_XBUTTONUP, mu) 139 Dim mb = New MessageEventHandler(AddressOf( t.OnMouseDblClkBase))140 Dim mb = New MessageEventHandler(AddressOf(OnMouseDblClkBase)) 140 141 AddMessageEvent(WM_LBUTTONDBLCLK, mu) 141 142 AddMessageEvent(WM_RBUTTONDBLCLK, mu) … … 143 144 AddMessageEvent(WM_XBUTTONDBLCLK, mu) 144 145 145 AddMessageEvent(WM_MOUSELEAVE, AddressOf(t.OnMouseLeaveBase)) 146 AddMessageEvent(WM_PAINT, AddressOf(t.OnPaintBase)) 147 AddMessageEvent(WM_KEYDOWN, AddressOf(t.OnKeyDownBase)) 148 ' AddMessageEvent(WM_CHAR, AddressOf(t.OnChar)) 149 AddMessageEvent(WM_CREATE, AddressOf(t.OnCreateBase)) 146 AddMessageEvent(WM_MOUSEMOVE, AddressOf(OnMouseMoveBase)) 147 AddMessageEvent(WM_MOUSELEAVE, AddressOf(OnMouseLeaveBase)) 148 AddMessageEvent(WM_PAINT, AddressOf(OnPaintBase)) 149 AddMessageEvent(WM_KEYDOWN, AddressOf(OnKeyDownBase)) 150 ' AddMessageEvent(WM_CHAR, AddressOf(OnChar)) 151 AddMessageEvent(WM_CREATE, AddressOf(OnCreateBase)) 150 152 End Sub 151 153 152 154 Sub OnEraseBackground(sender As Object, e As MessageEventArgs) 153 Dim rc As RECT 154 Dim r = GetClientRect(hwnd, rc) 155 Dim rc = ClientRect 155 156 FillRect(e.WParam As HDC, rc, (COLOR_3DFACE + 1) As HBRUSH) 156 157 e.LResult = TRUE … … 197 198 Sub OnPaintBase(sender As Object, e As MessageEventArgs) 198 199 Dim ps As PAINTSTRUCT 199 BeginPaint( hwnd,ps)200 BeginPaint(ps) 200 201 Try 201 202 OnPaintDC(New PaintDCEventArgs(ps.hdc, ps.rcPaint)) 202 203 Finally 203 EndPaint( hwnd,ps)204 EndPaint(ps) 204 205 End Try 205 206 End Sub … … 272 273 ' インスタンスメンバ変数 273 274 Private 274 hwnd As HWND275 275 /*! 276 276 @brief マウスカーソルがクライアント領域に入っているかどうかのフラグ … … 291 291 Imports System.Runtime.InteropServices 292 292 293 Dim rThis = Control.FromHWndCore(hwnd)293 Dim rThis = FromHWndCore(hwnd) 294 294 If IsNothing(rThis) Then 295 295 Dim gchValue = TlsGetValue(tlsIndex) As LONG_PTR … … 306 306 End If 307 307 rThis.hwnd = hwnd 308 SetProp(hwnd, PropertyInstance As ULONG_PTR As PCSTR, gchValue As HANDLE)308 rThis.Prop[PropertyInstance] = gchValue As HANDLE 309 309 End If 310 310 WndProcFirst = rThis.WndProc(msg, wp, lp) 311 311 If msg = WM_NCDESTROY Then 312 Dim gchValue = GetProp(hwnd, PropertyInstance As ULONG_PTR As PCTSTR) As ULONG_PTR312 Dim gchValue = rThis.Prop(PropertyInstance) As ULONG_PTR 313 313 If gchValue <> 0 Then 314 Dim gch = GCHandle.FromIntPtr(gchValue) 315 gch.Free() 314 GCHandle.FromIntPtr(gchValue).Free() 316 315 End If 317 316 End If … … 320 319 321 320 *InstanceIsNotFound 322 OutputDebugString( "ActiveBasic.Windows.UI.Control.WndProcFirst: The attached instance is not found.")321 OutputDebugString(Ex"ActiveBasic.Windows.UI.Control.WndProcFirst: The attached instance is not found.\r\n") 323 322 WndProcFirst = DefWindowProc(hwnd, msg, wp, lp) 324 323 End Function … … 408 407 End Class 409 408 410 Class Form '仮411 Inherits Control412 Protected413 Override Sub GetCreateStruct(ByRef cs As CREATESTRUCT)414 With cs415 .lpCreateParams = 0416 '.hInstance417 .hMenu = 0418 .hwndParent = 0419 .cy = CW_USEDEFAULT420 .cx = CW_USEDEFAULT421 .y = CW_USEDEFAULT422 .x = CW_USEDEFAULT423 .style = WS_OVERLAPPEDWINDOW424 .lpszName = ""425 '.lpszClass426 .dwExStyle = 0427 End With428 End Sub429 Public430 431 Override Function WndProc(msg As DWord, wp As WPARAM, lp As LPARAM) As LRESULT432 WndProc = 0433 Select Case msg434 Case Else435 WndProc = Super.WndProc(msg, wp, lp)436 End Select437 End Function438 End Class439 440 409 End Namespace 'UI 441 410 End Namespace 'Widnows 442 411 End Namespace 'ActiveBasic 443 444 '----------445 'テスト実行用446 447 Imports ActiveBasic.Windows.UI448 449 'OleInitialize()450 Control.Initialize(GetModuleHandle(0))451 452 Class MyForm453 Inherits Form454 Public455 Sub MyForm()456 Dim f = This457 f.AddMessageEvent(WM_DESTROY, AddressOf (f.Destory))458 f.AddPaintDC(AddressOf (f.Paint))459 End Sub460 461 Sub Destory(sender As Object, e As EventArgs)462 OutputDebugString(Ex"Destory\r\n")463 PostQuitMessage(0)464 End Sub465 466 Sub Paint(sender As Object, e As PaintDCEventArgs)467 TextOut(e.Handle, 10, 10, "Hello world!", 12)468 End Sub469 End Class470 471 Dim f = New MyForm472 f.Create()473 ShowWindow(f.Handle, SW_SHOW)474 475 Dim m As MSG476 Do477 Dim ret = GetMessage(m, 0, 0, 0)478 If ret = 0 Then479 Exit Do480 ElseIf ret = -1 Then481 ExitProcess(-1)482 End If483 484 TranslateMessage(m)485 DispatchMessage(m)486 Loop487 488 f = Nothing489 System.GC.Collect()490 491 Control.Uninitialize()492 'OleUninitialize()493 494 End
Note:
See TracChangeset
for help on using the changeset viewer.