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

  1. // ----------------------------------------------------------------------------
  2. // CUSTCALL.C: 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.h"
  21. #include <stdio.h>
  22.  
  23. // Declarations for custom control callbacks.
  24. // These callbacks are used to set and get custom control
  25. // properties and invoke custom control methods and events.
  26. //
  27. //    AID = Attribute Id - list is found in CUSTINCL.H
  28. //    CID = Control Id created internally by Visual Basic
  29. //    PID = Property Id - list is found in CUSTINCL.H
  30.  
  31. // Declare callbacks for setting and getting property values
  32. extern void _far _pascal SetProperty ();
  33. extern void _far _pascal GetProperty ();
  34.  
  35. // Declare callback for getting a control's container object.
  36. // This callback returns a CID for the container object.
  37. extern unsigned int _far _pascal GetContainer (unsigned int CID);
  38.  
  39. // Declare callback for setting a control's attributes (access key,
  40. // focus availability, arrow key trapping ability, and text cursor 
  41. // location).  Refer to the custom control section of the README.TXT
  42. // file for complete information on using this callback. 
  43. extern void _pascal SetAttribute (unsigned int CID, unsigned int AID, unsigned int Value);
  44.  
  45. // Declare callbacks for invoking methods and events.  These
  46. // callbacks accept a variable number and types of arguments
  47. // depending on the method or event that is being invoked.
  48. extern void _far _pascal InvokeEvent ();
  49. extern void _far _pascal InvokeMethod ();
  50.  
  51. unsigned int _pascal ControlID1;         // Storage for ControlId value
  52. unsigned int _pascal ControlID2;         // Storage for ControlId value
  53. unsigned int _pascal SourceControlID;    // ControlId value for DragDrop source
  54.  
  55. int _pascal Left1;                       // stores custom1.left
  56. int _pascal Top1;                        // stores top
  57. long _pascal Interval1;                  // stores custom1.interval
  58. unsigned long _pascal SDVal1;            // stores custom1.caption
  59. unsigned int _pascal ContainerID;        // stores parent ID
  60. float _pascal CoordX;                    // stores x coord for dragdrop
  61. float _pascal CoordY;                    // stores x coord for dragdrop
  62. unsigned int _pascal TypeOfControl;      // stores TYPEOF info
  63.  
  64.  
  65. // -------------------------------------------------------------------
  66. // The examples below assume that SDVal1 contains a valid Basic
  67. // string descriptor.  See the Mixed-Language Programming chapter
  68. // in the Professional Features Guide for more information.
  69. // ---------------------------------------------------------------------
  70.  
  71.  
  72. // SetAttribute example
  73. void AttributeSet(void)
  74. {
  75.  
  76. // Example of using the SetAttribute callback to specify access
  77. // key for a custom control.  Note, it is up to the custom control
  78. // developer to actually display the text containing the access key.
  79.  
  80.     // Set Alt+A or Alt+a as the access key.
  81.     SetAttribute (ControlID1, ATTR_AccessKey, 65);      // Alt+A.
  82.  
  83. }
  84.  
  85. // Property set examples
  86. void PropSet(void)
  87. {
  88.  
  89. // SetProperty is a callback used to set INTEGER, LONG, and STRING properties.
  90. // All arguments to this routine must be passed BYVAL (the string for
  91. // string property set must be passed by reference however).  The callback
  92. // determines property type (INTEGER, LONG, STRING) based on the
  93. // PropertyID (last argument).  If an incorrect value type is passed
  94. // for the given PropertyID, unpredictable results will occur.
  95.  
  96. // control.left = 25
  97.     SetProperty (25, ControlID1, PROP_Left);
  98.  
  99. // control.interval = 50000L
  100.     SetProperty (50000L, ControlID1, PROP_Interval);
  101.  
  102. // control.caption = SDVal1
  103.     SetProperty ((void _near *)&SDVal1, ControlID1, PROP_Caption);
  104. }
  105.  
  106.  
  107. // Property get examples
  108. void PropGet(void)
  109. {
  110.  
  111. // GetProperty is a callback used to get INTEGER, LONG, and STRING properties.
  112. // The first argument to this routine must be passed by reference,
  113. // all others must be passed BYVAL.  The property value corresponding
  114. // to the PropertyID (last argument) is returned via the first argument (not
  115. // returned by Getproperty itself).  The callback determines
  116. // property type (INTEGER, LONG, STRING) based on the PropertyID
  117. // (last argument).  If an incorrect data type is passed
  118. // for the given PropertyID, unpredictable results will occur.
  119.  
  120. // Left1 = Control1.left
  121.     GetProperty (&Left1, ControlID1, PROP_Left);
  122.  
  123. // Interval1 = Control1.Interval
  124.     GetProperty (&Interval1, ControlID1, PROP_Interval);
  125.  
  126. // SDVal1 = Control1.caption
  127.     GetProperty (&SDVal1, ControlID1, PROP_Caption);
  128.  
  129. // Example of using the GetProperty callback to retrieve the
  130. // control's type (TYPEOF).
  131.     GetProperty (&TypeOfControl, ControlID1,
  132.              PROP_TypeOf);                   //TypeOfControl = Control1.TypeOf
  133.     if (TypeOfControl == TYPEOF_Form)
  134.         printf("Container is a FORM\n");
  135.  
  136. }
  137.  
  138.  
  139. // GetContainer example
  140. void GetParent(void)
  141. {
  142.  
  143. // Example of using the GetContainer callback to retrieve
  144. // a control's container object (returned as a ControlID).
  145.     ContainerID = GetContainer(ControlID1);
  146.  
  147. }
  148.  
  149.  
  150. // InvokeEvent example
  151. void EventInvoke(void)
  152. {
  153.  
  154. // Example of using the InvokeEvent callback to trigger a
  155. // custom control's DragDrop event and execute user's DragDrop
  156. // code if it exists.  The standard event arguments (passed to
  157. // the user's code) are listed
  158. // first, followed by the ControlID and EventID for the control
  159. // and event to be triggered.  If the arguments passed don't match
  160. // the number and type of arguments expected for the EventID,
  161. // unpredictable results will occur.
  162.  
  163. InvokeEvent (SourceControlID, &CoordX, &CoordY, ControlID1, EVENT_DragDrop);
  164.  
  165. }
  166.  
  167.  
  168. // InvokeMethod example
  169. void MethodInvoke(void)
  170. {
  171.  
  172. // Example of using the InvokeMethod callback to invoke
  173. // a custom control's MOVE method.  The MOVE method can take
  174. // up to 4 arguments (left, top, width, height).  The
  175. // order in which the arguments are passed to InvokeMethod
  176. // is the same as that for the method, followed by the
  177. // number of arguments and the ControlID and
  178. // MethodID.  All arguments must be passed by value.
  179. // If the arguments passed don't match the number and type of
  180. // arguments expected for the MethodID, unpredictable results will occur.
  181.  
  182.     InvokeMethod (Left1, Top1, 2, ControlID1, METHOD_Move);
  183. }
  184.  
  185.