home *** CD-ROM | disk | FTP | other *** search
/ On Hand / On_Hand_From_Softbank_1994_Release_2_Disc_2_1994.iso / 00202 / s / disk3 / xlist.c_ / xlist.bin
Text File  |  1993-04-28  |  21KB  |  729 lines

  1. //---------------------------------------------------------------------------
  2. //        Copyright (C) 1992-93 Microsoft Corporation
  3. //
  4. // You have a royalty-free right to use, modify, reproduce and distribute
  5. // the Sample Custom Control Files (and/or any modified version) in any way
  6. // you find useful, provided that you agree that Microsoft has no warranty,
  7. // obligation or liability for any Custom Control File.
  8. //---------------------------------------------------------------------------
  9. // XList.c
  10. //---------------------------------------------------------------------------
  11. // XList Custom Control
  12. //---------------------------------------------------------------------------
  13. // FUNCTIONS:
  14. //
  15. // XListCtlProc()      - Process Windows and Visual Basic messages
  16. //       CheckProperty()     - Validate setting of XLIST property
  17. //       SetPropertyArray()  - Set XLIST property stored in list item
  18. //       GetPropertyArray()  - Get value of XLIST property
  19. //       Methods()           - Process standard listbox methods
  20. //       DrawItem()           - Paint the item in the list
  21. //       MeasureItem()       - Return the height of the item in the list
  22. // LibMain()           - Perform DLL initialization tasks (DLL is loading)
  23. // VBGetModelInfo()    - Return model info to host
  24. // VBInitCC()           - Perform VBX intialization tasks: register model
  25. // WEP()           - Perform DLL termination tasks (DLL is unloading)
  26. //---------------------------------------------------------------------------
  27.  
  28. #include <windows.h>
  29. #include <vbapi.h>
  30. #include <memory.h>
  31. #include "xlist.h"
  32. #include "xlistvb1.h"
  33.  
  34. HANDLE hmodDLL;
  35.  
  36.  
  37. //---------------------------------------------------------------------------
  38. // Standard Error Values
  39. //---------------------------------------------------------------------------
  40. #define ERR_XLIST_NONE            0
  41. #define ERR_XLIST_BADINDEX      381  // Error$(381) = "Invalid property array index"
  42. #define ERR_XLIST_BADFORMAT    30000
  43. #define ERR_XLIST_FONTSIZE    30001
  44.  
  45.  
  46. //---------------------------------------------------------------------------
  47. // Other Constants
  48. //---------------------------------------------------------------------------
  49. #define USE_DEFAULT_PROC       -1
  50.  
  51.  
  52. //---------------------------------------------------------------------------
  53. // Local Prototypes
  54. //---------------------------------------------------------------------------
  55. LONG  NEAR PASCAL CheckProperty(USHORT iprop, LONG lp);
  56. VOID  NEAR PASCAL DrawItem(HCTL hctl, LPDRAWITEMSTRUCT lpdi);
  57. VOID  NEAR PASCAL FreeItemAttr(HWND hwnd, SHORT sIndex);
  58. HFONT NEAR PASCAL GetFontHandle(LPSTR lpFontName, int nHeight);
  59. int   NEAR PASCAL GetFontNameFromhFont(HFONT hFont, LPSTR szFontName);
  60. LONG  NEAR PASCAL GetPropertyArray(HCTL hctl, HWND hwnd, USHORT iprop, LPDATASTRUCT lpds);
  61. VOID  NEAR PASCAL MeasureItem(HCTL hctl, LPMEASUREITEMSTRUCT lpMI);
  62. LONG  NEAR PASCAL Methods(HWND hwnd, USHORT meth, LONG lp);
  63. LONG  NEAR PASCAL SetPropertyArray(HWND hwnd, USHORT iprop, LPDATASTRUCT lpds);
  64.  
  65.  
  66. //---------------------------------------------------------------------------
  67. // This routine is the subclassed window procedure.  Visual Basic passes
  68. // VBM_, VBN_, and WM_ messages to this routine.  The custom control
  69. // determines which messages to process.  Any messages that are not
  70. // processed need to passed on to the default message processing routine
  71. // VBDefControlProc().
  72. //---------------------------------------------------------------------------
  73. LONG FAR PASCAL _export XListCtlProc
  74. (
  75.     HCTL   hctl,
  76.     HWND   hwnd,
  77.     USHORT msg,
  78.     USHORT wp,
  79.     LONG   lp
  80. )
  81. {
  82.     LONG    lRetVal;
  83.     LPXLIST lpxlist;
  84.     SHORT   sItems;
  85.     SHORT   i;
  86.  
  87.     switch (msg)
  88.     {
  89.     case WM_CREATE:
  90.         // For each newly created control, set the default property
  91.         // values.
  92.         lpxlist = (LPXLIST)VBDerefControl(hctl);
  93.         lpxlist->itemDefHeight = DEFAULT_ITEM_HEIGHT;
  94.         lpxlist->bInvert = TRUE;
  95.         break;
  96.  
  97.     case VBM_METHOD:
  98.         // Respond to the AddItem and RemoveItem methods for the listbox.
  99.         lRetVal = Methods(hwnd, wp, lp);
  100.         if (lRetVal != USE_DEFAULT_PROC)
  101.         return lRetVal;
  102.         break;
  103.  
  104.         case VBM_CHECKPROPERTY:
  105.         // Validate the property setting before it is saved.
  106.         lRetVal = CheckProperty(wp, lp);
  107.         if (lRetVal != USE_DEFAULT_PROC)
  108.         return lRetVal;
  109.         break;
  110.  
  111.         case VBM_SETPROPERTY:
  112.         // Set the property value.
  113.         lRetVal = SetPropertyArray(hwnd, wp, (LPDATASTRUCT)lp);
  114.         if (lRetVal != USE_DEFAULT_PROC)
  115.         return lRetVal;
  116.         break;
  117.  
  118.         case VBM_GETPROPERTY:
  119.         // Get the property value.
  120.         switch (wp)
  121.         {
  122.         case IPROP_XLIST_ITEMBACKCOLOR:
  123.         case IPROP_XLIST_ITEMFONTNAME:
  124.         case IPROP_XLIST_ITEMFONTSIZE:
  125.         case IPROP_XLIST_ITEMFORECOLOR:
  126.         case IPROP_XLIST_ITEMIMAGE:
  127.             lRetVal = GetPropertyArray(hctl, hwnd, wp, (LPDATASTRUCT)lp);
  128.             if (lRetVal != USE_DEFAULT_PROC)
  129.             return lRetVal;
  130.             break;
  131.         }
  132.         break;
  133.  
  134.     case VBN_DRAWITEM:
  135.         // Draw the specified item in the listbox.
  136.         DrawItem(hctl, (LPDRAWITEMSTRUCT)lp);
  137.         return 0;
  138.  
  139.     case VBN_MEASUREITEM:
  140.         // Return the height of the specified item in the listbox.
  141.         MeasureItem(hctl, (LPMEASUREITEMSTRUCT)lp);
  142.         return 0;
  143.  
  144.     case WM_DESTROY:
  145.         // Deallocate all memory associated with the listbox item.
  146.         sItems = (SHORT)SendMessage(hwnd, LB_GETCOUNT, 0, 0L);
  147.  
  148.         for (i = 0; i < sItems; i++)
  149.         FreeItemAttr(hwnd, i);
  150.         break;
  151.     }
  152.  
  153.     return VBDefControlProc(hctl, hwnd, msg, wp, lp);
  154. }
  155.  
  156.  
  157. //---------------------------------------------------------------------------
  158. // Deallocate the memory that is stored with each item in the listbox.
  159. //---------------------------------------------------------------------------
  160. VOID NEAR PASCAL FreeItemAttr
  161. (
  162.     HWND  hwnd,
  163.     SHORT sIndex
  164. )
  165. {
  166.     HANDLE hAttr;
  167.     LPATTR lpAttr;
  168.  
  169.     hAttr = (HANDLE)SendMessage(hwnd, LB_GETITEMDATA, sIndex, 0L);
  170.     if (hAttr == (HANDLE)NULL)
  171.     return;
  172.  
  173.     lpAttr = (LPATTR)GlobalLock(hAttr);
  174.     if (lpAttr == (LPATTR)NULL)
  175.     return;
  176.  
  177.     if (lpAttr->hFont)
  178.     DeleteObject(lpAttr->hFont);
  179.  
  180.     if (lpAttr->hPic)
  181.     VBFreePic(lpAttr->hPic);
  182.  
  183.     GlobalUnlock(hAttr);
  184.     GlobalFree(hAttr);
  185. }
  186.  
  187.  
  188. //---------------------------------------------------------------------------
  189. // This routine validates the value of the property setting before it is
  190. // saved.
  191. //---------------------------------------------------------------------------
  192. LONG NEAR PASCAL CheckProperty
  193. (
  194.     USHORT iprop,
  195.     LONG   lp
  196. )
  197. {
  198.     PIC pic;
  199.  
  200.     switch (iprop)
  201.     {
  202.     case IPROP_XLIST_ITEMIMAGE:
  203.         // Verify the ItemImage property is a valid bitmap file.
  204.         VBGetPic((HPIC)lp, &pic);
  205.         switch (pic.picType)
  206.         {
  207.         case PICTYPE_BITMAP:
  208.             return ERR_XLIST_NONE;
  209.  
  210.         default:
  211.             return VBSetErrorMessage(ERR_XLIST_BADFORMAT,
  212.                          "Image format not supported.");
  213.         }
  214.     break;
  215.     }
  216.  
  217.     return USE_DEFAULT_PROC;
  218. }
  219.  
  220.  
  221. //---------------------------------------------------------------------------
  222. // This routine saves the value of the property setting, using the data
  223. // storage area of the list item.
  224. //---------------------------------------------------------------------------
  225. LONG NEAR PASCAL SetPropertyArray
  226. (
  227.     HWND     hwnd,
  228.     USHORT     iprop,
  229.     LPDATASTRUCT lpds
  230. )
  231. {
  232.     HANDLE  hAttr;
  233.     HANDLE  hFontNew = NULL;
  234.     LPATTR  lpAttr;
  235.     LONG    lReturn;
  236.     SHORT   i;
  237.  
  238.     switch (iprop)
  239.     {
  240.     case IPROP_XLIST_ITEMBACKCOLOR:
  241.     case IPROP_XLIST_ITEMFONTNAME:
  242.     case IPROP_XLIST_ITEMFONTSIZE:
  243.     case IPROP_XLIST_ITEMFORECOLOR:
  244.     case IPROP_XLIST_ITEMIMAGE:
  245.         break;
  246.  
  247.     default:
  248.        return USE_DEFAULT_PROC;
  249.     }
  250.  
  251.     i = (SHORT)lpds->index[0].data;
  252.  
  253.     hAttr = (HANDLE)SendMessage(hwnd, LB_GETITEMDATA, i, 0L);
  254.     if (hAttr == (HANDLE)LB_ERR)
  255.     return ERR_XLIST_BADINDEX;
  256.  
  257.     lpAttr = (LPATTR)GlobalLock(hAttr);
  258.  
  259.     lReturn = 0;
  260.     switch (iprop)
  261.     {
  262.     case IPROP_XLIST_ITEMBACKCOLOR:
  263.         lpAttr->cBack = (COLORREF)lpds->data;
  264.         break;
  265.  
  266.     case IPROP_XLIST_ITEMFONTNAME:
  267.         hFontNew = GetFontHandle((LPSTR)lpds->data, lpAttr->fontSize);
  268.         if (hFontNew) {
  269.             if (lpAttr->hFont)
  270.                 DeleteObject(lpAttr->hFont);
  271.             lpAttr->hFont = hFontNew;
  272.             }
  273.         else
  274.             lReturn = ERR_XLIST_BADINDEX;
  275.         break;
  276.  
  277.     case IPROP_XLIST_ITEMFONTSIZE:
  278.         {
  279.         char szFontName[255];
  280.  
  281.         if ((USHORT)lpds->data == lpAttr->fontSize)
  282.             break;
  283.  
  284.         lpAttr->fontSize = (USHORT)lpds->data;
  285.  
  286.         if (lpAttr->hFont == (HFONT)NULL)
  287.             break;
  288.  
  289.         if (GetFontNameFromhFont(lpAttr->hFont, (LPSTR)szFontName) == 0)
  290.             return ERR_XLIST_FONTSIZE;
  291.  
  292.         hFontNew = GetFontHandle((LPSTR)szFontName, lpAttr->fontSize);
  293.         if (hFontNew) {
  294.             if (lpAttr->hFont)
  295.                 DeleteObject(lpAttr->hFont);
  296.             lpAttr->hFont = hFontNew;
  297.             }
  298.         else
  299.             lReturn = ERR_XLIST_BADINDEX;
  300.         
  301.         }        
  302.         break;
  303.  
  304.     case IPROP_XLIST_ITEMFORECOLOR:
  305.         lpAttr->cFore = (COLORREF)lpds->data;
  306.         break;
  307.  
  308.     case IPROP_XLIST_ITEMIMAGE:
  309.         if (lpAttr->hPic)
  310.             VBFreePic(lpAttr->hPic);
  311.  
  312.         lpAttr->hPic = (HPIC)lpds->data;
  313.         VBRefPic(lpAttr->hPic);
  314.         break;
  315.     }
  316.  
  317.     GlobalUnlock(hAttr);
  318.  
  319.     if (lReturn == 0)
  320.         InvalidateRect(hwnd, NULL, TRUE);
  321.  
  322.     return lReturn;
  323. }
  324.  
  325.  
  326. //---------------------------------------------------------------------------
  327. // This routine retrieves the value of the property setting, using the data
  328. // storage area of the list item.
  329. //---------------------------------------------------------------------------
  330. LONG NEAR PASCAL GetPropertyArray
  331. (
  332.     HCTL     hctl,
  333.     HWND     hwnd,
  334.     USHORT     iprop,
  335.     LPDATASTRUCT lpds
  336. )
  337. {
  338.     HANDLE  hAttr;
  339.     LPATTR  lpAttr;
  340.     LONG    lReturn;
  341.     LOGFONT logfont;
  342.     SHORT   i;
  343.  
  344.     i = (SHORT)lpds->index[0].data;
  345.  
  346.     hAttr = (HANDLE)SendMessage(hwnd, LB_GETITEMDATA, i, 0L);
  347.     if (hAttr == (HANDLE)LB_ERR)
  348.     return ERR_XLIST_BADINDEX;
  349.  
  350.     lpAttr = (LPATTR)GlobalLock(hAttr);
  351.  
  352.     lReturn = 0;
  353.     switch (iprop)
  354.     {
  355.     case IPROP_XLIST_ITEMBACKCOLOR:
  356.         lpds->data = (LONG)lpAttr->cBack;
  357.         break;
  358.  
  359.     case IPROP_XLIST_ITEMFONTNAME:
  360.         if ((GetObject(lpAttr->hFont, sizeof(LOGFONT), (LPSTR)&logfont)) == 0)
  361.         return ERR_XLIST_BADINDEX;
  362.  
  363.         lpds->data = (LONG)VBCreateHsz((_segment)hctl, (LPSTR)logfont.lfFaceName);
  364.         break;
  365.  
  366.     case IPROP_XLIST_ITEMFONTSIZE:
  367.         lpds->data = (LONG)lpAttr->fontSize;
  368.         break;
  369.  
  370.     case IPROP_XLIST_ITEMFORECOLOR:
  371.         lpds->data = (LONG)lpAttr->cFore;
  372.         break;
  373.  
  374.     case IPROP_XLIST_ITEMIMAGE:
  375.         lpds->data = (LONG)lpAttr->hPic;
  376.         break;
  377.     }
  378.  
  379.     GlobalUnlock(hAttr);
  380.     return lReturn;
  381. }
  382.  
  383.  
  384. //---------------------------------------------------------------------------
  385. // This routine creates a font handle from the specified font name and font
  386. // size.
  387. //---------------------------------------------------------------------------
  388. HFONT NEAR PASCAL GetFontHandle
  389. (
  390.     LPSTR lpFontName,
  391.     int   nHeight
  392. )
  393. {
  394.     LOGFONT logfont;
  395.  
  396.     // Set all logical font values to 0 (default).
  397.     _fmemset(&logfont, '\0', sizeof(logfont));
  398.  
  399.     logfont.lfHeight = nHeight;
  400.     lstrcpy((LPSTR)logfont.lfFaceName, lpFontName);
  401.  
  402.     return CreateFontIndirect(&logfont);
  403. }
  404.  
  405.  
  406. //---------------------------------------------------------------------------
  407. // This routine returns the font name from a given a font handle.
  408. //---------------------------------------------------------------------------
  409. int NEAR PASCAL GetFontNameFromhFont
  410. (
  411.     HFONT hFont,
  412.     LPSTR szFaceName
  413. )
  414. {
  415.     LOGFONT logfont;
  416.  
  417.     if (GetObject(hFont, sizeof(LOGFONT), &logfont) == 0)
  418.         return 0;
  419.  
  420.     lstrcpy((LPSTR)szFaceName, (LPSTR)logfont.lfFaceName);
  421.     return 1;
  422. }
  423.  
  424.  
  425. //---------------------------------------------------------------------------
  426. // This routine handles the AddItem and RemoveItem methods.
  427. //---------------------------------------------------------------------------
  428. LONG NEAR PASCAL Methods
  429. (
  430.     HWND   hwnd,
  431.     USHORT meth,
  432.     LONG   lp
  433. )
  434. {
  435.     LPSTR   lpAddItem;
  436.     LPDWORD lpdwArgv;
  437.     SHORT   cIndex;
  438.     HANDLE  hAttr;
  439.     LPATTR  lpAttr;
  440.     SHORT   cItems;
  441.     LONG    lResult;
  442.  
  443.     lpdwArgv = (LPDWORD)lp;
  444.  
  445.     switch (meth)
  446.     {
  447.     case METH_ADDITEM:
  448.         cItems = (SHORT)SendMessage(hwnd, LB_GETCOUNT, 0, 0L);
  449.  
  450.         if ((USHORT)lpdwArgv[0] == 3)
  451.         {
  452.         cIndex = (SHORT)lpdwArgv[2];
  453.         if (cIndex >= cItems)
  454.             return ERR_XLIST_BADINDEX;
  455.         }
  456.         else
  457.         cIndex = -1;
  458.  
  459.         lpAddItem = VBDerefHsz((HSZ)lpdwArgv[1]);
  460.         cIndex = (USHORT)SendMessage(hwnd, LB_INSERTSTRING, cIndex, (DWORD)lpAddItem);
  461.  
  462.         // Allocate a structure and store the handle to it in the item
  463.         // that was just added to the listbox.
  464.         hAttr = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, sizeof(ATTR));
  465.         if (hAttr == (HANDLE)NULL)
  466.         return 0;
  467.  
  468.         lpAttr = (LPATTR)GlobalLock(hAttr);
  469.         lpAttr->cBack = GetSysColor(COLOR_WINDOW);
  470.         lpAttr->cFore = GetSysColor(COLOR_WINDOWTEXT);
  471.         GlobalUnlock(hAttr);
  472.         SendMessage(hwnd, LB_SETITEMDATA, cIndex, (DWORD)hAttr);
  473.         return 0L;
  474.  
  475.     case METH_REMOVEITEM:
  476.         cItems = (SHORT)SendMessage(hwnd, LB_GETCOUNT, 0, 0L);
  477.  
  478.         cIndex = (SHORT)lpdwArgv[1];
  479.         if (cIndex >= cItems)
  480.         return ERR_XLIST_BADINDEX;
  481.  
  482.         // Deallocate any allocated values corresponding to the item that
  483.         // is being deleted from the listbox.
  484.         FreeItemAttr(hwnd, cIndex);
  485.  
  486.         lResult = SendMessage(hwnd, LB_DELETESTRING, cIndex, 0L);
  487.         return ((lResult == LB_ERR) ? ERR_XLIST_BADINDEX : 0L);
  488.  
  489.     case METH_CLEAR:
  490.         // Deallocate all memory associated with the listbox item.
  491.         cItems = (SHORT)SendMessage(hwnd, LB_GETCOUNT, 0, 0L);
  492.  
  493.         for (cIndex = 0; cIndex < cItems; cIndex++)
  494.             FreeItemAttr(hwnd, cIndex);
  495.  
  496.         SendMessage(hwnd, LB_RESETCONTENT, 0, 0L);
  497.         return 0L;
  498.  
  499.     default:
  500.         return USE_DEFAULT_PROC;
  501.     }
  502. }
  503.  
  504.  
  505. //---------------------------------------------------------------------------
  506. // This routine paints the item in the listbox, using the attributes stored
  507. // with the item.
  508. //---------------------------------------------------------------------------
  509. VOID NEAR PASCAL DrawItem
  510. (
  511.     HCTL         hctl,
  512.     LPDRAWITEMSTRUCT lpdi
  513. )
  514. {
  515.     CHAR     buffer[255];
  516.     LPSTR    lpBuf;
  517.     HBRUSH   hBrush;
  518.     USHORT   usLen;
  519.     COLORREF cBack;
  520.     COLORREF cFore;
  521.     HFONT    hFont;
  522.     HFONT    hOldFont;
  523.     PIC      pic;
  524.     BITMAP   bmp;
  525.     HDC      hdcMem;
  526.     LPATTR   lpAttr;
  527.     HANDLE   hAttr;
  528.     HPIC     hPic;
  529.     LPXLIST  lpxlist;
  530.     SHORT    offset;
  531.  
  532.     switch (lpdi->itemAction)
  533.     {
  534.     case ODA_DRAWENTIRE:
  535.         hAttr = (HANDLE)SendMessage(lpdi->hwndItem, LB_GETITEMDATA, lpdi->itemID, 0L);
  536.         if (hAttr) {
  537.             lpAttr = (LPATTR)GlobalLock(hAttr);
  538.             cBack = lpAttr->cBack;
  539.             cFore = lpAttr->cFore;
  540.             hFont = lpAttr->hFont;
  541.             hPic = lpAttr->hPic;
  542.             GlobalUnlock(hAttr);
  543.         } else {
  544.             cBack = GetSysColor(COLOR_WINDOW);
  545.             cFore = GetSysColor(COLOR_WINDOWTEXT);
  546.             hFont = (HFONT)NULL;
  547.             hPic = (HPIC)NULL;
  548.         }
  549.  
  550.         hBrush = CreateSolidBrush(cBack);
  551.         FillRect(lpdi->hDC, (LPRECT)&lpdi->rcItem, hBrush);
  552.         DeleteObject(hBrush);
  553.         SetBkColor(lpdi->hDC, cBack);
  554.  
  555.         offset = 0;
  556.         if (hPic)
  557.         {
  558.         VBGetPic(hPic, &pic);
  559.         GetObject(pic.picData.bmp.hbitmap, sizeof(BITMAP), (LPSTR)&bmp);
  560.         hdcMem = CreateCompatibleDC(lpdi->hDC);
  561.         SelectObject(hdcMem, pic.picData.bmp.hbitmap);
  562.  
  563.         BitBlt(lpdi->hDC, lpdi->rcItem.left, lpdi->rcItem.top,
  564.             lpdi->rcItem.right - lpdi->rcItem.left + 1,
  565.             lpdi->rcItem.bottom - lpdi->rcItem.top + 1,
  566.             hdcMem, 0, 0, SRCCOPY);
  567.  
  568.         DeleteDC(hdcMem);
  569.         offset = (SHORT)(bmp.bmWidth * 1.25);
  570.         }
  571.  
  572.         lpBuf = (LPSTR)buffer;
  573.         SendMessage(lpdi->hwndItem, LB_GETTEXT, lpdi->itemID, (DWORD)lpBuf);
  574.         usLen = (USHORT)lstrlen(lpBuf);
  575.  
  576.         if (usLen)
  577.         {
  578.         SetTextColor(lpdi->hDC, cFore);
  579.  
  580.         hOldFont = NULL;
  581.         if (hFont)
  582.             hOldFont = SelectObject(lpdi->hDC, hFont);
  583.  
  584.         lpdi->rcItem.left += offset;
  585.         DrawText(lpdi->hDC, lpBuf, usLen, &lpdi->rcItem, DT_LEFT);
  586.  
  587.         if (hOldFont)
  588.             SelectObject(lpdi->hDC, hOldFont);
  589.         }
  590.  
  591.         if (lpdi->itemState != ODS_SELECTED)
  592.         break;
  593.  
  594.         /*    FALL THROUGH  */
  595.  
  596.     case ODA_SELECT:
  597.         lpxlist = (LPXLIST)VBDerefControl(hctl);
  598.         if (lpxlist->bInvert)
  599.         InvertRect(lpdi->hDC, &lpdi->rcItem);
  600.         break;
  601.  
  602.     case ODA_FOCUS:
  603.         DrawFocusRect(lpdi->hDC, &lpdi->rcItem);
  604.         break;
  605.     }
  606. }
  607.  
  608.  
  609. //---------------------------------------------------------------------------
  610. // This routine retrieves the height of the items in the listbox.
  611. //---------------------------------------------------------------------------
  612. VOID NEAR PASCAL MeasureItem
  613. (
  614.     HCTL        hctl,
  615.     LPMEASUREITEMSTRUCT lpMI
  616. )
  617. {
  618.     LPXLIST lpxlist;
  619.  
  620.     lpxlist = (LPXLIST)VBDerefControl(hctl);
  621.  
  622.     // Convert the height to pixels before setting the value.
  623.     if (lpxlist->itemDefHeight)
  624.     lpMI->itemHeight = VBYTwipsToPixels(lpxlist->itemDefHeight);
  625.     else
  626.     lpMI->itemHeight = VBYTwipsToPixels(DEFAULT_ITEM_HEIGHT);
  627. }
  628.  
  629.  
  630. //---------------------------------------------------------------------------
  631. // This routine is called when the first client loads the DLL.
  632. //---------------------------------------------------------------------------
  633. BOOL FAR PASCAL LibMain
  634. (
  635.     HANDLE hmod,
  636.     HANDLE wDataSeg,
  637.     USHORT cbHeapSize,
  638.     LPSTR  lpszCmdLine
  639. )
  640. {
  641.     // Avoid warnings on unused (but required) formal parameters.
  642.     wDataSeg    = wDataSeg;
  643.     cbHeapSize    = cbHeapSize;
  644.     lpszCmdLine = lpszCmdLine;
  645.     
  646.     hmodDLL = hmod;
  647.  
  648.     return TRUE;
  649. }
  650.  
  651.  
  652. //---------------------------------------------------------------------------
  653. // Provide custom control model information to host environment.
  654. //---------------------------------------------------------------------------
  655. LPMODELINFO FAR PASCAL _export VBGetModelInfo
  656. (
  657.     USHORT usVersion
  658. )
  659. {
  660.     if (usVersion < VB_VERSION)
  661.     return (LPMODELINFO)&modelXList_Vb1;
  662.     else
  663.     return (LPMODELINFO)&modelXList;
  664. }
  665.  
  666.  
  667. //---------------------------------------------------------------------------
  668. // This routine is called by VB when the custom control DLL is loaded for
  669. // use.
  670. //---------------------------------------------------------------------------
  671. BOOL FAR PASCAL _export VBInitCC
  672. (
  673.     USHORT usVersion,
  674.     BOOL   bRuntime
  675. )
  676. {
  677.     // Avoid warnings on unused (but required) formal parameters.
  678.     bRuntime  = bRuntime;
  679.  
  680.     // Register the XList control according to the VB version.
  681.     if (usVersion < VB_VERSION)
  682.     return VBRegisterModel(hmodDLL, &modelXList_Vb1);
  683.     else
  684.     return VBRegisterModel(hmodDLL, &modelXList);
  685. }
  686.  
  687.  
  688. //---------------------------------------------------------------------------
  689. // WEP
  690. //---------------------------------------------------------------------------
  691. // C7 and QCWIN provide default a WEP:
  692. //---------------------------------------------------------------------------
  693. #if (_MSC_VER < 610)
  694.  
  695. int FAR PASCAL WEP(int fSystemExit);
  696.  
  697. //---------------------------------------------------------------------------
  698. // For Windows 3.0 it is recommended that the WEP function reside in a
  699. // FIXED code segment and be exported as RESIDENTNAME.  This is
  700. // accomplished using the alloc_text pragma below and the related EXPORTS
  701. // and SEGMENTS directives in the .DEF file.
  702. //
  703. // Read the comments section documenting the WEP function in the Windows
  704. // 3.1 SDK "Programmers Reference, Volume 2: Functions" before placing
  705. // any additional code in the WEP routine for a Windows 3.0 DLL.
  706. //---------------------------------------------------------------------------
  707. #pragma alloc_text(WEP_TEXT,WEP)
  708.  
  709. //---------------------------------------------------------------------------
  710. // Performs cleanup tasks when the DLL is unloaded.  WEP() is
  711. // called automatically by Windows when the DLL is unloaded (no
  712. // remaining tasks still have the DLL loaded).    It is strongly
  713. // recommended that a DLL have a WEP() function, even if it does
  714. // nothing but returns success (1), as in this example.
  715. //---------------------------------------------------------------------------
  716. int FAR PASCAL WEP
  717. (
  718.     int fSystemExit
  719. )
  720. {
  721.     // Avoid warnings on unused (but required) formal parameters
  722.     fSystemExit = fSystemExit;
  723.  
  724.     return 1;
  725. }
  726. #endif // C6
  727.  
  728. //---------------------------------------------------------------------------
  729.