home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / v / vlistbox.zip / VLSCROLL.C < prev    next >
C/C++ Source or Header  |  1993-01-26  |  24KB  |  688 lines

  1. #include "vlistint.h"
  2.  
  3. #include <string.h>
  4.  
  5. static void SetFocustoLB(PVLBOX pVLBox);
  6. static void SetFocustoVLB(PVLBOX pVLBox);
  7.  
  8. int VLBScrollDownLine( PVLBOX pVLBox)
  9. {
  10.     RECT   UpdRect;
  11.     int    nSelected;
  12.     LONG   lFreeItem;
  13.  
  14.     if ( pVLBox->wFlags & USEDATAVALUES ) {
  15.         pVLBox->vlbStruct.lIndex = -1L;
  16.         lFreeItem = SendMessage(pVLBox->hwndList, LB_GETITEMDATA, 0, 0L);
  17.     }
  18.     else {
  19.         pVLBox->vlbStruct.lIndex = pVLBox->lToplIndex + pVLBox->nLines - 1L;
  20.         lFreeItem = pVLBox->lToplIndex;
  21.     }
  22.  
  23.     pVLBox->vlbStruct.lpTextPointer = NULL;
  24.     pVLBox->vlbStruct.lData = SendMessage(pVLBox->hwndList, LB_GETITEMDATA, pVLBox->nCountInBox-1, 0L);
  25.     pVLBox->vlbStruct.nCtlID = pVLBox->nId;
  26.     SendMessage(pVLBox->hwndParent, VLB_NEXT, 0, (LPARAM)((LPVLBSTRUCT)&(pVLBox->vlbStruct)));
  27.     if ( pVLBox->vlbStruct.nStatus == VLB_OK ) {
  28.        nSelected = (int)SendMessage(pVLBox->hwndList, LB_GETCURSEL, 0, 0L);
  29.        if ( nSelected == 0 ) {
  30.            SendMessage(pVLBox->hwndList, LB_SETCURSEL, (WPARAM)-1, (LPARAM)0L);
  31.            SetFocustoVLB(pVLBox);
  32.        }
  33.  
  34.        //
  35.        // Remove the top String
  36.        //
  37.        SendMessage(pVLBox->hwndList, LB_DELETESTRING, 0, 0L);
  38.        SendMessage(pVLBox->hwndParent, VLBN_FREEITEM, pVLBox->nId, lFreeItem);
  39.  
  40.        //
  41.        // Add the new line
  42.        //
  43.        if ( pVLBox->wFlags & HASSTRINGS) {
  44.            SendMessage(pVLBox->hwndList, LB_ADDSTRING, 0, (LPARAM) pVLBox->vlbStruct.lpTextPointer);
  45.            SendMessage(pVLBox->hwndList, LB_SETITEMDATA, pVLBox->nCountInBox-1, pVLBox->vlbStruct.lData);
  46.        }
  47.        else
  48.            SendMessage(pVLBox->hwndList, LB_ADDSTRING, 0, (LPARAM) pVLBox->vlbStruct.lData);
  49.  
  50.  
  51.  
  52.        pVLBox->lToplIndex++;
  53.        UpdateVLBWindow(pVLBox, &UpdRect);
  54.  
  55.        //
  56.        // Tell Windows not to paint the whole LB
  57.        //
  58.        ValidateRect(pVLBox->hwndList, NULL);
  59.  
  60.        //
  61.        // Scroll the window up
  62.        //
  63.        ScrollWindow(pVLBox->hwndList, 0, (-1)*pVLBox->nchHeight, NULL, NULL);
  64.  
  65.        //
  66.        // Now tell windows the bottom line needs fixing
  67.        //
  68.        SendMessage(pVLBox->hwndList, LB_GETITEMRECT,
  69.                    pVLBox->nLines-1, (LPARAM) (LPRECT) &UpdRect);
  70.  
  71.        InvalidateRect(pVLBox->hwndList, &UpdRect, TRUE);
  72.  
  73.        UpdateWindow(pVLBox->hwndList);
  74.  
  75.        if ( TestSelectedItem(pVLBox, pVLBox->vlbStruct) ) {
  76.           SendMessage(pVLBox->hwndList, LB_SETCURSEL, pVLBox->nLines-1, 0L);
  77.           SetFocustoLB(pVLBox);
  78.        }
  79.        else if ( nSelected != LB_ERR ) {
  80.           if ( nSelected != 0 ) {
  81.               // Need to move the selection Up 1
  82.               SendMessage(pVLBox->hwndList, LB_SETCURSEL, nSelected-1, 0L);
  83.           }
  84.        }
  85.  
  86.  
  87.        return VLB_OK;
  88.     }
  89.     return VLB_ERR;
  90. }
  91.  
  92. int VLBScrollUpLine( PVLBOX pVLBox)
  93. {
  94.     RECT   UpdRect;
  95.     RECT   ListRect;
  96.     RECT   FAR *lpRect;
  97.     int    nSelected;
  98.     LONG   lFreeItem;
  99.  
  100.     if ( pVLBox->wFlags & USEDATAVALUES ) {
  101.         pVLBox->vlbStruct.lIndex = -1L;
  102.         lFreeItem = SendMessage(pVLBox->hwndList, LB_GETITEMDATA, pVLBox->nCountInBox-1, 0L);
  103.     }
  104.     else {
  105.         pVLBox->vlbStruct.lIndex = pVLBox->lToplIndex;
  106.         lFreeItem = pVLBox->lToplIndex + pVLBox->nLines - 1L;
  107.     }
  108.  
  109.     pVLBox->vlbStruct.lpTextPointer = NULL;
  110.     pVLBox->vlbStruct.lData = SendMessage(pVLBox->hwndList, LB_GETITEMDATA, 0, 0L);
  111.     pVLBox->vlbStruct.nCtlID = pVLBox->nId;
  112.     SendMessage(pVLBox->hwndParent, VLB_PREV, 0, (LPARAM)(LPVLBSTRUCT)&(pVLBox->vlbStruct));
  113.     if ( pVLBox->vlbStruct.nStatus  == VLB_OK ) {
  114.        nSelected = (int)SendMessage(pVLBox->hwndList, LB_GETCURSEL, 0, 0L);
  115.        if ( nSelected == pVLBox->nLines-1 ) {
  116.           SendMessage(pVLBox->hwndList, LB_SETCURSEL, (WPARAM)-1, (LPARAM)0L);
  117.           SetFocustoVLB(pVLBox);
  118.        }
  119.  
  120.        //
  121.        // Remove the bottom String
  122.        //
  123.        SendMessage(pVLBox->hwndList, LB_DELETESTRING, pVLBox->nLines-1, 0L);
  124.        SendMessage(pVLBox->hwndParent, VLBN_FREEITEM, pVLBox->nId, lFreeItem);
  125.  
  126.        //
  127.        // Add the new line
  128.        //
  129.        if ( pVLBox->wFlags & HASSTRINGS) {
  130.            SendMessage(pVLBox->hwndList, LB_INSERTSTRING, 0, (LPARAM) pVLBox->vlbStruct.lpTextPointer);
  131.            SendMessage(pVLBox->hwndList, LB_SETITEMDATA, 0, pVLBox->vlbStruct.lData);
  132.        }
  133.        else
  134.            SendMessage(pVLBox->hwndList, LB_INSERTSTRING, 0, (LPARAM) pVLBox->vlbStruct.lData);
  135.  
  136.        pVLBox->lToplIndex--;
  137.        UpdateVLBWindow(pVLBox, &UpdRect);
  138.  
  139.        //
  140.        // Tell Windows not to paint the whole LB
  141.        //
  142.        ValidateRect(pVLBox->hwndList, NULL);
  143.  
  144.        //
  145.        // Check for partial line at bottom...
  146.        // if so clear it
  147.        //
  148.        SendMessage(pVLBox->hwndList, LB_GETITEMRECT,
  149.                    pVLBox->nLines-1, (LPARAM)(LPRECT)&UpdRect);
  150.  
  151.        GetClientRect(pVLBox->hwndList, &ListRect);
  152.        if ( pVLBox->bHScrollBar || (UpdRect.bottom != ListRect.bottom) ) {
  153.            ListRect.bottom = UpdRect.top ;
  154.            lpRect = &ListRect;
  155.        }
  156.        else {
  157.            lpRect = NULL;
  158.        }
  159.  
  160.        //
  161.        // Scroll the window down
  162.        //
  163.        ScrollWindow(pVLBox->hwndList, 0, pVLBox->nchHeight, lpRect, NULL);
  164.  
  165.        //
  166.        // Now tell windows the top line needs fixing
  167.        //
  168.        SendMessage(pVLBox->hwndList, LB_GETITEMRECT,
  169.                    0, (LPARAM)(LPRECT)&UpdRect);
  170.        InvalidateRect(pVLBox->hwndList, &UpdRect, TRUE);
  171.        UpdateWindow(pVLBox->hwndList);
  172.  
  173.        if ( TestSelectedItem(pVLBox, pVLBox->vlbStruct) ) {
  174.           SendMessage(pVLBox->hwndList, LB_SETCURSEL, 0, 0L);
  175.           SetFocustoLB(pVLBox);
  176.        }
  177.        else if ( nSelected != LB_ERR ) {
  178.           if ( nSelected !=  pVLBox->nLines-1) {
  179.               // Need to move the selection Up 1
  180.               SendMessage(pVLBox->hwndList, LB_SETCURSEL, nSelected+1, 0L);
  181.           }
  182.        }
  183.  
  184.  
  185.        return VLB_OK;
  186.     }
  187.     return VLB_ERR;
  188. }
  189.  
  190.  
  191. int VLBScrollDownPage( PVLBOX pVLBox, int nAdjustment)
  192. {
  193.     int  nCount;
  194.     int  nSelected;
  195.     LONG lFreeItem;
  196.  
  197.     nSelected = (int)SendMessage(pVLBox->hwndList, LB_GETCURSEL, 0, 0L);
  198.     if ( nSelected == LB_ERR )
  199.         nSelected = -10000;
  200.  
  201.     SendMessage(pVLBox->hwndList, LB_SETCURSEL, (WPARAM)-1, (LPARAM)0L);
  202.     SetFocustoVLB(pVLBox);
  203.  
  204.     for ( nCount = 0; nCount < pVLBox->nLines+nAdjustment; nCount++) {
  205.         if ( pVLBox->wFlags & USEDATAVALUES )
  206.             pVLBox->vlbStruct.lIndex = -1L;
  207.         else
  208.             pVLBox->vlbStruct.lIndex = pVLBox->lToplIndex + pVLBox->nLines - 1L;
  209.  
  210.         pVLBox->vlbStruct.lpTextPointer = NULL;
  211.         pVLBox->vlbStruct.lData = SendMessage(pVLBox->hwndList, LB_GETITEMDATA, pVLBox->nCountInBox-1, 0L);
  212.         pVLBox->vlbStruct.nCtlID = pVLBox->nId;
  213.         SendMessage(pVLBox->hwndParent, VLB_NEXT, 0, (LPARAM)(LPVLBSTRUCT)&(pVLBox->vlbStruct));
  214.         if (  pVLBox->vlbStruct.nStatus == VLB_OK ) {
  215.  
  216.            if ( nCount == 0 )
  217.               vlbRedrawOff(pVLBox);
  218.  
  219.            if ( pVLBox->wFlags & USEDATAVALUES ) {
  220.                lFreeItem = SendMessage(pVLBox->hwndList, LB_GETITEMDATA, 0, 0L);
  221.            }
  222.            else {
  223.                lFreeItem = pVLBox->lToplIndex;
  224.            }
  225.            SendMessage(pVLBox->hwndList, LB_DELETESTRING, 0, 0L);
  226.            SendMessage(pVLBox->hwndParent, VLBN_FREEITEM, pVLBox->nId, lFreeItem);
  227.  
  228.            if ( pVLBox->wFlags & HASSTRINGS) {
  229.                SendMessage(pVLBox->hwndList, LB_ADDSTRING, 0, (LPARAM) pVLBox->vlbStruct.lpTextPointer);
  230.                SendMessage(pVLBox->hwndList, LB_SETITEMDATA, pVLBox->nCountInBox-1, pVLBox->vlbStruct.lData);
  231.            }
  232.            else
  233.                SendMessage(pVLBox->hwndList, LB_ADDSTRING, 0, (LPARAM) pVLBox->vlbStruct.lData);
  234.  
  235.            if ( TestSelectedItem(pVLBox, pVLBox->vlbStruct) ) {
  236.               nSelected = pVLBox->nLines-1;
  237.            }
  238.            else {
  239.               nSelected--;
  240.            }
  241.  
  242.            pVLBox->lToplIndex++;
  243.  
  244.         }
  245.         else {
  246.             if ( nCount == 0 )
  247.                 return VLB_ERR;
  248.             break;
  249.         }
  250.     }
  251.  
  252.     if ( nSelected >= 0 ) {
  253.        SendMessage(pVLBox->hwndList, LB_SETCURSEL, nSelected, 0L);
  254.        SetFocustoLB(pVLBox);
  255.     }
  256.     else {
  257.        SetFocustoVLB(pVLBox);
  258.        SendMessage(pVLBox->hwndList, LB_SETCURSEL, (WPARAM)-1, (LPARAM)0L);
  259.     }
  260.  
  261.     UpdateVLBWindow(pVLBox, NULL);
  262.     vlbRedrawOn(pVLBox);
  263.     return VLB_OK;
  264.  
  265. }
  266.  
  267.  
  268. int VLBScrollUpPage( PVLBOX pVLBox, int nAdjustment)
  269. {
  270.     int  nCount;
  271.     int  nSelected;
  272.     LONG lFreeItem;
  273.  
  274.     nSelected = (int)SendMessage(pVLBox->hwndList, LB_GETCURSEL, 0, 0L);
  275.     if ( nSelected == LB_ERR )
  276.         nSelected = -10000;
  277.  
  278.     SetFocustoVLB(pVLBox);
  279.     SendMessage(pVLBox->hwndList, LB_SETCURSEL, (WPARAM)-1, (LPARAM)0L);
  280.  
  281.     for ( nCount = 0; nCount < pVLBox->nLines+nAdjustment; nCount++) {
  282.         if ( pVLBox->wFlags & USEDATAVALUES ) {
  283.             pVLBox->vlbStruct.lIndex = -1L;
  284.         }
  285.         else {
  286.             pVLBox->vlbStruct.lIndex = pVLBox->lToplIndex;
  287.         }
  288.  
  289.         pVLBox->vlbStruct.lpTextPointer = NULL;
  290.         pVLBox->vlbStruct.lData = SendMessage(pVLBox->hwndList, LB_GETITEMDATA, 0, 0L);
  291.         pVLBox->vlbStruct.nCtlID = pVLBox->nId;
  292.         SendMessage(pVLBox->hwndParent, VLB_PREV, 0, (LPARAM)(LPVLBSTRUCT)&(pVLBox->vlbStruct));
  293.         if ( pVLBox->vlbStruct.nStatus  == VLB_OK ) {
  294.            if ( nCount == 0 )
  295.               vlbRedrawOff(pVLBox);
  296.  
  297.            if ( pVLBox->wFlags & HASSTRINGS) {
  298.                SendMessage(pVLBox->hwndList, LB_INSERTSTRING, 0, (LPARAM) pVLBox->vlbStruct.lpTextPointer);
  299.                SendMessage(pVLBox->hwndList, LB_SETITEMDATA, 0, pVLBox->vlbStruct.lData);
  300.            }
  301.            else
  302.                SendMessage(pVLBox->hwndList, LB_INSERTSTRING, 0, (LPARAM) pVLBox->vlbStruct.lData);
  303.  
  304.            if ( TestSelectedItem(pVLBox, pVLBox->vlbStruct) ) {
  305.               nSelected = 0;
  306.            }
  307.            else {
  308.               nSelected++;
  309.            }
  310.  
  311.            if ( pVLBox->wFlags & USEDATAVALUES ) {
  312.                lFreeItem = SendMessage(pVLBox->hwndList, LB_GETITEMDATA, pVLBox->nLines, 0L);
  313.            }
  314.            else {
  315.                lFreeItem = pVLBox->lToplIndex + pVLBox->nLines - 1L;
  316.            }
  317.            SendMessage(pVLBox->hwndList, LB_DELETESTRING, pVLBox->nLines, 0L);
  318.            SendMessage(pVLBox->hwndParent, VLBN_FREEITEM, pVLBox->nId, lFreeItem);
  319.  
  320.            pVLBox->lToplIndex--;
  321.         }
  322.         else  {
  323.             if ( nCount == 0 )
  324.                return VLB_ERR;
  325.            break;
  326.         }
  327.     }
  328.  
  329.     if ( nSelected >= 0 && nSelected <= pVLBox->nLines ) {
  330.        SendMessage(pVLBox->hwndList, LB_SETCURSEL, nSelected, 0L);
  331.        SetFocustoLB(pVLBox);
  332.     }
  333.     else {
  334.        SetFocustoVLB(pVLBox);
  335.        SendMessage(pVLBox->hwndList, LB_SETCURSEL, (WPARAM)-1, (LPARAM)0L);
  336.     }
  337.  
  338.     UpdateVLBWindow(pVLBox, NULL);
  339.     vlbRedrawOn(pVLBox);
  340.     return VLB_OK;
  341. }
  342.  
  343.  
  344. void UpdateVLBWindow( PVLBOX pVLBox, LPRECT lpRect)
  345. {
  346.     int   nPos;
  347.  
  348.     if ( pVLBox->lNumLogicalRecs == -1L )
  349.        SetScrollPos(pVLBox->hwndList, SB_VERT, 50, TRUE);
  350.     else {
  351.        if ( pVLBox->lNumLogicalRecs <= pVLBox->nLines ) {
  352.           if ( pVLBox->styleSave & VLBS_DISABLENOSCROLL )
  353.              EnableScrollBar(pVLBox->hwndList, SB_VERT, ESB_DISABLE_BOTH);
  354.           else
  355.              ShowScrollBar(pVLBox->hwndList, SB_VERT, FALSE);
  356.        }
  357.        else {
  358.            if ( pVLBox->styleSave & VLBS_DISABLENOSCROLL )
  359.               EnableScrollBar(pVLBox->hwndList, SB_VERT, ESB_ENABLE_BOTH);
  360.            else
  361.               ShowScrollBar(pVLBox->hwndList, SB_VERT, TRUE);
  362.            if ( pVLBox->lToplIndex >= (pVLBox->lNumLogicalRecs-pVLBox->nLines) ) {
  363.                nPos = 100;
  364.            }
  365.            else if (pVLBox->lToplIndex == 0L) {
  366.                nPos = 0;
  367.            }
  368.            else {
  369.                nPos = (int) ((pVLBox->lToplIndex*100L) / (pVLBox->lNumLogicalRecs-pVLBox->nLines+1));
  370.            }
  371.            SetScrollPos(pVLBox->hwndList, SB_VERT, nPos, TRUE);
  372.        }
  373.  
  374.     }
  375.  
  376. }
  377.  
  378.  
  379.  
  380. int VLBFindPos( PVLBOX pVLBox, int nPos)
  381. {
  382.     pVLBox->vlbStruct.lpTextPointer = NULL;
  383.     pVLBox->vlbStruct.lIndex = (LONG) nPos;
  384.     pVLBox->vlbStruct.lData = (LONG) nPos;
  385.     pVLBox->vlbStruct.nCtlID = pVLBox->nId;
  386.     SendMessage(pVLBox->hwndParent, VLB_FINDPOS, 0, (LPARAM)(LPVLBSTRUCT)&(pVLBox->vlbStruct));
  387.     if ( pVLBox->vlbStruct.nStatus  == VLB_OK ) {
  388.        SetFocustoVLB(pVLBox);
  389.        vlbRedrawOff(pVLBox);
  390.        SendMessage(pVLBox->hwndList, LB_RESETCONTENT, 0, 0L);
  391.        SendMessage(pVLBox->hwndParent, VLBN_FREEALL, pVLBox->nId, 0L);
  392.  
  393.        if ( pVLBox->wFlags & HASSTRINGS) {
  394.            SendMessage(pVLBox->hwndList, LB_ADDSTRING, 0, (LPARAM) pVLBox->vlbStruct.lpTextPointer);
  395.            SendMessage(pVLBox->hwndList, LB_SETITEMDATA, 0, pVLBox->vlbStruct.lData);
  396.        }
  397.        else
  398.            SendMessage(pVLBox->hwndList, LB_ADDSTRING, 0, (LPARAM) pVLBox->vlbStruct.lData);
  399.  
  400.        if ( TestSelectedItem(pVLBox, pVLBox->vlbStruct) ) {
  401.           SendMessage(pVLBox->hwndList, LB_SETCURSEL, 0, 0L);
  402.           SetFocustoLB(pVLBox);
  403.        }
  404.  
  405.        if ( pVLBox->lNumLogicalRecs == -1L )
  406.           pVLBox->lToplIndex = pVLBox->vlbStruct.lData;
  407.        else if ( pVLBox->wFlags & USEDATAVALUES )
  408.           pVLBox->lToplIndex = (LONG)nPos* (pVLBox->lNumLogicalRecs-pVLBox->nLines+1)/100L;
  409.        else
  410.           pVLBox->lToplIndex = pVLBox->vlbStruct.lIndex;
  411.  
  412.        pVLBox->vlbStruct.lIndex = 0L;
  413.        pVLBox->nCountInBox = 1;
  414.        while ( pVLBox->nCountInBox < pVLBox->nLines ) {
  415.           pVLBox->vlbStruct.nCtlID = pVLBox->nId;
  416.           SendMessage(pVLBox->hwndParent, VLB_NEXT, 0, (LPARAM)(LPVLBSTRUCT)&(pVLBox->vlbStruct));
  417.           if ( pVLBox->vlbStruct.nStatus  == VLB_OK ) {
  418.              if ( pVLBox->wFlags & HASSTRINGS) {
  419.                  SendMessage(pVLBox->hwndList, LB_ADDSTRING, 0, (LPARAM) pVLBox->vlbStruct.lpTextPointer);
  420.                  SendMessage(pVLBox->hwndList, LB_SETITEMDATA, pVLBox->nCountInBox, pVLBox->vlbStruct.lData);
  421.              }
  422.              else
  423.                  SendMessage(pVLBox->hwndList, LB_ADDSTRING, 0, (LPARAM) pVLBox->vlbStruct.lData);
  424.  
  425.              if ( TestSelectedItem(pVLBox, pVLBox->vlbStruct) ) {
  426.                 SendMessage(pVLBox->hwndList, LB_SETCURSEL, 0, 0L);
  427.                 SetFocustoLB(pVLBox);
  428.              }
  429.  
  430.              pVLBox->nCountInBox++;
  431.           }
  432.           else
  433.             break;
  434.        }
  435.        UpdateVLBWindow(pVLBox, NULL);
  436.        vlbRedrawOn(pVLBox);
  437.        return VLB_OK;
  438.     }
  439.     else
  440.         return VLB_ERR;
  441. }
  442.  
  443.  
  444. int VLBFindPage( PVLBOX pVLBox, LONG lFindRecNum, BOOL bUpdateTop)
  445. {
  446.     int nSelected;
  447.  
  448.     nSelected = -1000;
  449.     pVLBox->vlbStruct.lpTextPointer = NULL;
  450.     pVLBox->vlbStruct.lData = pVLBox->vlbStruct.lIndex = lFindRecNum;
  451.     pVLBox->vlbStruct.nCtlID = pVLBox->nId;
  452.     SendMessage(pVLBox->hwndParent, VLB_FINDITEM, 0, (LPARAM)(LPVLBSTRUCT)&(pVLBox->vlbStruct));
  453.     if ( pVLBox->vlbStruct.nStatus  == VLB_OK ) {
  454.        SetFocustoVLB(pVLBox);
  455.        vlbRedrawOff(pVLBox);
  456.        SendMessage(pVLBox->hwndList, LB_RESETCONTENT, 0, 0L);
  457.        SendMessage(pVLBox->hwndParent, VLBN_FREEALL, pVLBox->nId, 0L);
  458.  
  459.        if ( pVLBox->wFlags & HASSTRINGS) {
  460.            SendMessage(pVLBox->hwndList, LB_ADDSTRING, 0, (LPARAM) pVLBox->vlbStruct.lpTextPointer);
  461.            SendMessage(pVLBox->hwndList, LB_SETITEMDATA, 0, pVLBox->vlbStruct.lData);
  462.        }
  463.        else
  464.            SendMessage(pVLBox->hwndList, LB_ADDSTRING, 0, (LPARAM) pVLBox->vlbStruct.lData);
  465.  
  466.        if ( TestSelectedItem(pVLBox, pVLBox->vlbStruct) ) {
  467.           nSelected = 0;
  468.        }
  469.  
  470.        if ( bUpdateTop ) {
  471.            if ( pVLBox->lNumLogicalRecs == -1L )
  472.               pVLBox->lToplIndex = pVLBox->vlbStruct.lData;
  473.            else if ( pVLBox->wFlags & USEDATAVALUES )
  474.               pVLBox->lToplIndex = pVLBox->lNumLogicalRecs/2L;
  475.            else
  476.               pVLBox->lToplIndex = pVLBox->vlbStruct.lIndex;
  477.        }
  478.  
  479.        pVLBox->vlbStruct.lIndex = lFindRecNum;
  480.        pVLBox->nCountInBox = 1;
  481.        while ( pVLBox->nCountInBox < pVLBox->nLines ) {
  482.           pVLBox->vlbStruct.nCtlID = pVLBox->nId;
  483.           SendMessage(pVLBox->hwndParent, VLB_NEXT, 0, (LPARAM)(LPVLBSTRUCT)&(pVLBox->vlbStruct));
  484.           if ( pVLBox->vlbStruct.nStatus  == VLB_OK ) {
  485.              if ( pVLBox->wFlags & HASSTRINGS) {
  486.                  SendMessage(pVLBox->hwndList, LB_ADDSTRING, 0, (LPARAM) pVLBox->vlbStruct.lpTextPointer);
  487.                  SendMessage(pVLBox->hwndList, LB_SETITEMDATA, pVLBox->nCountInBox, pVLBox->vlbStruct.lData);
  488.              }
  489.              else
  490.                  SendMessage(pVLBox->hwndList, LB_ADDSTRING, 0, (LPARAM) pVLBox->vlbStruct.lData);
  491.  
  492.              if ( TestSelectedItem(pVLBox, pVLBox->vlbStruct) ) {
  493.                  nSelected = pVLBox->nCountInBox;
  494.              }
  495.  
  496.              pVLBox->nCountInBox++;
  497.           }
  498.           else
  499.             break;
  500.        }
  501.  
  502.        if ( pVLBox->nCountInBox < pVLBox->nLines ) {
  503.           if ( pVLBox->wFlags & USEDATAVALUES )
  504.               pVLBox->vlbStruct.lIndex = -1L;
  505.           else
  506.               pVLBox->vlbStruct.lIndex = pVLBox->lToplIndex;
  507.           pVLBox->vlbStruct.lpTextPointer = NULL;
  508.           pVLBox->vlbStruct.lData = SendMessage(pVLBox->hwndList, LB_GETITEMDATA, 0, 0L);
  509.           while ( pVLBox->nCountInBox < pVLBox->nLines ) {
  510.              pVLBox->vlbStruct.nCtlID = pVLBox->nId;
  511.              SendMessage(pVLBox->hwndParent, VLB_PREV, 0, (LPARAM)(LPVLBSTRUCT)&(pVLBox->vlbStruct));
  512.              if ( pVLBox->vlbStruct.nStatus  == VLB_OK ) {
  513.                 if ( pVLBox->wFlags & HASSTRINGS) {
  514.                     SendMessage(pVLBox->hwndList, LB_INSERTSTRING, 0, (LPARAM) pVLBox->vlbStruct.lpTextPointer);
  515.                     SendMessage(pVLBox->hwndList, LB_SETITEMDATA, 0, pVLBox->vlbStruct.lData);
  516.                 }
  517.                 else
  518.                     SendMessage(pVLBox->hwndList, LB_INSERTSTRING, 0, (LPARAM) pVLBox->vlbStruct.lData);
  519.  
  520.                 if ( TestSelectedItem(pVLBox, pVLBox->vlbStruct) ) {
  521.                     nSelected = 0;
  522.                 }
  523.                 else {
  524.                     nSelected++;
  525.                 }
  526.  
  527.                 pVLBox->nCountInBox++;
  528.                 if ( pVLBox->lNumLogicalRecs != -1L )
  529.                    pVLBox->lToplIndex--;
  530.              }
  531.              else
  532.                 break;
  533.           }
  534.        }
  535.  
  536.        if ( nSelected >= 0 ) {
  537.           SendMessage(pVLBox->hwndList, LB_SETCURSEL, nSelected, 0L);
  538.           SetFocustoLB(pVLBox);
  539.        }
  540.  
  541.        UpdateVLBWindow(pVLBox, NULL);
  542.        vlbRedrawOn(pVLBox);
  543.        return VLB_OK;
  544.     }
  545.     else
  546.         return VLB_ERR;
  547. }
  548.  
  549.  
  550. void VLBFirstPage( PVLBOX pVLBox)
  551. {
  552.     pVLBox->vlbStruct.lpTextPointer = NULL;
  553.     pVLBox->vlbStruct.lData = pVLBox->vlbStruct.lIndex = 0L;
  554.     pVLBox->vlbStruct.nCtlID = pVLBox->nId;
  555.     SendMessage(pVLBox->hwndParent, VLB_FIRST, 0, (LPARAM)((LPVLBSTRUCT)&(pVLBox->vlbStruct)));
  556.     if ( pVLBox->vlbStruct.nStatus  == VLB_OK ) {
  557.        SetFocustoVLB(pVLBox);
  558.        vlbRedrawOff(pVLBox);
  559.        SendMessage(pVLBox->hwndList, LB_RESETCONTENT, 0, 0L);
  560.        SendMessage(pVLBox->hwndParent, VLBN_FREEALL, pVLBox->nId, 0L);
  561.  
  562.        if ( pVLBox->wFlags & HASSTRINGS) {
  563.            SendMessage(pVLBox->hwndList, LB_ADDSTRING, 0,  (LPARAM) pVLBox->vlbStruct.lpTextPointer);
  564.            SendMessage(pVLBox->hwndList, LB_SETITEMDATA, 0, pVLBox->vlbStruct.lData);
  565.        }
  566.        else
  567.            SendMessage(pVLBox->hwndList, LB_ADDSTRING, 0,  (LPARAM) pVLBox->vlbStruct.lData);
  568.  
  569.        if ( TestSelectedItem(pVLBox, pVLBox->vlbStruct) ) {
  570.            SendMessage(pVLBox->hwndList, LB_SETCURSEL, 0, 0L);
  571.            SetFocustoLB(pVLBox);
  572.        }
  573.  
  574.        if ( pVLBox->lNumLogicalRecs == -1L )
  575.           pVLBox->lToplIndex = pVLBox->vlbStruct.lData;
  576.        else if ( pVLBox->wFlags & USEDATAVALUES )
  577.           pVLBox->lToplIndex = 0L;
  578.        else
  579.           pVLBox->lToplIndex = pVLBox->vlbStruct.lIndex;
  580.  
  581.        pVLBox->vlbStruct.lIndex = 0L;
  582.        pVLBox->nCountInBox = 1;
  583.        while ( pVLBox->nCountInBox < pVLBox->nLines ) {
  584.           pVLBox->vlbStruct.nCtlID = pVLBox->nId;
  585.           SendMessage(pVLBox->hwndParent, VLB_NEXT, 0, (LPARAM)(LPVLBSTRUCT)&(pVLBox->vlbStruct));
  586.           if ( pVLBox->vlbStruct.nStatus  == VLB_OK ) {
  587.             if ( pVLBox->wFlags & HASSTRINGS) {
  588.                 SendMessage(pVLBox->hwndList, LB_ADDSTRING, 0, (LPARAM) pVLBox->vlbStruct.lpTextPointer);
  589.                 SendMessage(pVLBox->hwndList, LB_SETITEMDATA, pVLBox->nCountInBox, pVLBox->vlbStruct.lData);
  590.             }
  591.             else
  592.                 SendMessage(pVLBox->hwndList, LB_ADDSTRING, 0, (LPARAM) pVLBox->vlbStruct.lData);
  593.  
  594.             if ( TestSelectedItem(pVLBox, pVLBox->vlbStruct) ) {
  595.                SendMessage(pVLBox->hwndList, LB_SETCURSEL, pVLBox->nCountInBox, 0L);
  596.                SetFocustoLB(pVLBox);
  597.             }
  598.  
  599.             pVLBox->vlbStruct.lIndex = (LONG) pVLBox->nCountInBox;
  600.             pVLBox->nCountInBox++;
  601.           }
  602.           else
  603.             break;
  604.        }
  605.     }
  606.     UpdateVLBWindow(pVLBox, NULL);
  607.     vlbRedrawOn(pVLBox);
  608. }
  609.  
  610. void VLBLastPage(PVLBOX pVLBox)
  611. {
  612.     pVLBox->vlbStruct.lpTextPointer = NULL;
  613.     pVLBox->vlbStruct.lData = pVLBox->vlbStruct.lIndex = 0L;
  614.     pVLBox->vlbStruct.nCtlID = pVLBox->nId;
  615.     SendMessage(pVLBox->hwndParent, VLB_LAST, 0, (LPARAM)(LPVLBSTRUCT)&(pVLBox->vlbStruct));
  616.     if ( pVLBox->vlbStruct.nStatus  == VLB_OK ) {
  617.        SetFocustoVLB(pVLBox);
  618.        vlbRedrawOff(pVLBox);
  619.        SendMessage(pVLBox->hwndList, LB_RESETCONTENT, 0, 0L);
  620.        SendMessage(pVLBox->hwndParent, VLBN_FREEALL, pVLBox->nId, 0L);
  621.  
  622.        if ( pVLBox->wFlags & HASSTRINGS) {
  623.            SendMessage(pVLBox->hwndList, LB_ADDSTRING, 0, (LPARAM) pVLBox->vlbStruct.lpTextPointer);
  624.            SendMessage(pVLBox->hwndList, LB_SETITEMDATA, 0, pVLBox->vlbStruct.lData);
  625.        }
  626.        else
  627.            SendMessage(pVLBox->hwndList, LB_ADDSTRING, 0, (LPARAM) pVLBox->vlbStruct.lData);
  628.  
  629.        if ( TestSelectedItem(pVLBox, pVLBox->vlbStruct) ) {
  630.           SendMessage(pVLBox->hwndList, LB_SETCURSEL, 0, 0L);
  631.           SetFocustoLB(pVLBox);
  632.        }
  633.  
  634.        if ( pVLBox->lNumLogicalRecs == -1L )
  635.           pVLBox->lToplIndex = pVLBox->vlbStruct.lData;
  636.        else if ( pVLBox->wFlags & USEDATAVALUES )
  637.           pVLBox->lToplIndex = pVLBox->lNumLogicalRecs;
  638.        else
  639.           pVLBox->lToplIndex = pVLBox->vlbStruct.lIndex;
  640.  
  641.        pVLBox->nCountInBox = 1;
  642.        while ( pVLBox->nCountInBox < pVLBox->nLines ) {
  643.           pVLBox->vlbStruct.nCtlID = pVLBox->nId;
  644.           SendMessage(pVLBox->hwndParent, VLB_PREV, 0, (LPARAM)(LPVLBSTRUCT)&(pVLBox->vlbStruct));
  645.           if ( pVLBox->vlbStruct.nStatus  == VLB_OK ) {
  646.              if ( pVLBox->wFlags & HASSTRINGS) {
  647.                  SendMessage(pVLBox->hwndList, LB_INSERTSTRING, 0, (LPARAM) pVLBox->vlbStruct.lpTextPointer);
  648.                  SendMessage(pVLBox->hwndList, LB_SETITEMDATA, 0, pVLBox->vlbStruct.lData);
  649.              }
  650.              else
  651.                  SendMessage(pVLBox->hwndList, LB_INSERTSTRING, 0, (LPARAM) pVLBox->vlbStruct.lData);
  652.  
  653.              if ( TestSelectedItem(pVLBox, pVLBox->vlbStruct) ) {
  654.                  SendMessage(pVLBox->hwndList, LB_SETCURSEL, pVLBox->nCountInBox, 0L);
  655.                  SetFocustoLB(pVLBox);
  656.              }
  657.  
  658.              pVLBox->nCountInBox++;
  659.              if ( pVLBox->lNumLogicalRecs != -1L )
  660.                 pVLBox->lToplIndex--;
  661.           }
  662.           else
  663.              break;
  664.        }
  665.  
  666.        UpdateVLBWindow(pVLBox, NULL);
  667.        vlbRedrawOn(pVLBox);
  668.     }
  669. }
  670.  
  671.  
  672. static void SetFocustoLB(PVLBOX pVLBox)
  673. {
  674.    pVLBox->wFlags &= ~PARENTFOCUS;
  675.    if ( pVLBox->wFlags & HASFOCUS ) {
  676.       SetFocus(pVLBox->hwndList);
  677.    }
  678. }
  679.  
  680.  
  681. static void SetFocustoVLB(PVLBOX pVLBox)
  682. {
  683.    pVLBox->wFlags |= PARENTFOCUS;
  684.    if ( pVLBox->wFlags & HASFOCUS ) {
  685.       SetFocus(pVLBox->hwnd);
  686.    }
  687. }
  688.