Asm example 32 / 64 bit

Started by Frank Brübach, August 22, 2024, 03:57:20 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Frank Brübach

Gui example: frank's calculator

' -- halProment-> franks calculator
' -- 23.03.2024, 22.08.2024, translated of my own freebasic example ;)
'
'
take promgui

% IDB_BUTTON 100
sys hWndStdButton

% IDC_OWNERDRAWN  1000
sys hWndClrButton

% IDC_TRANSLATE 1001
sys hWndClrButton2

% IDC_EDIT 1002
sys myEdit

% IDC_EDIT2 1003
sys myEdit2

MainWindow 440, 320 , WS_OVERLAPPEDWINDOW

' Constants for controls
% IDC_NUM1 = 1001
% IDC_NUM2 = 1002
% IDC_RESULT = 1003
% IDC_ADD = 2001
% IDC_SUBTRACT = 2002
% IDC_MULTIPLY = 2003
% IDC_DIVIDE = 2004
% IDC_CALCULATE = 2005


Function WndProc(pro hwnd, uint MainMsg, pro wParam, lParam) as pro callback
    select case MainMsg
        case WM_CREATE
            SetWindowText(hwnd, "frank's Translator")

            sys hInstance = GetWindowLongPtr(hWnd, GWL_HINSTANCE)

            ' Create edit boxes for numbers
            CreateWindowEx(0, "EDIT", "", WS_CHILD Or WS_VISIBLE Or WS_BORDER Or ES_MULTILINE Or ES_AUTOHSCROLL, 50, 50, 100, 20, hWnd, IDC_NUM1, GetModuleHandle(Null), ByVal Null)
            CreateWindowEx(0, "EDIT", "", WS_CHILD Or WS_VISIBLE Or WS_BORDER Or ES_MULTILINE Or ES_AUTOHSCROLL, 200, 50, 100, 20, hWnd, IDC_NUM2, GetModuleHandle(Null), ByVal Null)
           
            ' Create radio buttons for operations
            CreateWindowEx(0, "BUTTON", "+", WS_CHILD Or WS_VISIBLE Or BS_AUTORADIOBUTTON, 50, 100, 50, 20, hWnd, IDC_ADD, GetModuleHandle(Null), ByVal Null)
            CreateWindowEx(0, "BUTTON", "-", WS_CHILD Or WS_VISIBLE Or BS_AUTORADIOBUTTON, 100, 100, 50, 20, hWnd, IDC_SUBTRACT, GetModuleHandle(Null), ByVal Null)
            CreateWindowEx(0, "BUTTON", "*", WS_CHILD Or WS_VISIBLE Or BS_AUTORADIOBUTTON, 150, 100, 50, 20, hWnd, IDC_MULTIPLY, GetModuleHandle(Null), ByVal Null)
            CreateWindowEx(0, "BUTTON", "/", WS_CHILD Or WS_VISIBLE Or BS_AUTORADIOBUTTON, 200, 100, 50, 20, hWnd, IDC_DIVIDE, GetModuleHandle(Null), ByVal Null)
           
            ' Create button for calculation
            CreateWindowEx(0, "BUTTON", "=", WS_CHILD Or WS_VISIBLE Or BS_AUTORADIOBUTTON, 250, 100, 50, 20, hWnd, IDC_CALCULATE, GetModuleHandle(Null), ByVal Null)
           
            ' Create edit box for result
            CreateWindowEx(0, "EDIT", "", WS_CHILD Or WS_VISIBLE Or WS_BORDER Or ES_MULTILINE Or ES_AUTOHSCROLL Or ES_READONLY, 50, 150, 250, 20, hWnd, IDC_RESULT, GetModuleHandle(Null), ByVal Null)
           
            ' Set default operation to addition
            SendDlgItemMessage(hWnd, IDC_ADD, BM_SETCHECK, BST_CHECKED, 0)

   Case WM_COMMAND
    If HIWORD(wParam) = BN_CLICKED Then
        dim operation As String
 
        ' Get selected operation
        Select Case LOWORD(wParam)
            Case IDC_ADD
                operation = "+"
            Case IDC_SUBTRACT
                operation = "-"
            Case IDC_MULTIPLY
                operation = "*"
            Case IDC_DIVIDE
                operation = "/"
            Case IDC_CALCULATE
                Dim num1 As Double
                Dim num2 As Double
                Dim result As Double
                dim as string snum1=space(21)
                dim as string snum2=space(21)
                dim as string sresult=space(21)
               
                GetDlgItemText(hWnd, IDC_NUM1, strptr(snum1), 20)
                GetDlgItemText(hWnd, IDC_NUM2, strptr(snum2), 20)
                    num1= val(snum1)
                    num2= val(snum2)

                ' Perform calculation based on selected operation
                Select Case operation
                    Case "+"
                        result = num1 + num2
                    Case "-"
                        result = num1 - num2
                    Case "*"
                        result = num1 * num2
                    Case "/"
                        If num2 <> 0 Then
                            result = num1 / num2
                        Else
                            Print "Cannot divide by zero! Error"
                            Exit Function
                        End If
                    case else
                    ''default addition otherwise result = zero
                    result = num1 + num2
                End Select
                sresult=str(result)
                ' Display result
                SetDlgItemText(hWnd, IDC_RESULT, Strptr(sresult))
        End Select
    End If
 
        Case WM_CLOSE
            DestroyWindow(hWnd)
        Case WM_DESTROY
            PostQuitMessage(0)
        Case Else
            Return DefWindowProc(hWnd, MainMsg, wParam, lParam)
    End Select
    Return 0
End Function
' ends

Frank Brübach

Parse example again updated and alternative

' new parse example halProment, april-august2024, frank bruebach
' alternative example, 22-23/08/2024
'
take kons 'same like: #include konsole
pindex 1

function Parse(pstring expression, delimiter as string= ",", int index ) as pstring
    int count = 1
    pstring temp = ""
    pro d = 1
    pro f = 0
    pro i = 0
    pstring z ""
    do
        i = instr(d, expression, delimiter)
        if i > 0 then
            f = i
            if count = index then
                exit do
            end if
            count += 1
            f += Len(delimiter)
            d = f
        elseif count = index then
            f = Len(expression) + 1
        end if
    loop until i = 0
     return MID(expression,d, f-d)
        
end function

printl "parse example test"
printl ""
pstring a,b,c
a = parse("one,two,three", ,2) '' ok -> returns "two" 

b = parse("xyz", , 1)            ' ok -> returns "xyz"

c = parse("xx1x","x", 3)         ' ok -> returns "1"

Printl "'" + a + "'"
Printl "'" + b + "'"
Printl "'" + c + "'"

wait

Frank Brübach

#17
'  infos, news
'  halProment Basic, update 6, 22. august 2024, time periode march-august 2024, by frank bruebach, germany

'  using at own risc, have fun :-)

'  halProment.Dll updated, halpromIde24 IDE updated.
'  compiling 32, 64 bit possible
'  new ones: GUI example and OpgenGL examples (beginning, 3 expl), dim variable suffixes, print alternatives, macros,
   parse, parser examples, listview combobox button etcpp
 
'  as I was ill for some weeks in summer time , my left index finger was broken, I couldn't
'  make any progress, sorry
'  more updates will come, all works in progress, regards, frank
'  if you have any question or wishes please ask or contact me via the board here

' 22.+23. August 2024, regards frank
' PS: No AI was involved for halProment ;-)

Frank Brübach

#18
Class example 3: salary

Code]
' new: simple class example3 with data
' by frank bruebach, halProment, 16-04-2024, 24-08-2024
'
' halProment Class example3
'
class Employee
    pstring names2
    pstring depts2
    pro salarys2

    '-------------------/
    method constructor(pstring name1="Diana", pstring dept1="Computer Lab", pro salary=2000)
        names2 = name1
        depts2 = dept1
        salarys2 = salary
        p? "construct!"
    End method

    method destructor()
    '-------------------/
       'destroy strings
        del names2
        del depts2
      del salarys2
        p? "destruct!"
    end method

    method act() as pstring
    '-----------------------/
        return names2 ",  " depts2 ", " salarys2
    end method

    method act2() as pstring
    '-----------------------/
        return names2 ",  " depts2 ", " salarys2+700
    end method

end class
'-------------------/

new Employee diana("Diana","Computer Lab", 2000)
p? diana.act
p? diana.act2
del diana

' ends

Frank Brübach

Macro new examples vs functions

' -- macro vs function, june,july-august 2024, halProment
' -- new macros implemented with three params go
'
pstring s="Hello macros and functions "
p? s
'
'-- test 1:
'
' macro with three params!
'-- > new! ---------------------- // go
macro abc(one,two,three) msgbox one two three
abc("Hello Avengers ","Hello x-Men ", "Hello Batman") ' result: Hello Avengers Hello x-Men Hello Batman 
'-- > new! ---------------------- //

'-- test 2:  ------------ //
function abcd(p1 as string,p2 as string, p3 as string) as string
print p1
print p2
print p3
function = 1
end function

abcd("Hello diana3 ","Hello george3 ","Hello paul3 ")

'-- test 3:  ------------ //
macro av(z1,z2)
print z1+z2
end macro

av(2,4) '6

'-- test 3a: ------------ //
macro av(z1,z2)
print z1+z2
' end macro not needed

av(4,8) '12

'-- test 4:  ------------ //
function one(a as pro) as long
return print a*a
end function

function two(b as pro) as long
return print b*b
end function

one(4) two(6) '36 ' 16 '' 52
'one(4) + two(6) '36 ' 16 '' 52

function one4() as pro
int a=1
return print a*a
end function

function two4() as pro
int b=1
return print b*b
end function

'-- test 5:  ------------ //
macro one2(a as pro)
print a*a
end macro

macro two2(b as pro)
print b*b
end macro

one2(4) + two2(6) '36 ' 16 '' 52
' ends