Version 10

Started by Zlatko Vid, April 11, 2023, 08:00:20 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Zlatko Vid

micro(A) version 10

This is some sort of breakthrough for me and for micro(A) interpreter.
Event driven programming is in basic very simply once you get it how work
and on Windows is crucial thing.
So to short story i finally add event IDOK using WM_COMMAND message to
enable testing IDOK constant which work by pressing key ENTER out of
WM_KEYDOWN message ,so on this process i can get text from edit control
for testing i just add print text "IDOK" on left side of window each time
ENTER key is pressed which is important for some type of programs like
quiz or textual based programs ..or similar

'create input box ( edit control used for input text)
ptr hbox ,hImg,hb
ptr wmKeyDown, wmCommand
str sText, cStr
var wp, tx ,ty
'LoadImage(0, strRes, imgType, imgW, imgH, cFlag)
LoadImg hImg,"microgirls.bmp"  ,0, 264,236, 24
wcolor 200,190,200 : swap
cStr = "test text"
'syntax INPUTBOX handle , x,y,w,h,text
ShowImgT hImg,400,80,264,236 :swap
INPUTBOX hbox , 10, 350, 300, 23 , "micro(A)"
print 10,10,"Testing IDOK event under WM_COMMAND message in micro(A) v10"
GETTEXT hbox , sText
print  10,400, sText : swap
ty = 50

'events.................
WinMsg wmCOMMAND
'in this case hWparam is LoWord(wParam) -> control ID
hWparam wp

'if is -> IDOK / which is 1
if wp = 1
  tx = 10 : ty = ty + 20
  print tx,ty,"IDOK"
  swap
endif

EndWm
'..................


func get_text()
    GETTEXT hbox, sText
    rect 10,400,100,23
    fcolor 200,230,250 : print  10,400, sText : swap
 
endfn
  •  

Zlatko Vid

this part of o2 code execute this event:

CASE WM_COMMAND
         controlID = LoWord(wParam)  'get control ID
         notifyCode = HiWord(wParam) 'get notification message
         'hWParam = wParam
         Select controlID
         hwParam = controlID

            CASE IDOK
            'call block winMsg
            if notifycode = 0
              if pos_wmCommand > 0
                 tc = pos_wmCommand : tokInterpreter()
                 tc=0
              end if
            end if

           CASE IDCANCEL
              print "ID_CANCEL"

       End Select

  •  

Zlatko Vid

So after current changes and re-compilation i update micro(A)
here is screenshot with simple Guess the Number game in micro(A)
which use KEY N for start of new game , and ENTER key (IDOK)
for entering answer (in this case numbers between 1 to 10)
and seems that all work well.

once again thanks!

ps .if you interested how work ..download and try

'guess my number ? micro(A)
ptr hbox ,hImg,hb
ptr wmKeyDown, wmCommand, wp
str sText, cStr , resText
var  keyN ,tx ,ty ,turn ,newGame , randNumber , result
'LoadImage(0, strRes, imgType, imgW, imgH, cFlag)
LoadImg hImg,"crazyNumbers.bmp"  ,0, 264,236, 24
wcolor 200,190,200 : swap
cStr = "test text"
'syntax INPUTBOX handle , x,y,w,h,text
ShowImgT hImg,400,80,264,236 :swap
INPUTBOX hbox , 10, 350, 300, 23 , "enter number (1-10)"
print 10,10,"GUESS THE NUMBER ...in micro(A) v10"
print 10,40,"press key N for NEW GAME!"
GETTEXT hbox , sText
print 10,400, sText : swap
ty = 50
print 400,40,"NEW GAME":swap
fcolor 220,200,150 : rect 470,38,30,24 : print 480,40,newGame : swap
'events.................
WinMsg wmCOMMAND
'in this case hWparam is LoWord(wParam) -> control ID
hWparam wp

'if is -> IDOK / which is 1
if newGame = 1
if wp = 1
  tx = 10 : ty = ty + 20
  get_text()
  get_result()
  fcolor 0,0,0 : print tx,ty,result : print (tx + 40) ,ty , resText
  swap
  'check if turn > 3 then reset game
  if turn = 4 : newGame = 0 : SETTEXT hbox,"END": setfocus 0 :setfocus hbox: endif
endif
endif

EndWm
'..................
WinMsg wmKeyDown

hWparam keyN
'vkN -> 78
if keyN = 78
  if newGame = 0
      newGame = 1
      'set random number
      randNumber = RAND(10)
      'show rand number
      fcolor 120,150,120 : rect 8,428,30,24 : print 14,430,randNumber :swap
      'set turn to 1
      turn = 1
    fcolor 220,200,150 : rect 470,38,30,24 : print 480,40,newGame : swap
    'print 480,40 ,turn :swa
  endif
endif

EndWm

func get_text()
    GETTEXT hbox, sText 
endfn

func get_result()
    result = VAL(sText)
    'test typed number
    print 50,430, result
    '1.
    if result > randNumber
        resText = "result is larger than number!" 
    endif
    '2.
    if result < randNumber
        resText = "result is lower than number!" 
    endif
    '3.
    if result = randNumber
        resText = "BINGO..you guess the number!" 
    endif
 

    turn = turn + 1
endfn



 
  •