home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / lb_msgs / lb_msgs.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-09-06  |  9.3 KB  |  272 lines

  1. VERSION 2.00
  2. Begin Form LB_Msgs 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   3  'Fixed Double
  5.    Caption         =   "ListBox Messages"
  6.    ClientHeight    =   4260
  7.    ClientLeft      =   1890
  8.    ClientTop       =   1635
  9.    ClientWidth     =   2280
  10.    Height          =   4665
  11.    Left            =   1830
  12.    LinkMode        =   1  'Source
  13.    LinkTopic       =   "Form1"
  14.    ScaleHeight     =   4260
  15.    ScaleWidth      =   2280
  16.    Top             =   1290
  17.    Width           =   2400
  18.    Begin CommandButton More 
  19.       Caption         =   "More..."
  20.       Height          =   372
  21.       Left            =   1152
  22.       TabIndex        =   12
  23.       Top             =   3648
  24.       Width           =   972
  25.    End
  26.    Begin CommandButton GetDir 
  27.       Caption         =   "Get DIR"
  28.       Height          =   372
  29.       Left            =   96
  30.       TabIndex        =   11
  31.       Tag             =   "SendMessage(GetFocus(), LB_DIR, ByVal DOS_attr&, filespecs$)"
  32.       Top             =   3648
  33.       Width           =   972
  34.    End
  35.    Begin CommandButton QuitThis 
  36.       Caption         =   "Seen it all"
  37.       Height          =   372
  38.       Left            =   3744
  39.       TabIndex        =   8
  40.       Top             =   3072
  41.       Width           =   1212
  42.    End
  43.    Begin CommandButton SelectString 
  44.       Caption         =   "SelectString"
  45.       Height          =   372
  46.       Left            =   2304
  47.       TabIndex        =   4
  48.       Tag             =   "SendMessage(GetFocus(), LB_SELECTSTRING, ByVal startingAt%, ByVal theString$)"
  49.       Top             =   3072
  50.       Width           =   1212
  51.    End
  52.    Begin CommandButton SetCurSel 
  53.       Caption         =   "SetCurSel"
  54.       Height          =   372
  55.       Left            =   2304
  56.       TabIndex        =   5
  57.       Tag             =   "SendMessage(GetFocus(), LB_SETCURSEL, ByVal listEntry%, 0&)"
  58.       Top             =   2496
  59.       Width           =   1212
  60.    End
  61.    Begin CommandButton FillErUp 
  62.       Caption         =   "Fill List Box"
  63.       Height          =   372
  64.       Left            =   3744
  65.       TabIndex        =   10
  66.       Tag             =   "SendMessage(GetFocus(), LB_ADDSTRING, 0, ByVal theString$)"
  67.       Top             =   1920
  68.       Width           =   1212
  69.    End
  70.    Begin CommandButton GetCurSel 
  71.       Caption         =   "GetCurSel"
  72.       Height          =   372
  73.       Left            =   2304
  74.       TabIndex        =   3
  75.       Tag             =   "SendMessage(GetFocus(), LB_GETCURSEL, 0%, 0&)"
  76.       Top             =   1920
  77.       Width           =   1212
  78.    End
  79.    Begin CommandButton FindString 
  80.       Caption         =   "FindString"
  81.       Height          =   372
  82.       Left            =   2304
  83.       TabIndex        =   2
  84.       Tag             =   "SendMessage(GetFocus(), LB_FINDSTRING, ByVal startAt%, ByVal theString$)"
  85.       Top             =   1344
  86.       Width           =   1212
  87.    End
  88.    Begin CommandButton ResetContent 
  89.       Caption         =   "ResetContent"
  90.       Height          =   372
  91.       Left            =   3744
  92.       TabIndex        =   9
  93.       Tag             =   "SendMessage(GetFocus(), LB_RESETCONTENT, 0%, 0&)"
  94.       Top             =   768
  95.       Width           =   1212
  96.    End
  97.    Begin CommandButton SetTopIndex 
  98.       Caption         =   "SetTopIndex"
  99.       Height          =   372
  100.       Left            =   2304
  101.       TabIndex        =   6
  102.       Tag             =   "SendMessage(GetFocus(), LB_SETTOPINDEX, ByVal Index%, 0&)"
  103.       Top             =   768
  104.       Width           =   1212
  105.    End
  106.    Begin CommandButton GetTextLen 
  107.       Caption         =   "GetTextLen"
  108.       Height          =   372
  109.       Left            =   3744
  110.       TabIndex        =   7
  111.       Tag             =   "SendMessage(GetFocus(), LB_GETTEXTLEN, ByVal listEntry%, 0&)"
  112.       Top             =   192
  113.       Width           =   1212
  114.    End
  115.    Begin CommandButton TopIndex 
  116.       Caption         =   "GetTopIndex"
  117.       Height          =   372
  118.       Left            =   2304
  119.       TabIndex        =   0
  120.       Tag             =   "SendMessage(GetFocus(), LB_GETTOPINDEX, 0%, 0&)"
  121.       Top             =   192
  122.       Width           =   1212
  123.    End
  124.    Begin ListBox theList 
  125.       BackColor       =   &H00C0C0C0&
  126.       Height          =   3345
  127.       Left            =   96
  128.       Sorted          =   -1  'True
  129.       TabIndex        =   1
  130.       Top             =   96
  131.       Width           =   2055
  132.    End
  133. DefInt A-Z
  134. Dim result&
  135. Sub FillErUp_Click ()
  136. ' fill the list box with some predictable garbage
  137. ' text strings must be terminated by Chr$(0)
  138.   Cls                   'we'll display results on the form
  139.   theList.SetFocus
  140.   result& = SendMessage(GetFocus(), LB_RESETCONTENT, 0, 0&)
  141.   For i = 0 To 24
  142.     For j = 0 To 24
  143.       a$ = Chr$(Asc("A") + i) + " " + Chr$(Asc("A") + j) + Str$(i * 25 + j) + Chr$(0)
  144.       result& = SendMessage(GetFocus(), LB_ADDSTRING, 0, ByVal a$)
  145.       ' result& at this point contains the index number of
  146.       ' the just added item (in contrast to theList.AddItem)
  147.     Next
  148.     x = DoEvents()      'give other tasks some breathing space too, and see
  149.                         'the list box fill up (if your PC is slow enough...)
  150.   Next
  151.   Cls
  152.   showResult FillErUp
  153. End Sub
  154. Sub FindString_Click ()
  155. ' finds a string (MS call it "prefix") but doesn't select it
  156. ' (see LB_SELECTSTRING for find-and-select)
  157. ' the search string must be terminated by Chr$(0)
  158. ' "startingAt" selects the entry at which the search starts
  159. ' (wraps around if necessary). "-1" starts at the top.
  160.   theList.SetFocus
  161.   startingAt = -1
  162.   a$ = Chr$(Asc("A") + Rnd * 24) + " " + Chr$(Asc("A") + Rnd * 24) + Chr$(0)
  163.   result& = SendMessage(GetFocus(), LB_FINDSTRING, ByVal startingAt, ByVal a$)
  164.   Cls
  165.   showResult FindString
  166. End Sub
  167. Sub Form_Load ()
  168.   LB_function.Show
  169. End Sub
  170. Sub Form_Unload (Cancel As Integer)
  171.   Unload LB_function
  172. End Sub
  173. Sub GetCurSel_Click ()
  174. ' returns the index number of the currently selected
  175. ' list box entry or LB_ERR if none selected
  176.   theList.SetFocus
  177.   result& = SendMessage(GetFocus(), LB_GETCURSEL, 0, 0&)
  178.   Cls
  179.   showResult GetCurSel
  180. End Sub
  181. Sub GetDir_Click ()
  182.   filespecs$ = "c:\*.*" 'filespec string; anything valid in a DIR command
  183.   DOS_attr& = &H4037
  184.                         'DOS attributes as follows (combine as needed using OR):
  185.                         '&H0000 = read/write files, no add'l attributes
  186.                         '&H0001 = read-only files
  187.                         '&H0002 = hidden files
  188.                         '&H0004 = system files
  189.                         '&H0010 = subdirectories
  190.                         '&H0020 = archives
  191.                         '&H4000 = drives
  192.                         '&H8000 = exclusive bit. If set, only files of the
  193.                         '         specified type are listed.
  194.   theList.SetFocus
  195.   result& = SendMessage(GetFocus(), LB_DIR, ByVal DOS_attr&, filespecs$)
  196.   'result& = number of items minus one
  197.   Cls
  198.   showResult GetDir
  199. End Sub
  200. Sub GetTextLen_Click ()
  201. ' gets the length in characters of an entry in the list box
  202. ' (here: length of currently selected entry found by
  203. ' LB_GETCURSEL).
  204.   theList.SetFocus
  205.   curr = SendMessage(GetFocus(), LB_GETCURSEL, 0, 0&)
  206.   result& = SendMessage(GetFocus(), LB_GETTEXTLEN, ByVal curr, 0&)
  207.   Cls
  208.   showResult GetTextLen
  209. End Sub
  210. Sub More_Click ()
  211.   theList.SetFocus
  212.   result& = SendMessage(GetFocus(), LB_RESETCONTENT, 0, 0&)
  213.   GetDir.Visible = False
  214.   More.Visible = False
  215.   LB_msgs.Height = More.Top + 550
  216.   LB_msgs.Width = QuitThis.Left + QuitThis.Width + 250
  217.   FillErUp_Click
  218. End Sub
  219. Sub QuitThis_Click ()
  220.   Unload LB_msgs       'self-documenting, don't you think?
  221. End Sub
  222. Sub ResetContent_Click ()
  223. ' clear list box contents. Much faster than VB
  224.   theList.SetFocus
  225.   result& = SendMessage(GetFocus(), LB_RESETCONTENT, 0, 0&)
  226.   Cls
  227.   showResult ResetContent
  228. End Sub
  229. Sub SelectString_Click ()
  230. ' finds a search string and selects the list box entry (unlike LB_FINDSTRING).
  231. ' the search string must be terminated by Chr$(0). "startingAt"
  232. ' sets the entry where searching should start (wraps around if
  233. ' necessary). "-1" starts at the top.
  234.   theList.SetFocus
  235.   startingAt = -1
  236.   a$ = Chr$(Asc("A") + Rnd * 24) + " " + Chr$(Asc("A") + Rnd * 24) + Chr$(0)
  237.   result& = SendMessage(GetFocus(), LB_SELECTSTRING, ByVal startingAt, ByVal a$)
  238.   Cls
  239.   showResult SelectString
  240. End Sub
  241. Sub SetCurSel_Click ()
  242. ' sets current selection
  243.   theList.SetFocus
  244.   a = Rnd * 25 * 25         'random nth entry
  245.   result& = SendMessage(GetFocus(), LB_SETCURSEL, ByVal a, 0&)
  246.   Cls
  247.   result& = a
  248.   showResult SetCurSel
  249. End Sub
  250. Sub SetTopIndex_Click ()
  251. ' sets current top (= visible) entry in list box
  252.   theList.SetFocus
  253.   a = Rnd * 25 * 25             'random nth entry
  254.   result& = SendMessage(GetFocus(), LB_SETTOPINDEX, ByVal a, 0&)
  255.   Cls
  256.   result& = a
  257.   showResult SetTopIndex
  258. End Sub
  259. Sub showResult (c As Control)
  260.   LB_msgs.CurrentX = c.Left
  261.   LB_msgs.CurrentY = c.Top + c.Height
  262.   Print Format$(result&, "0")
  263.   LB_function.Label1.Caption = c.Tag
  264. End Sub
  265. Sub TopIndex_Click ()
  266. ' returns the index of the top (= first visible) item
  267.   theList.SetFocus
  268.   result& = SendMessage(GetFocus(), LB_GETTOPINDEX, 0, 0&)
  269.   Cls
  270.   showResult TopIndex
  271. End Sub
  272.