popupmenu without defined labels (on error trick)
Nov 7, 2021 4:11:56 GMT -5
Brandon Parker likes this
Post by tsh73 on Nov 7, 2021 4:11:56 GMT -5
It happens that we can use popup menu
without making all that million of labels!
without making all that million of labels!
[Apples]
[RedApples]
[LargeRedApples]
[Apples]
[GreenApples] (label not defined)
[Apples]
[RedApples]
[SmallRedApples] (label not defined)
[Pears]
[RedPears] (label not defined)
[Pears]
[GreenPears] (label not defined)
global storedCurX, storedCurY
open "test" for graphics_nsb_nf as #gr
#gr "down; trapclose [quit]"
#gr "home; posxy cx cy"
'#gr "font Times_new_roman 16"
txt$="Click Apples|Red Apples|Large Red Apples"
'txtW=200
#gr "stringwidth? txt$ txtW"
#gr "place ";cx-txtW/2;" ";cy
#gr "\";txt$
#gr, "when leftButtonDown [popup1]"
on error goto [err]
wait
[popup1]
call StoreCursorPos
level = 0
popupmenu "Apples", [Apples], "Pears", [Pears] 'first popupmenu
wait
[Apples]
lbl$ = "[Apples]"
print space$(4*level);lbl$
level = level +1
call RestoreCursorPos
popupmenu "RedApples", [RedApples], "Green Apples", [GreenApples]
wait
[Pears]
lbl$ = "[Pears]"
print space$(4*level);lbl$
level = level +1
call RestoreCursorPos
popupmenu "Red Pears", [RedPears], "Green Pears", [GreenPears]
wait
[RedApples]
lbl$ = "[RedApples]"
print space$(4*level);lbl$
level = level +1
call RestoreCursorPos
popupmenu "Large Red Apples", [LargeRedApples], "Small Red Apples", [SmallRedApples]
wait
[LargeRedApples]
lbl$ = "[LargeRedApples]"
print space$(4*level);lbl$
notice "end of chain, see mainwin"
wait
'etc
wait
[quit]
close #gr
end
sub StoreCursorPos
Struct tagPoint, x As long, _
y As long
CallDLL #user32, "GetCursorPos", _
tagPoint As struct, _
GetCursorPos As long
storedCurX = tagPoint.x.struct
storedCurY = tagPoint.y.struct
end sub
Sub RestoreCursorPos
res = SetCursorPos(storedCurX, storedCurY)
end sub
Function SetCursorPos ( intX, intY )
CallDLL #user32, "SetCursorPos", intX As long, _
intY As long, _
SetCursorPos As long
End Function
[err]
if Err=8 then
'notice "Error!"+chr$(13)+"Likely label not defined yet"+chr$(13)+str$(Err)+" "+Err$
'print Err$
'Branch label not found: [GreenApples]
lbl$=mid$(Err$, len("Branch label not found: ")+1)
'print ">";lbl$;"<"
print space$(4*level);lbl$; " (label not defined)"
else
notice "Error!"+chr$(13)+Err$
goto [quit]
end if
wait