home *** CD-ROM | disk | FTP | other *** search
/ Dan Appleman's Visual Bas…s Guide to the Win32 API / Dan.Applmans.Visual.Basic.5.0.Programmers.Guide.To.The.Win32.API.1997.Ziff-Davis.Press.CD / VB5PG32.mdf / vbpg32 / samples4 / ch05 / scroll.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-02-16  |  3.9 KB  |  104 lines

  1. VERSION 4.00
  2. Begin VB.Form frmScroll 
  3.    Caption         =   "Scrolling Example"
  4.    ClientHeight    =   2835
  5.    ClientLeft      =   2280
  6.    ClientTop       =   1995
  7.    ClientWidth     =   3975
  8.    ClipControls    =   0   'False
  9.    Height          =   3240
  10.    Left            =   2220
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   189
  13.    ScaleMode       =   3  'Pixel
  14.    ScaleWidth      =   265
  15.    Top             =   1650
  16.    Width           =   4095
  17.    Begin VB.CommandButton cmdScroll2 
  18.       Caption         =   "Scroll Window2"
  19.       Height          =   435
  20.       Left            =   2220
  21.       TabIndex        =   2
  22.       Top             =   720
  23.       Width           =   1395
  24.    End
  25.    Begin VB.CommandButton cmdScroll1 
  26.       Caption         =   "ScrollWindow"
  27.       Height          =   435
  28.       Left            =   2220
  29.       TabIndex        =   1
  30.       Top             =   120
  31.       Width           =   1395
  32.    End
  33.    Begin VB.CommandButton cmdScrollEx 
  34.       Caption         =   "ScrollWindowEx"
  35.       Height          =   435
  36.       Left            =   2220
  37.       TabIndex        =   0
  38.       Top             =   1320
  39.       Width           =   1395
  40.    End
  41. Attribute VB_Name = "frmScroll"
  42. Attribute VB_Creatable = False
  43. Attribute VB_Exposed = False
  44. Option Explicit
  45. ' Copyright 
  46.  1996 by Desaware. All Rights Reserved
  47. '**********************************
  48. '**  Constant Definitions:
  49. #If Win32 Then
  50. Private Const SW_ERASE& = &H4
  51. Private Const SW_INVALIDATE& = &H2
  52. Private Const SW_SCROLLCHILDREN = &H1
  53. #End If 'WIN32
  54. '**********************************
  55. '**  Function Declarations:
  56. #If Win32 Then
  57. Private Declare Function ScrollWindow Lib "user32" (ByVal hWnd As Long, ByVal XAmount As Long, ByVal YAmount As Long, lpRect As RECT, lpClipRect As RECT) As Long
  58. Private Declare Function ScrollWindowByNum& Lib "user32" Alias "ScrollWindow" (ByVal hWnd As Long, ByVal XAmount As Long, ByVal YAmount As Long, ByVal lpRect As Long, ByVal lpClipRect As Long)
  59. Private Declare Function ScrollWindowEx& Lib "user32" (ByVal hWnd As Long, ByVal dx As Long, ByVal dy As Long, lprcScroll As RECT, lprcClip As RECT, ByVal hrgnUpdate As Long, lprcUpdate As RECT, ByVal fuScroll As Long)
  60. Private Declare Function ScrollWindowExByNum& Lib "user32" Alias "ScrollWindowEx" (ByVal hWnd As Long, ByVal dx As Long, ByVal dy As Long, lprcScroll As RECT, lprcClip As RECT, ByVal hrgnUpdate As Long, ByVal lprcUpdate As Long, ByVal fuScroll As Long)
  61. Private Declare Function InflateRect Lib "user32" (lpRect As RECT, ByVal x As Long, ByVal y As Long) As Long
  62. Private Declare Function GetClientRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
  63. Private Declare Function UpdateWindow& Lib "user32" (ByVal hWnd As Long)
  64. #End If 'WIN32
  65. '**********************************
  66. '**  Type Definitions:
  67. #If Win32 Then
  68. Private Type RECT
  69.         left As Long
  70.         top As Long
  71.         right As Long
  72.         bottom As Long
  73. End Type
  74. #End If 'WIN32 Types
  75. Private Sub cmdScroll1_Click()
  76.     Dim dl&
  77.     dl& = ScrollWindowByNum&(Me.hWnd, 15, 10, 0, 0)
  78. End Sub
  79. Private Sub cmdScroll2_Click()
  80.     Dim rc1 As RECT
  81.     Dim rc2 As RECT
  82.     Dim dl&
  83.     ' Scroll the entire client area
  84.     dl& = GetClientRect(Me.hWnd, rc1)
  85.     LSet rc2 = rc1
  86.     ' But specify a smaller clipping rectangle
  87.     dl& = InflateRect(rc2, -30, -30)
  88.     ' Note how the controls don't move - but the image of them does!
  89.     dl& = ScrollWindow&(Me.hWnd, 15, 10, rc1, rc2)
  90. End Sub
  91. Private Sub cmdScrollEx_Click()
  92.     Dim dl&
  93.     Dim rc1 As RECT
  94.     Dim rc2 As RECT
  95.     dl& = GetClientRect(Me.hWnd, rc1)
  96.     LSet rc2 = rc1
  97.     dl& = ScrollWindowExByNum&(Me.hWnd, 15, 10, rc1, rc2, 0, 0, _
  98.                        SW_INVALIDATE Or SW_ERASE Or SW_SCROLLCHILDREN)
  99. End Sub
  100. ' Draw a line that
  101. Private Sub Form_Paint()
  102.     Line (20, 20)-(200, 200)
  103. End Sub
  104.