Bay Six Software Forum Index Bay Six Software
Beyond the Basics
 
 FAQFAQ   SearchSearch   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

WMLiberty Demos - Dynamic Buttons
 
WMLiberty -> Demos -> API-Created Controls -> Dynamic buttons (Download)

Code:
' Dynamic Buttons Demo
' By Brent D. Thorn, 2006
' PUBLIC DOMAIN

    Global g.hInstance
    Global g.nButtons

    CallDLL #kernel32, "GetModuleHandleA", _
        _NULL As ULong, _
        g.hInstance As ULong

    g.nButtons = 12

    Dim hwndButtons(g.nButtons)

    Open "WMLiberty" For DLL As #wmlib

    UpperLeftX = Int((DisplayWidth-WindowWidth)/2)
    UpperLeftY = Int((DisplayHeight-WindowHeight)/2)

    StaticText  #demo.stc,"",4,4,300,20

    Open "Dynamic Buttons" For Window As #demo

    #demo "TrapClose demo.Close"

    hWnd = HWnd(#demo)
    Callback lpfn, OnCommand(ULong,ULong,ULong,ULong),Long

    CallDLL #wmlib, "SetWMHandler", _
        hWnd As ULong, _
        _WM_COMMAND As ULong, _
        lpfn As ULong, _
        -1 As Long, _
        ret As Long

    CallDLL #gdi32, "GetStockObject", _
        _DEFAULT_GUI_FONT As Long, _
        hFont As ULong

    dwStyle = _WS_CHILD Or _WS_VISIBLE Or _BS_PUSHBUTTON
    nWidth = Int((WindowWidth-16) / 3)
    nHeight = 25
    x = 4
    y = 25

    For b = 1 To g.nButtons
        hwndButtons(b) = _
            CreateWindowEx(0, "BUTTON", "Button #"+Str$(b), _
                dwStyle, x, y, nWidth, nHeight, _
                hWnd, 0, g.hInstance, 0)
        Call SendMessageLong hwndButtons(b), _WM_SETFONT, hFont, 1
        x = x + nWidth
        If x+nWidth > WindowWidth Then
            x = 4
            y = y + nHeight
        End If
    Next

    Call DoEvents

Sub DoEvents
[localLoop]
    Scan
    CallDLL #kernel32, "Sleep", 50 As Long, ret As Void
    GoTo [localLoop]
End Sub

Sub demo.Close me$
    Close #me$
    Close #wmlib
    End
End Sub

Function OnCommand( hWnd, uMsg, wParam, lParam )
    Select Case HIWORD(wParam)
    Case _BN_CLICKED
        For b = 1 To g.nButtons
            If hwndButtons(b) = lParam Then Exit For
        Next
        If b <= g.nButtons Then
            #demo.stc "You clicked Button #";b;"."
        End If
    End Select
End Function

Function CreateWindowEx( StyleEx, Class$, Text$, Style, X, Y, Width, Height, Parent, ID, Instance, Param )
    CallDLL #user32, "CreateWindowExA", _
        StyleEx As ULong, Class$ As Ptr, Text$ As Ptr, Style As ULong, _
        X As Long, Y As Long, Width As ULong, Height As ULong, _
        Parent As ULong, ID As ULong, Instance As ULong, _
        Param As ULong, CreateWindowEx As ULong
End Function

Sub SendMessageLong hWnd, uMsg, wParam, lParam
    CallDLL #user32, "SendMessageA", _
        hWnd As ULong, uMsg As ULong, _
        wParam As ULong, lParam As ULong, _
        ret As Long
End Sub

Function HIWORD( dw )
    HIWORD = (dw And 4294901760) / 65536
End Function

Function LOWORD( dw )
    LOWORD = (dw And 65535)
End Function

Powered by phpBB © 2001, 2005 phpBB Group