home *** CD-ROM | disk | FTP | other *** search
- Program MouseMenuDemo;
-
- Uses Crt,Dos,Mouse;
- Type
- Str30 = string[30];
-
- Var
- Result : byte;
- i : integer;
-
- Const
- MaxItems = 5;
- UpArrow = #200; {Up arrow OR $80}
- DownArrow = #208; {Down arrow OR $80}
- Home = #199; {Home OR $80}
- EndKey = #207; {End OR $80}
- Inverse = $70;
- Normal = $0E;
- LB = 1;
- RB = 2;
- LRB = 3;
- MB = 4;
- LMB = 5;
- MRB = 6;
- LMR = 7;
- MenuItem : array[1..MaxItems] of str30 =
- (' Menu Item #1 ',
- ' Menu Item #2 ',
- ' Menu Item #3 ',
- ' Menu Item #4 ',
- ' Menu Item #5 ');
-
- Function GetAKey : byte;
- Var X1,Y1,x,y,Button,SaveAttr,Item : integer;
- KeyPress : boolean;
- Ch : char;
- Const
- HiLimit = 16;
- LoLimit = 8;
- Label Top;
- begin
- x := 30;
- y := 9;
- Top:
- if MouseAvail then
- begin
- SetMousePosition(40,12);
- MickeyToPixelRatio(40,8);
- end;
- Button := 0;
- Repeat
- gotoxy(x,y);
- TextAttr := inverse;
- write(MenuItem[y-8]);
- KeyPress := Keypressed;
- If (not keypress) and MouseAvail then Button := ReadMousePosition(X1,Y1);
- Until Keypress or (Button > 0) or (Y1 < LoLimit) or (Y1 > HiLimit);
- If Button > 0 then
- case Button of
- LB : Ch := chr(y-8);
- MB : Ch := Home;
- RB : Ch := #255;
- end
- else if (not KeyPress) and MouseAvail then
- begin
- if y1 > HiLimit then ch := DownArrow;
- if y1 < LoLimit then ch := UpArrow;
- delay(200);
- end
- else
- begin
- if button = 0 then Ch := ReadKey;
- if button = 0 then if Ch = #0 then Ch := Chr(Ord(ReadKey) or $80);
- end;
- TextAttr := Normal;
- gotoxy(x,y);
- write(MenuItem[y-8]);
- case ch of
- DownArrow : if y < 13 then y := succ(y) else y := 9;
- UpArrow : if Y > 9 then y := pred(y) else y := 13;
- #13 : ch := chr(y-8);
- Home : begin
- y := 9;
- goto top;
- end;
- EndKey : begin
- y := 13;
- goto top;
- end;
- end;
- if ch in [UpArrow,DownArrow] then goto top;
- GetAKey := ord(ch);
- end;
-
- Procedure Action(Item : byte);
- begin
- clrscr;
- gotoxy(10,10);
- write('Menu item ',item,' was selected');
- repeat until keypressed;
- end;
-
- begin
- TextAttr := Normal;
- clrscr;
- DefineTextCursor(1,9,0); {Hide the cursor on a CGA}
- for i := 1 to 5 do
- begin
- gotoxy(30,i+8);
- write(MenuItem[i]);
- end;
- repeat
- Result := GetAKey;
- gotoxy(1,25);
- if result in [1..5] then Action(result);
- until (Result in [1..5]) or (result = 27);
- DefineTextCursor(1,7,8);
- end.