home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l391 / 4.ddi / CUSTCALL.BA$ / CUSTCALL.bin
Encoding:
Text File  |  1992-08-19  |  6.5 KB  |  168 lines

  1. ' ----------------------------------------------------------------------------
  2. ' CUSTCALL.BAS: Custom Control Callback Examples
  3. '
  4. ' Copyright (C) 1982-1992 Microsoft Corporation
  5. '
  6. ' You have a royalty-free right to use, modify, reproduce
  7. ' and distribute the sample applications and toolkits provided with
  8. ' Visual Basic for MS-DOS (and/or any modified version)
  9. ' in any way you find useful, provided that you agree that
  10. ' Microsoft has no warranty, obligations or liability for
  11. ' any of the sample applications or toolkits.
  12. '
  13. ' NOTE: This file demonstrates sample usage of the custom control
  14. ' callbacks. It is provided for examples of how different
  15. ' callbacks work. It is not part of a working custom control.
  16. ' ----------------------------------------------------------------------------
  17.  
  18. ' Include file containing constant definitions for
  19. ' Property, Event, Method and ControlType ID numbers.
  20. '$INCLUDE: 'custincl.bi'
  21.  
  22. ' Declarations for custom control callbacks.
  23. ' These callbacks are used to set and get custom control
  24. ' properties and invoke custom control methods and events.
  25. '
  26. '    AID = Attribute Id - list is found in CUSTINCL.BI
  27. '    CID = Control Id created internally by Visual Basic
  28. '    PID = Property Id - list is found in CUSTINCL.BI
  29.  
  30. ' Declare callbacks for setting and getting property values
  31. DECLARE SUB SetProperty
  32. DECLARE SUB GetProperty
  33.  
  34. ' Declare callback for getting a control's container object.
  35. ' This callback returns a CID for the container object.
  36. DECLARE FUNCTION GetContainer (CID AS INTEGER) AS INTEGER
  37.  
  38. ' Declare callback for setting a control's attributes (access key,
  39. ' focus availability, arrow key trapping ability, and text cursor
  40. ' location).  Refer to the custom control section of the README.TXT
  41. ' file for complete information on using this callback.
  42. DECLARE SUB SetAttribute (BYVAL CID AS INTEGER, BYVAL AID AS INTEGER, BYVAL Value AS INTEGER)
  43.  
  44. ' Declare callbacks for invoking methods and events.  These
  45. ' callbacks accept a variable number and types of arguments
  46. ' depending on the method or event that is being invoked.
  47. DECLARE SUB InvokeEvent
  48. DECLARE SUB InvokeMethod
  49.  
  50. DIM SHARED ControlID1 AS INTEGER        ' Storage for ControlId value
  51. DIM SHARED ControlID2 AS INTEGER        ' Storage for ControlId value
  52. DIM SHARED SourceControlID AS INTEGER   ' ControlId value for DragDrop source
  53.  
  54. DIM SHARED Left1 AS INTEGER             ' stores custom1.left
  55. DIM SHARED Top1  AS INTEGER             ' stores top
  56. DIM SHARED Interval1 AS LONG            ' stores custom1.interval
  57. DIM SHARED SDVal1 AS STRING             ' stores custom1.caption
  58. DIM SHARED ContainerID AS INTEGER       ' stores parent ID
  59. DIM SHARED CoordX AS SINGLE             ' stores x coord for dragdrop
  60. DIM SHARED CoordY AS SINGLE             ' stores x coord for dragdrop
  61. DIM SHARED TypeOfControl AS INTEGER     ' stores TYPEOF info
  62.  
  63. ' SetAttribute example
  64. SUB AttributeSet ()
  65.  
  66. ' Example of using the SetAttribute callback to specify access
  67. ' key for a custom control.  Note, it is up to the custom control
  68. ' developer to actually display the text containing the access key.
  69.  
  70.     ' Set Alt+A or Alt+a as the access key.
  71.     SetAttribute ControlID1, ATTR_AccessKey, 65      'Alt+A.
  72.  
  73. END SUB
  74.  
  75. ' InvokeEvent example
  76. SUB EventInvoke ()
  77.  
  78. ' Example of using the InvokeEvent callback to trigger a
  79. ' custom control's DragDrop event and execute user's DragDrop
  80. ' code if it exists.  The standard event arguments (passed to
  81. ' the user's code) are listed
  82. ' first, followed by the ControlID and EventID for the control
  83. ' and event to be triggered.  If the arguments passed don't match
  84. ' the number and type of arguments expected for the EventID, 
  85. ' unpredictable results will occur.
  86.  
  87.     InvokeEvent BYVAL SourceControlID, CoordX, CoordY, BYVAL ControlID1, BYVAL EVENT_DragDrop
  88.  
  89. END SUB
  90.  
  91. ' GetContainer example
  92. SUB GetParent ()
  93.  
  94. ' Example of using the GetContainer callback to retrieve
  95. ' a control's container object (returned as a ControlID).
  96.     ContainerID = GetContainer(ControlID1)
  97.  
  98. END SUB
  99.  
  100. ' InvokeMethod example
  101. SUB MethodInvoke ()
  102.  
  103. ' Example of using the InvokeMethod callback to invoke
  104. ' a custom control's MOVE method.  The MOVE method can take
  105. ' up to 4 arguments (left, top, width, height).  The
  106. ' order in which the arguments are passed to InvokeMethod
  107. ' is the same as that for the method, followed by the
  108. ' number of arguments and the ControlID and
  109. ' MethodID.  All arguments must be passed by value.
  110. ' If the arguments passed don't match the number and type of
  111. ' arguments expected for the MethodID, unpredictable results will occur.
  112.  
  113.     InvokeMethod BYVAL Left1, BYVAL Top1, BYVAL 2, BYVAL ControlID1, BYVAL METHOD_Move
  114.  
  115. END SUB
  116.  
  117. ' Property get examples
  118. SUB PropGet ()
  119.  
  120. ' GetProperty is a callback used to get INTEGER, LONG, and STRING properties.
  121. ' The first argument to this routine must be passed by reference,
  122. ' all others must be passed BYVAL.  The property value corresponding
  123. ' to the PropertyID (last argument) is returned via the first argument (not
  124. ' returned by Getproperty itself).  The callback determines
  125. ' property type (INTEGER, LONG, STRING) based on the PropertyID
  126. ' (last argument).  If an incorrect data type is passed
  127. ' for the given PropertyID, unpredictable results will occur.
  128.  
  129. 'Left1 = Control1.left
  130.     GetProperty Left1, BYVAL ControlID1, BYVAL PROP_Left
  131.  
  132. 'Interval1 = Control1.Interval
  133.     GetProperty Interval1, BYVAL ControlID1, BYVAL PROP_Interval
  134.  
  135. 'SDVal1 = Control1.caption
  136.     GetProperty SDVal1, BYVAL ControlID1, BYVAL PROP_Caption
  137.  
  138. ' Example of using the GetProperty callback to retrieve the
  139. ' control's type (TYPEOF).
  140.     GetProperty TypeOfControl, BYVAL ControlID1, BYVAL PROP_TypeOf                           'TypeOfControl = Control1.TypeOf
  141.     IF TypeOfControl = TYPEOF_Form THEN
  142.         PRINT "Container is a FORM"
  143.     END IF
  144.  
  145. END SUB
  146.  
  147. ' Property set examples
  148. SUB PropSet ()
  149.  
  150. ' SetProperty is a callback used to set INTEGER, LONG, and STRING properties.
  151. ' All arguments to this routine must be passed BYVAL (the string for
  152. ' string property set must be passed by reference however).  The callback
  153. ' determines property type (INTEGER, LONG, STRING) based on the
  154. ' PropertyID (last argument).  If an incorrect value type is passed
  155. ' for the given PropertyID, unpredictable results will occur.
  156.  
  157. 'control.left = 25
  158.     SetProperty BYVAL 25, BYVAL ControlID1, BYVAL PROP_Left
  159.  
  160. 'control.interval = 50000L
  161.     SetProperty BYVAL 50000, BYVAL ControlID1, BYVAL PROP_Interval
  162.  
  163. 'control.caption = SDVal1
  164.     SetProperty SDVal1, BYVAL ControlID1, BYVAL PROP_Caption
  165.  
  166. END SUB
  167.  
  168.