declare function wins% (z$)   '按键选择
declare sub txo (h%, l%)      '画方框
declare sub scrc (s$)         '保存屏幕

print wins("第一个选择项,第二个选择项,第三个选择项,这个是标题行")

defint a-z
sub scrc (s$)   
def seg = &hb800
if s$ = "" then
   for d% = 0 to 3999
       s$ = s$ + chr$(peek(d%))
   next
else
   if len(s$) > 4000 then s$ = mid$(s$, 4000)
   for d% = 1 to len(s$)
        poke d% - 1, asc(mid$(s$, d%, 1))
   next
end if
def seg
end sub

sub txo (h%, l%)        '列空白方框
'   (包括方框的高,长)    行,列,行,列,边框
dim txs$(8)
locate , , 0
x% = csrlin
y% = pos(1)
if h% + x% > 26 then h% = 26 - x%
if l% + y% > 81 then l% = 81 - y%
txt$ = "谀砍忱馁"
for i% = 1 to 8
  txs$(i%) = mid$(txt$, i%, 1)
next
    locate x%, y%, 0
     print txs$(1);
     print string$(l% - 2, txs$(2));
     print txs$(3);
   for i% = 1 to (h% - 2)
    locate x% + i%, y%
     print txs$(4);
    locate , y% + l% - 1
     print txs$(5);
   next
    locate x% + h% - 1, y%
     print txs$(6);
     print string$(l% - 2, txs$(7));
     print txs$(8);
 if oo% = 0 then    '填空格
   for i% = 1 to (h% - 2)
   locate x% + i%, y% + 1
   print space$(l% - 2);
   next
 end if
x% = x% + h%
ll% = l%
if y% + l% > 80 then l% = 80 - y%
def seg = &hb800
   if x% < 26 then
    for i%=((x%-1)*160+y%*2+1)to((x%-1)*160+(y%+l%)*2-1)step 2
     poke i%, 8
    next
   end if
   if y% + ll% < 81 then
      y% = (y% + ll%) * 2 - 1
      for i% = ((x% - h%) * 160 + y%) to ((x% - 2) * 160 + y%) step 160
       poke i%, 8
      next
   end if
def seg
end sub

function wins (z$)
s$ = z$
l = len(s$) \ 2
dim a$(l)
i = instr(s$, ",")
do while i
   j = j + 1
   a$(j) = left$(s$, i - 1)
   s$ = mid$(s$, i + 1)
   if len(a$(j)) > ml then ml = len(a$(j))
   i = instr(s$, ",")
loop
a$(0) = s$   '标题
if j < 1 or ml < 1 then exit function
x = (25 - 3 - j) \ 2
y = (80 - 3 - ml) \ 2
scrc ts$
color 14, 7
locate x - 1, y, 0
print "["; left$(a$(0) + space$(ml), ml); "]";
color 1, 7
locate x, y, 0
txo j + 2, ml + 2
color 0, 7
for i = 1 to j
    locate x + i, y + 1
    a$(i) = left$(a$(i) + space$(ml), ml)
    print a$(i);
next
t1 = 1
t2 = 1
do
  if t1 > j then t1 = 1
  if t1 < 1 then t1 = j
  color 0, 7
  locate x + t2, y + 1
  print a$(t2);
   color 31, 5
   locate x + t1, y + 1
   print a$(t1);
  t2 = t1
  locate , , 0
  do: k$ = inkey$: loop while k$ = ""
  select case k$
  case chr$(0) + chr$(72): t1 = t1 - 1      '上
  case chr$(0) + chr$(80): t1 = t1 + 1      '下
  case chr$(0) + chr$(71), chr$(0) + chr$(73), chr$(0) + chr$(119): t1 = 1
  case chr$(0) + chr$(81), chr$(0) + chr$(79), chr$(0) + chr$(117): t1 = j
  case chr$(49) to chr$(57): t1 = asc(k$) - 48   '1-9
  case chr$(27), chr$(48): w = -1
  case chr$(13): w = t1
  end select
loop until w
scrc ts$
color 7, 0
if w > 0 then wins = w
end function