Microsoft KB Archive/37315

From BetaArchive Wiki
< Microsoft KB Archive
Revision as of 14:14, 21 July 2020 by X010 (talk | contribs) (Text replacement - "&" to "&")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Base


Macintosh QuickBASIC Example to Create and Use Scroll Bars

Article ID: 37315

Article Last Modified on 1/8/2003



APPLIES TO

  • Microsoft QuickBasic Compiler for Macintosh 1.0



This article was previously published under Q37315

SUMMARY

This article contains a sample program that creates and uses QuickBASIC scroll bars. Before attempting to write your own QuickBASIC program that uses scroll bars, we recommend that you research the following areas in the "Microsoft QuickBASIC for the Macintosh: BASIC Language Reference" manual:

   Item                Page(s)
   ----                -------

   NewScroll           488

   DisposeScroll       478

   ScrollText          492

   SetRect             495

   FrameRect           402

   SetPt               495

   PtInRect            490

   GetFontInfo         482

   Mouse function      210-214
                

Scrolling is also discussed on Pages 432-434.

A program that defines scroll bars is provided further below. Two additional examples for defining scroll bars in QuickBASIC are "ToolBoxSampler" and "File Browser.source", which are located in the QB Demos folder on the Examples disk for QuickBASIC Version 1.00 for the Apple Macintosh.

MORE INFORMATION

Code Example

'PROGRAM: scroll

'DESCRIPTION:
' This programs puts up a scroll bar with an associated scrolling
' region. This region contains lines of text to be scrolled by
' clicking or dragging the scroll box around the scroll bar.
' Clicking on a particular line of text selects that line. And
' finally, a double-click ends the program.

'CONSTANTS:
'  SingleClick               Single click value
'  DoubleClick               Double-click value
'  MaxLines                  Maximum number of text lines

'VARIABLES:
'  linenum                   Currently selected line
'  top                       Top line in scroll region
'  s&                        Handle to a scroll bar
'  PtInside                  Boolean flag that indicates
'                            inside/outside of scroll region
'  s$()                      Array that holds text to be
'                            scrolled
'  scr()                     Array that holds dimensions of
'                            scroll region (rectangle)
'  bar()                     Array that holds dimensions of
'                            scroll bar (rectangle)
'  FontInfo()                Array that holds information
'                            about the current font
'  AnyPt()                   Array that holds the (x,y)
'                            coordinates of the mouse pointer
'                            at the time of a single click,
'                            inside the scroll region
'  FontHeight                Vertical length of the current
'                            font
defint a-z
option base 1
SingleClick = -1: DoubleClick = -2: MaxLines = 10
linenum=1: top=0: s&=0: PtInside=0
dim s$(Maxlines), scr(4), bar(4), FontInfo(4), AnyPt(2)

SetRect scr(1), 3, 6, 114, 111
SetRect bar(1), 113, 6, 129, 111
FrameRect varptr (scr(1))
NewScroll s&, bar(1), 1, 1, 10, 1
GetFontInfo FontInfo(1)
FontHeight = FontInfo(1) + FontInfo(2) + FontInfo(4)

for n = 1 to MaxLines
  read s$(n)
next n

while Mouse (0) <> DoubleClick
  ScrollText s&, scr(1), s$(1), top, MaxLines, linenum
  if Mouse (0) = SingleClick then
    PtInside = 0
    SetPt AnyPt(1), Mouse(1), Mouse(2)
    PtInRect AnyPt(1), scr(1), PtInside
    if PtInside then
      linenum = (AnyPt(1) - scr(1)) \ (FontHeight + 4) + top
      top = 0
    end if
  end if
wend
DisposeScroll s&

end
  data one, two, three, four, five
  data six, seven, eight, nine, ten
                


Additional query words: MQuickB

Keywords: KB37315