Ignore:
Timestamp:
Jul 17, 2008, 11:20:10 PM (16 years ago)
Author:
イグトランス (egtra)
Message:

Buttonの追加。WM_COMMANDから子のClickイベントを発生させる仕組みの追加など。

File:
1 edited

Legend:

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

    r547 r551  
    22
    33#require <Classes/ActiveBasic/Windows/UI/Control.ab>
     4#require <Classes/ActiveBasic/Windows/UI/Button.ab>
    45
    56Namespace ActiveBasic
     
    1213@author Egtra
    1314*/
     15
    1416Class Form
    1517    Inherits Control
     18Public
     19    Sub Form()
     20        AddMessageEvent(WM_COMMAND, AddressOf (OnCommand))
     21    End Sub
     22
    1623Protected
    1724    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
    3226    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
    3341#include "FormEvent.sbp"
    3442End Class
     
    4250
    4351#require <Classes/ActiveBasic/Windows/UI/Application.ab>
     52#require <Classes/ActiveBasic/Windows/UI/Button.ab>
    4453
    4554Imports ActiveBasic.Windows.UI
     
    4857Control.Initialize(GetModuleHandle(0))
    4958
     59Sub Paint(sender As Object, e As PaintDCArgs)
     60    TextOut(e.Handle, 10, 10, "Hello world!", 12)
     61End Sub
     62
    5063Class MyForm
    5164    Inherits Form
    5265Public
    5366    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"
    5970    End Sub
    6071
    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()
    6478    End Sub
    6579
    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")
    7682    End Sub
    7783
     
    8187Dim f = New MyForm
    8288f.Create()
     89f.Text = "Hello"
     90
     91Dim b = New Button
     92b.Create(f)
     93b.Move(50, 50, 100, 100)
     94b.Text = "Ok"
     95b.AddClick(AddressOf(f.OnClick))
     96
    8397Application.Run(f)
    8498f = Nothing
     
    89103
    90104End
    91 
Note: See TracChangeset for help on using the changeset viewer.