Buchempfehlung
Windows System Programming
Windows System Programming
Das Kompendium liefert viele interessante Informationen zur Windows-Programmierung auf Englisch. [Mehr Infos...]
FreeBASIC-Chat
Es sind Benutzer im FreeBASIC-Chat online.
(Stand:  )
FreeBASIC bei Twitter
Twitter FreeBASIC-Nachrichten jetzt auch über Twitter erhalten. Follow us!

fb:porticula NoPaste

Info
Info / Hilfe
Liste
Übersicht / Liste
Neu
Datei hochladen
Suche
Quellcode suchen
Download
Dateidownload

Muh-Buttons-Taschenrechner (Primitiv)

Uploader:MitgliedThe_Muh
Datum/Zeit:20.11.2008 21:32:12

declare sub create_button(text as string,textfarbe as integer,x as integer, y as integer, hoehe as integer,rahmen as integer,farbe as integer = 15, link as any ptr)



type button_type

    x as integer

    y as integer

    hoehe as integer

    breite as integer

    farbe as integer

    rahmen as integer

    text as string

    textfarbe as integer

    link as any ptr

end type



dim shared button() as button_type



sub refresh_buttons()

    dim i as integer

    for i = 1 to ubound(button)

        line (button(i).x  ,button(i).y  )-(button(i).x+button(i).breite,button(i).y+button(i).hoehe),button(i).rahmen, BF

        line (button(i).x+1,button(i).y+1)-(button(i).x+button(i).breite-1,button(i).y+button(i).hoehe-1),button(i).farbe,BF

        draw string (button(i).x+4,button(i).y+(button(i).hoehe/2) -4),button(i).text,button(i).textfarbe

    next

end sub



sub create_button(text as string,textfarbe as integer,x as integer, y as integer, hoehe as integer,rahmen as integer,farbe as integer = 15, link as any ptr)

    dim i as integer

    dim breite as integer

    breite = len(text)*8 +8

    line (x,y)-(x+breite,y+hoehe),rahmen, BF

    line (x+1,y+1)-(x+breite-1,y+hoehe-1),farbe,BF

    draw string (x+5,y+(hoehe/2) -4),text,textfarbe

    redim preserve button(ubound(button)+1)

    i = ubound(button)

    button(i).x = x

    button(i).y = y

    button(i).hoehe = hoehe

    button(i).breite = breite

    button(i).farbe = farbe

    button(i).rahmen = rahmen

    button(i).text = text

    button(i).textfarbe = textfarbe

    button(i).link = link

end sub



sub click_button(mx as integer, my as integer)

    dim dummy as any ptr

    for i as integer = 1 to ubound(button)

        if mx >= button(i).x and mx <= (button(i).x + button(i).breite)  and _

        my >= button(i).y and my <= (button(i).y + button(i).hoehe) then

            dim by_click as sub = button(i).link

            by_click()

            exit sub

        end if

    next

end sub





'---

'Ab hier das Beispiel:

'---



dim as integer mx,my,taste

dim shared value as  single

dim shared value2 as single

dim shared rechenzeichen as byte



sub foo1()

    if len(str(value)) = 10 then exit sub

    value = value * 10 + 1

end sub



sub foo2()

    if len(str(value)) = 10 then exit sub

    value = value * 10 + 2

end sub



sub foo3()

    if len(str(value)) = 10 then exit sub

    value = value * 10 + 3

end sub



sub foo4()

    if len(str(value)) = 10 then exit sub

    value = value * 10 + 4

end sub



sub foo5()

    if len(str(value)) = 10 then exit sub

    value = value * 10 + 5

end sub



sub foo6()

    if len(str(value)) = 10 then exit sub

    value = value * 10 + 6

end sub



sub foo7()

    if len(str(value)) = 10 then exit sub

    value = value * 10 + 7

end sub



sub foo8()

    if len(str(value)) = 10 then exit sub

    value = value * 10 + 8

end sub



sub foo9()

    if len(str(value)) = 10 then exit sub

    value = value * 10 + 9

end sub



sub foo0()

    if len(str(value)) = 10 then exit sub

    value = value * 10 + 0

end sub



sub fooplus()

    if len(str(value)) = 10 then exit sub

    rechenzeichen = 1

    if value <> 0 then

        value2 = value

        value = 0

    end if

end sub



sub foominus()

    rechenzeichen = 2

    if value <> 0 then

        value2 = value

        value = 0

    end if

end sub



sub foomal()

    if len(str(value)) = 10 then exit sub

    rechenzeichen = 3

    if value <> 0 then

        value2 = value

        value = 0

    end if

end sub



sub foogeteilt()

    rechenzeichen = 4

    if value <> 0 then

        value2 = value

        value = 0

    end if

end sub



sub foogleich()

    select case rechenzeichen

    case 1

        value = value2 + value

    case 2

        value = value2 - value

    case 3

        value = value2 * value

    case 4

        value = value2 / value

    end select

    value2 = 0

end sub



sub foodelete()

    value = 0

end sub





sub foo()

    end

end sub



screenres 150,140

color 0,15

cls

'1. Parameter = Text                                 = String

'2. Parameter = Textfarbe                            = Integer

'3. Parameter = X-Koordinate                         = Integer

'4. Parameter = Y-Koordinate                         = Integer

'5. Parameter = Hoehe des Buttons                    = Integer

'6. Parameter = Hintergrundfarbe des Buttons         = Integer

'7. Parameter = Rahmenfarbe des Buttons              = Integer

'8. Parameter = Sub die bei klick aufgerufen wird    = Pointer auf Sub



create_button(string(10," "),0,14,10,15,0,15,@foo)

create_button("1",0,10,30,15,0,15,@foo1)

create_button("2",0,30,30,15,0,15,@foo2)

create_button("3",0,50,30,15,0,15,@foo3)

create_button("4",0,10,50,15,0,15,@foo4)

create_button("5",0,30,50,15,0,15,@foo5)

create_button("6",0,50,50,15,0,15,@foo6)

create_button("7",0,10,70,15,0,15,@foo7)

create_button("8",0,30,70,15,0,15,@foo8)

create_button("9",0,50,70,15,0,15,@foo9)

create_button("0",0,30,90,15,0,15,@foo0)

create_button("+",0,70,30,15,0,15,@fooplus)

create_button("-",0,70,50,15,0,15,@foominus)

create_button("*",0,70,70,15,0,15,@foomal)

create_button("/",0,70,90,15,0,15,@foogeteilt)

create_button("=",0,90,30,35,0,15,@foogleich)

create_button("Reset",0,58,110,15,0,15,@foodelete)



create_button("Ende",0,10,110,15,0,15,@foo)

do

    getmouse mx,my,,taste

    if taste = 1 then

        click_button(mx,my)

        while taste = 1

            getmouse mx,my,,taste

            sleep 1

        wend

    end if

    sleep 10

    cls

    button(1).text = str(value)

    refresh_buttons

loop while inkey = ""



sleep