Ignore:
Timestamp:
Sep 29, 2008, 1:02:27 AM (16 years ago)
Author:
イグトランス (egtra)
Message:

Button.OnClickの仕組みを汎用的(WM_COMMAND全般)に。WndProcなどをProtectedへ。

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/Control.ab

    r615 r637  
    138138        registerStandardEvent()
    139139        AssociateHWnd(hwndNew)
     140    End Sub
     141
     142    Sub BeginSubclass()
     143        throwIfNotCreated()
    140144        prevWndProc = SetWindowLongPtr(GWLP_WNDPROC, AddressOf(WndProcFirst) As LONG_PTR) As WNDPROC
    141145    End Sub
     
    144148    Sub throwIfAlreadyCreated()
    145149        If hwnd <> 0 Then
    146             Throw New System.InvalidOperationException("Window already created.")
     150            Throw New System.InvalidOperationException("Window is already created.")
     151        End If
     152    End Sub
     153
     154    Sub throwIfNotCreated()
     155        If hwnd = 0 Then
     156            Throw New System.InvalidOperationException("Window is not already created.")
    147157        End If
    148158    End Sub
     
    150160'--------------------------------
    151161' ウィンドウプロシージャ
    152 'Protected
    153 Public
     162
     163Protected
    154164    Virtual Function WndProc(msg As DWord, wp As WPARAM, lp As LPARAM) As LRESULT
     165        If Not ProcessMessage(msg, wp, lp, WndProc) Then
     166            WndProc = DefWndProc(msg, wp, lp)
     167        End If
     168    End Function
     169
     170    Virtual Function DefWndProc(msg As DWord, wp As WPARAM, lp As LPARAM) As LRESULT
     171        If prevWndProc Then
     172            DefWndProc = CallWindowProc(prevWndProc, hwnd, msg, wp, lp)
     173        Else
     174            DefWndProc = DefWindowProc(hwnd, msg, wp, lp)
     175        End If
     176    End Function
     177Protected
     178    Function ProcessMessage(msg As DWord, wp As WPARAM, lp As LPARAM, ByRef lr As LRESULT) As Boolean
    155179        Dim h = Nothing As MessageHandler
    156180        Dim b = messageMap.TryGetValue(Hex$(msg), h)
     
    160184                h(This, a)
    161185                If a.Handled Then
    162                     WndProc = a.LResult
     186                    lr = a.LResult
     187                    ProcessMessage = True
    163188                    Exit Function
    164189                End If
    165190            End If
    166191        End If
    167         WndProc = DefWndProc(msg, wp, lp)
    168     End Function
    169 
    170     Virtual Function DefWndProc(msg As DWord, wp As WPARAM, lp As LPARAM) As LRESULT
    171         If prevWndProc Then
    172             DefWndProc = CallWindowProc(prevWndProc, hwnd, msg, wp, lp)
    173         Else
    174             DefWndProc = DefWindowProc(hwnd, msg, wp, lp)
    175         End If
    176     End Function
    177 
     192        ProcessMessage = False
     193    End Function
    178194Private
    179195    Static Function makeKeysFormMsg(e As MessageArgs) As Keys
     
    428444    */
    429445    Sub AssociateHWnd(hwndNew As HWND)
    430         hwnd = hwndNew
     446        SetHWnd(hwndNew)
    431447        Prop[PropertyInstance] = ObjPtr(This) As HANDLE
    432448        comImpl.AddRef()
     
    513529    Static Sub Initialize(hinst As HINSTANCE)
    514530        tlsIndex = TlsAlloc()
     531        If tlsIndex = TLS_OUT_OF_INDEXES Then
     532            ThrowWithLastError("Control.Initialize: TlsAlloc failed.")
     533        End If
    515534        hInstance = hinst
    516535        hmodComctl = LoadLibrary("comctl32.dll")
     
    519538        Dim PropertyInstanceString = WindowClassName + " " + Hex$(GetCurrentProcessId())
    520539        PropertyInstance = GlobalAddAtom(ToTCStr(PropertyInstanceString))
     540        If PropertyInstance = 0 Then
     541            ThrowWithLastError("Control.Initialize: GlobalAddAtom failed.")
     542        End If
    521543
    522544        Dim wcx As WNDCLASSEX
     
    537559        atom = RegisterClassEx(wcx)
    538560        If atom = 0 Then
    539             Dim buf[1023] As TCHAR
    540             wsprintf(buf, Ex"ActiveBasic.Windows.UI.Control.Control: RegisterClasseEx failed. Error code: &h%08X\r\n", GetLastError())
    541             OutputDebugString(buf)
    542             Debug
    543             ExitThread(0)
     561            ThrowWithLastErrorNT("Control.Initialize: RegisterClasseEx failed.")
    544562        End If
    545563    End Sub
     
    561579End Class
    562580
     581/*!
     582@brief WM_COMMANDで通知を行うコントロールの基底クラス
     583@date 2008/08/28
     584@auther Egtra
     585親がWM_COMMANDを受け取ったら、RaiseCommandEventを呼ぶことを意図している。
     586(Formで実装済み)
     587*/
     588Class WmCommandControl
     589    Inherits Control
     590Public
     591    Abstract Function RaiseCommandEvent(notificationCode As Word) As Boolean
     592End Class
     593
    563594End Namespace 'UI
    564595End Namespace 'Widnows
Note: See TracChangeset for help on using the changeset viewer.