Scintilla/A simple sample using Scintilla from Visual Basic

Last-modified: 2008-02-24 (日) 10:09:51

Visual BasicからScintillaを使う簡単なサンプル

Private Const WS_CHILD = &H40000000
Private Const WS_VISIBLE = &H10000000
Private Const WS_EX_CLIENTEDGE = &H200
Private Const SCI_START = 2000
Private Const SCI_ADDTEXT = SCI_START + 1
Private Const SCI_SETSELBACK = SCI_START + 68
Private Declare Function CreateWindowEx Lib "USER32" _
    Alias "CreateWindowExA" (ByVal dwExStyle As Long, _
    ByVal lpClassName As String, _
    ByVal lpWindowName As String, _
    ByVal dwStyle As Long, ByVal x As Long, _
    ByVal y As Long, ByVal nWidth As Long, _
    ByVal nHeight As Long, ByVal hWndParent As Long, _
    ByVal hMenu As Long, ByVal hInstance As Long, _
    lpParam As Any) As Long
Private Declare Function LoadLibrary Lib "Kernel32" _
    Alias "LoadLibraryA" (ByVal lpLibFileName As String) _
    As Integer
Private Declare Function SendMessage Lib "USER32" _
    Alias "SendMessageA" (ByVal hWnd As Long, _
    ByVal msg As Long, ByVal wp As Long, _
    ByVal lp As Long) As Long
Private Declare Function SendMessageString Lib "USER32" _
    Alias "SendMessageA" (ByVal hWnd As Long, _
    ByVal msg As Long, ByVal wp As Long, _
    ByVal lp As Any) As Long
Private Declare Function SetWindowPos Lib "USER32" _
    (ByVal hWnd As Long, ByVal m As Long, _
    ByVal left As Long, ByVal top As Long, _
    ByVal width As Long, ByVal height As Long, _
    ByVal flags As Long) As Long
Dim sci As Long
Private Sub Form_Load()
    LoadLibrary ("SciLexer.DLL")
    sci = CreateWindowEx(WS_EX_CLIENTEDGE, "Scintilla", _
        "TEST", WS_CHILD Or WS_VISIBLE, 0, 0, 200, 200, _
        Form1.hWnd, 0, App.hInstance, 0)
    SendMessage sci, SCI_SETSELBACK, 1, &HFFEFD0
    SendMessageString sci, SCI_ADDTEXT, 16, "Hello non-Python"
End Sub
Private Sub Form_Resize()
    SetWindowPos sci, 0, 2, 2, Form1.width / 15 - 12, _
        Form1.height / 15 - 30, 0
End Sub