home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / tool / various / skelet / skelini.cpp < prev    next >
Text File  |  1994-08-15  |  6KB  |  193 lines

  1.  
  2. //////////////////////////////////////////////////////////////////////////////
  3. //
  4. // Filename:     skelini.cpp
  5. //
  6. // Description:  Skeleton Visual Basic Custom Control.
  7. //
  8. //               Initialisation (and termination) routines for the VBX (DLL)
  9. //               module.
  10. //
  11. // Date Created: <Date>
  12. //
  13. // Author:       <Your Name>
  14. //
  15. // Copyright (c) <Your Company Name> 1994
  16. //
  17. //               Portions of this product are based on original
  18. //                  source code from Anton Software Limited.
  19. //
  20. //////////////////////////////////////////////////////////////////////////////
  21.  
  22. #include <windows.h>
  23. #include <vbapi.h>
  24.  
  25. #include "skeleton.hpp"
  26. #include "skelexp.hpp"
  27. #include "skelext.hpp"
  28.  
  29. //////////////////////////////////////////////////////////////////////////////
  30. //
  31. // Local data
  32. //
  33. //////////////////////////////////////////////////////////////////////////////
  34.  
  35. // Number of programs currently using the VBX module.
  36. static WORD cVBXUsers = 0;
  37.  
  38. // Whether the about box's controlling window class has been registered.
  39. static BOOL fAboutClassRegistered = FALSE;
  40.  
  41. //////////////////////////////////////////////////////////////////////////////
  42. //
  43. // Function Name: LibMain
  44. //
  45. // Description:   Called by the system when the first client program loads the
  46. //                control.
  47. //
  48. // Parameters:    hModule    - library instance handle
  49. //                wDataSeg   - library data segment
  50. //                cbHeapSize - default heap size
  51. //                lszCmdLine - command line arguments
  52. //
  53. // Return Code:   1 to indicate success
  54. //
  55. //////////////////////////////////////////////////////////////////////////////
  56.  
  57. int CALLBACK LibMain
  58. (
  59.     HANDLE     hModule,     // library instance handle
  60.     WORD,   // wDataSeg,    // library data segment
  61.     WORD,   // cbHeapSize,  // default heap size
  62.     LPSTR   // lpszCmdLine  // command line arguments
  63. )
  64. {
  65.     // Save the module handle (used in VBINITCC()).
  66.     hmodDLL = hModule;
  67.  
  68.     // Return 1 to indicate success.
  69.     return 1;
  70.  
  71. } // LibMain
  72.  
  73. //////////////////////////////////////////////////////////////////////////////
  74. //
  75. // Function Name: VBGetModelInfo
  76. //
  77. // Description:   Provides custom control model information to the host
  78. //                environment (Visual Basic).
  79. //
  80. // Parameters:    uVersion - Visual Basic version
  81. //
  82. // Return Code:   Long pointer to the model information
  83. //
  84. //////////////////////////////////////////////////////////////////////////////
  85.  
  86. LPMODELINFO CALLBACK _export VBGetModelInfo
  87. (
  88.     USHORT uVersion     // Visual Basic version
  89. )
  90. {
  91.     // Don't bother to support VB1 (or, therefore, VC++).
  92.     if (uVersion == VB100_VERSION)
  93.         return NULL;
  94.  
  95.     // Return the model information.
  96.     return (LPMODELINFO)&modelinfoSkeleton;
  97.  
  98. } // VBGetModelInfo
  99.  
  100. //////////////////////////////////////////////////////////////////////////////
  101. //
  102. // Function Name: VBINITCC
  103. //
  104. // Description:   Called by Visual Basic when the custom control DLL is loaded
  105. //                for use by each application. Registers the custom control.
  106. //
  107. // Parameters:    uVersion - Visual Basic version
  108. //                fRuntime - whether run time
  109. //
  110. // Return Code:   TRUE if registering the control was successful; FALSE
  111. //                otherwise.
  112. //
  113. //////////////////////////////////////////////////////////////////////////////
  114.  
  115. BOOL CALLBACK _export VBINITCC
  116. (
  117.     USHORT    uVersion,     // Visual Basic version
  118.     BOOL   // fRuntime      // whether run time
  119. )
  120. {
  121.     // Don't bother to support VB1 (or, therefore, VC++).
  122.     if (uVersion == VB100_VERSION)
  123.     {
  124.         MessageBox(0,
  125.                    "VB1 and VC++ are not supported. " \
  126.                    "Please use VB2 or above.\n",
  127.                    lpstrMsgBoxTitle,
  128.                    MB_ICONSTOP);
  129.  
  130.         return FALSE;
  131.  
  132.     } // end if being loaded by VB1 (or VC++)
  133.  
  134.     // Register the about box's invisible controlling window class (if not
  135.     // already registered)...
  136.     if (!fAboutClassRegistered)
  137.     {
  138.         WNDCLASS WndClass;
  139.  
  140.         WndClass.style         = 0;
  141.         WndClass.lpfnWndProc   = (WNDPROC)AboutWndProc;
  142.         WndClass.cbClsExtra    = 0;
  143.         WndClass.cbWndExtra    = 0;
  144.         WndClass.hInstance     = hmodDLL;
  145.         WndClass.hIcon         = NULL;
  146.         WndClass.hCursor       = NULL;
  147.         WndClass.hbrBackground = NULL;
  148.         WndClass.lpszMenuName  = NULL;
  149.         WndClass.lpszClassName = lpstrAboutBoxParent;
  150.  
  151.         if (RegisterClass(&WndClass) == 0)
  152.             return FALSE;
  153.  
  154.         fAboutClassRegistered = TRUE;
  155.  
  156.     } // end if the about control window class is not already registered
  157.  
  158.     // Increment the count of programs using the VBX module.
  159.     cVBXUsers++;
  160.  
  161.     // Finally, return the result from registering the control's model.
  162.     return VBRegisterModel(hmodDLL, (LPMODEL)&modelSkeleton);
  163.  
  164. } // VBINITCC
  165.  
  166. //////////////////////////////////////////////////////////////////////////////
  167. //
  168. // Function Name: VBTERMCC
  169. //
  170. // Description:   An optional routine that is the opposite of VBINITCC(). Is
  171. //                called by VB when an application unloads the control.
  172. //
  173. // Parameters:    None
  174. //
  175. // Return Code:   None
  176. //
  177. //////////////////////////////////////////////////////////////////////////////
  178.  
  179. VOID CALLBACK _export VBTERMCC(void)
  180. {
  181.     // Decrement the count of programs using the VBX module.
  182.     cVBXUsers--;
  183.  
  184.     // Unregister the about box's controlling window class if no more users.
  185.     if ((cVBXUsers == 0) && fAboutClassRegistered)
  186.     {
  187.         UnregisterClass(lpstrAboutBoxParent, hmodDLL);
  188.         fAboutClassRegistered = FALSE;
  189.     }
  190.  
  191. } // VBTERMCC
  192.  
  193.