home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Unleashed / Visual_Basic_4_Unleashed_SAMS_Publishing_1995.iso / repease / rvb.c < prev    next >
C/C++ Source or Header  |  1995-08-14  |  27KB  |  745 lines

  1. /*==============================================================================
  2.    RVB.V
  3.    Visual Basic VBX shell for the TER DLL
  4.  
  5.    Version 4.0
  6.    ===========
  7.    
  8.    Sub Systems, Inc.
  9.    Software License Agreement  (1994)              
  10.    ----------------------------------
  11.    This license agreement allows the purchaser the right to modify the 
  12.    source code to incorporate in an application larger than the editor itself.
  13.    The target application must not be a programmer's utility 'like' a text editor.
  14.    Sub Systems, Inc. reserves the right to prosecute anybody found to be 
  15.    making illegal copies of the executable software or compiling the source
  16.    code for the purpose of selling there after.
  17. ===============================================================================*/
  18.  
  19. #define  STRICT
  20.  
  21. #include "windows.h"
  22. #include "stdio.h"
  23. #include "stdlib.h"
  24. #include "ctype.h"
  25. #include "dos.h"
  26. #include "fcntl.h"
  27. #include "io.h"
  28. #include "sys\types.h"
  29. #include "sys\stat.h"
  30. #include "string.h"
  31. #include "vbapi.h"
  32.  
  33. #if defined(__TURBOC__)
  34.    #include "alloc.h"
  35.    #include "mem.h"
  36.    #define   _fmemmove memmove
  37. #else
  38.    #include "malloc.h"
  39.    #include "memory.h"
  40.    #define farmalloc _fmalloc
  41.    #define farrealloc _frealloc
  42.    #define farfree   _ffree
  43. #endif
  44.  
  45. #include "rep.h"
  46.  
  47. #define  PREFIX 
  48. #include "rvb.h"
  49.  
  50. /******************************************************************************
  51.    VBINITCC: Visual Basic control intialization function
  52. ******************************************************************************/
  53. BOOL WINAPI _export VBINITCC(USHORT usVersion, BOOL rRuntime)
  54. {
  55.     return VBRegisterModel(hRvbInst,&model);
  56. }
  57.  
  58. /******************************************************************************
  59.    RepCtlProc: Control Proceedure
  60. ******************************************************************************/
  61. LONG WINAPI _export RepCtlProc(HCTL hCtl, HWND hWnd, USHORT message, USHORT wParam, LONG lParam)
  62. {
  63.     LPCTL pCtl;
  64.  
  65.     pCtl=(LPCTL)VBDerefControl(hCtl);
  66.  
  67.     switch (message) {
  68.         case VBM_INITIALIZE:                   // initialize the properties
  69.            FarMemSet(pCtl,0,sizeof(struct StrCtl));
  70.            GetBitmapDim(pCtl);
  71.            return NULL;                        // processed
  72.  
  73.         case VBM_CREATED:
  74.            if (VBGetMode()!=MODE_DESIGN) return 0L;
  75.            break;
  76.         
  77.         case WM_SIZE:
  78.            // snap to the old size
  79.            SetWindowPos(hWnd,NULL,0,0,pCtl->width,pCtl->height, SWP_NOMOVE | SWP_NOZORDER);
  80.            break;
  81.  
  82.         case WM_PAINT:
  83.            if (VBGetMode()==MODE_DESIGN) PaintControl(pCtl, hWnd);
  84.  
  85.            break;
  86.  
  87.         case REP_CLOSE:                // report close message
  88.            VBFireEvent(hCtl,IEVENT_UNLOAD,NULL);
  89.            break;
  90.  
  91.         default:
  92.            break;
  93.     }
  94.  
  95.     return VBDefControlProc(hCtl, hWnd, message, wParam, lParam);
  96. }
  97.  
  98. /****************************************************************************
  99.    RvbForm:
  100.    This routine fills the StrForm structure with the pointers for the
  101.    field selection and field field verication functions. It then calls
  102.    the 'form' function in the REP.DLL.
  103.  
  104.    The function returns a 0 if successful, otherwise it returns an error code. 
  105.    see ERR_ in rew.h file.
  106. *****************************************************************************/
  107. int WINAPI _export RvbForm(struct StrForm far *FormParam)
  108. {
  109.  
  110.    // fill in the call back function addresses
  111.    FormParam->UserSelection=(USER_SELECTION)MakeProcInstance((FARPROC)RvbFieldSelection,hRvbInst); // field selection routine 
  112.    FormParam->VerifyField=(VERIFY_FIELD)MakeProcInstance((FARPROC)RvbVerifyField,hRvbInst);          // field verification routine 
  113.    if (!FormParam->UserSelection || !FormParam->VerifyField) return ERR_OTHER;
  114.  
  115.    return form(FormParam);   // call the form editor
  116. }
  117.  
  118. /****************************************************************************
  119.    RvbInit:
  120.    Initialize the report executor
  121. *****************************************************************************/
  122. int WINAPI _export RvbInit(HWND hWnd, struct StrRep far *rep)
  123. {
  124.     int result;
  125.     HCTL hCtl;
  126.     LPCTL pCtl;
  127.  
  128.     if (hWnd!=rep->hParentWnd) {
  129.       MessageBox(NULL,"Invalid Control Handle!",NULL,MB_OK);
  130.       return ERR_OTHER;
  131.     }
  132.  
  133.     rep->DrawPicture=(DRAW_PICTURE)MakeProcInstance((FARPROC)RvbDrawPicture,hRvbInst); // picture drawing routine 
  134.  
  135.     result = RepInit(rep);
  136.  
  137.     // save the field pointers
  138.     if (result==0) {           // successful return
  139.        // Get the control handle and data area
  140.        if (NULL==(hCtl=VBGetHwndControl(hWnd))) return ERR_OTHER;
  141.        pCtl=(LPCTL)VBDerefControl(hCtl);
  142.  
  143.        pCtl->DataField=rep->field;
  144.        pCtl->SortField=rep->SortField;
  145.        pCtl->TotalFields=rep->TotalFields;
  146.        pCtl->TotalSortFields=rep->TotalSortFields;
  147.     }
  148.  
  149.     return result;
  150. }
  151.  
  152. /****************************************************************************
  153.    RvbRec:
  154.    Pass the record to the report executor
  155. *****************************************************************************/
  156. int WINAPI _export RvbRec(HWND hWnd)
  157. {
  158.    return RepRec();
  159. }
  160.  
  161. /****************************************************************************
  162.    RvbExit:
  163.    Close the report executor
  164. *****************************************************************************/
  165. int WINAPI _export RvbExit(HWND hWnd)
  166. {
  167.    return RepExit();
  168. }
  169.  
  170. /****************************************************************************
  171.    RvbSetTextField:
  172.    Set the data for the specified text field
  173. *****************************************************************************/
  174. int WINAPI _export RvbSetTextField(HWND hWnd, int FieldNo, LPSTR text,int TextLen)
  175. {
  176.     int i;
  177.     HCTL hCtl;
  178.     LPCTL pCtl;
  179.     struct StrField huge *field;
  180.  
  181.     // Get the control handle and data area
  182.     if (NULL==(hCtl=VBGetHwndControl(hWnd))) return FALSE;
  183.     pCtl=(LPCTL)VBDerefControl(hCtl);
  184.  
  185.     field=pCtl->DataField;
  186.     if (!field || FieldNo<0 || FieldNo>=pCtl->TotalFields) return FALSE;
  187.  
  188.     if (field[FieldNo].source!=SRC_APPL) return FALSE;  // not an application data field
  189.     if (field[FieldNo].type!=TYPE_TEXT)  return FALSE;  // not a text field
  190.  
  191.     // copy the field
  192.     if (TextLen>field[FieldNo].width) TextLen=field[FieldNo].width;
  193.     if (TextLen<0) TextLen=0;
  194.  
  195.     for (i=0;i<TextLen;i++) field[FieldNo].CharData[i]=text[i];
  196.     field[FieldNo].CharData[TextLen]=0;                 // NULL terminate the string
  197.  
  198.     return TRUE;
  199. }
  200.  
  201. /****************************************************************************
  202.    RvbSetNumField:
  203.    Set the data for the specified numeric, logical or date type field
  204. *****************************************************************************/
  205. int WINAPI _export RvbSetNumField(HWND hWnd, int FieldNo, long NumData)
  206. {
  207.     HCTL hCtl;
  208.     LPCTL pCtl;
  209.     struct StrField huge *field;
  210.  
  211.     // Get the control handle and data area
  212.     if (NULL==(hCtl=VBGetHwndControl(hWnd))) return FALSE;
  213.     pCtl=(LPCTL)VBDerefControl(hCtl);
  214.  
  215.     field=pCtl->DataField;
  216.     if (!field || FieldNo<0 || FieldNo>=pCtl->TotalFields) return FALSE;
  217.  
  218.     if (field[FieldNo].source!=SRC_APPL) return FALSE;  // not an application data field
  219.     if (field[FieldNo].type!=TYPE_NUM 
  220.      && field[FieldNo].type!=TYPE_LOGICAL 
  221.      && field[FieldNo].type!=TYPE_PICT 
  222.      && field[FieldNo].type!=TYPE_DATE)  return FALSE;  // not a numeric field
  223.  
  224.     // copy the field
  225.     field[FieldNo].NumData=NumData;
  226.  
  227.     return TRUE;
  228. }
  229.  
  230. /****************************************************************************
  231.    RvbSetDoubleField:
  232.    Set the data for the specified double field
  233. *****************************************************************************/
  234. int     WINAPI _export RvbSetDoubleField(HWND hWnd, int FieldNo, double DblData)
  235. {
  236.     HCTL hCtl;
  237.     LPCTL pCtl;
  238.     struct StrField huge *field;
  239.  
  240.     // Get the control handle and data area
  241.     if (NULL==(hCtl=VBGetHwndControl(hWnd))) return FALSE;
  242.     pCtl=(LPCTL)VBDerefControl(hCtl);
  243.  
  244.     field=pCtl->DataField;
  245.     if (!field || FieldNo<0 || FieldNo>=pCtl->TotalFields) return FALSE;
  246.  
  247.     if (field[FieldNo].source!=SRC_APPL) return FALSE;  // not an application data field
  248.     if (field[FieldNo].type!=TYPE_DBL)  return FALSE;   // not a double numeric field
  249.  
  250.     // copy the field
  251.     field[FieldNo].DblData=DblData;
  252.  
  253.     return TRUE;
  254. }
  255.  
  256. /****************************************************************************
  257.    RvbGetDataField:
  258.    Returns the specified data field
  259. *****************************************************************************/
  260. int WINAPI _export RvbGetDataField(HWND hWnd, int FieldNo, struct StrField far *field)
  261. {
  262.     HCTL hCtl;
  263.     LPCTL pCtl;
  264.  
  265.     // Get the control handle and data area
  266.     if (NULL==(hCtl=VBGetHwndControl(hWnd))) return FALSE;
  267.     pCtl=(LPCTL)VBDerefControl(hCtl);
  268.  
  269.     if (!(pCtl->DataField) || FieldNo<0 || FieldNo>=pCtl->TotalFields) return FALSE;
  270.     
  271.     // get the current field structure from the control area
  272.     FarMove(&(pCtl->DataField[FieldNo]),field,sizeof(struct StrField));
  273.  
  274.     return TRUE;
  275. }
  276.  
  277. /****************************************************************************
  278.    RvbGetSortField:
  279.    Returns the specified sort field
  280. *****************************************************************************/
  281. int WINAPI _export RvbGetSortField(HWND hWnd, int FieldNo, struct StrField far *field)
  282. {
  283.     HCTL hCtl;
  284.     LPCTL pCtl;
  285.  
  286.     // Get the control handle and data area
  287.     if (NULL==(hCtl=VBGetHwndControl(hWnd))) return FALSE;
  288.     pCtl=(LPCTL)VBDerefControl(hCtl);
  289.  
  290.     if (!(pCtl->SortField) || FieldNo<0 || FieldNo>=pCtl->TotalSortFields) return FALSE;
  291.     
  292.     // get the current field structure from the control area
  293.     FarMove(&(pCtl->SortField[FieldNo]),field,sizeof(struct StrField));
  294.  
  295.     return TRUE;
  296. }
  297.  
  298. /****************************************************************************
  299.    RvbGetFormField:
  300.    Get the current field. This function return TRUE when successful.
  301. *****************************************************************************/
  302. int WINAPI _export RvbGetFormField(HWND hWnd, struct StrField far *field, int far *SortLevel)
  303. {
  304.     HCTL hCtl;
  305.     LPCTL pCtl;
  306.  
  307.     // Get the control handle and data area
  308.     if (NULL==(hCtl=VBGetHwndControl(hWnd))) return FALSE;
  309.     pCtl=(LPCTL)VBDerefControl(hCtl);
  310.     
  311.     // get the current field structure from the control area
  312.     FarMove(&(pCtl->CurField),field,sizeof(struct StrField));
  313.     (*SortLevel)=pCtl->SortLevel;
  314.  
  315.     return TRUE;
  316. }
  317.  
  318. /****************************************************************************
  319.    RvbSetFormField:
  320.    Set the current field to the specified field structure. 
  321.    This function return TRUE when successful.
  322. *****************************************************************************/
  323. int WINAPI _export RvbSetFormField(HWND hWnd, struct StrField far *field, int valid)
  324. {
  325.     HCTL hCtl;
  326.     LPCTL pCtl;
  327.  
  328.     // Get the control handle and data area
  329.     if (NULL==(hCtl=VBGetHwndControl(hWnd))) return FALSE;
  330.     pCtl=(LPCTL)VBDerefControl(hCtl);
  331.     
  332.     // set the current field structure from the use area
  333.     FarMove(field,&(pCtl->CurField),sizeof(struct StrField));
  334.     pCtl->valid=valid;                     // TRUE for a valid field
  335.  
  336.     return TRUE;
  337. }
  338.  
  339. /****************************************************************************
  340.    RvbGetPictureInfo:
  341.    Get the information to draw a picture
  342. *****************************************************************************/
  343. int WINAPI _export RvbGetPictureInfo(HWND hWnd, struct StrPict far *pict)
  344. {
  345.     HCTL hCtl;
  346.     LPCTL pCtl;
  347.  
  348.     // Get the control handle and data area
  349.     if (NULL==(hCtl=VBGetHwndControl(hWnd))) return FALSE;
  350.     pCtl=(LPCTL)VBDerefControl(hCtl);
  351.  
  352.     // transfer the picture information structure
  353.     (*pict)=pCtl->pict;
  354.  
  355.     return TRUE;         
  356. }
  357.  
  358. /****************************************************************************
  359.    RvbDrawBitmap:
  360.    Draw the specified part of a specified bitmap to the current report output
  361.    device context.  This function is called by a visual basic application
  362.    within the DrawPicture event handler.
  363.  
  364.    The picture X location and width parameters are specified in percentage of
  365.    width.  The picture Y location and height parameters are specified in
  366.    percentage of height.   
  367. *****************************************************************************/
  368. int WINAPI _export RvbDrawBitmap(HWND hWnd, HWND hBMWnd, HBITMAP hBM,int x, int y, int width, int height)
  369. {
  370.     HCTL hCtl;
  371.     LPCTL pCtl;
  372.     BITMAP bm;
  373.     HANDLE   hInfo,hImage;        // handle to the device independent bitmap
  374.     LPSTR    pImage;              // pointer to the image data
  375.     LPBITMAPINFOHEADER pInfo;     // pointer to the image header data
  376.     DWORD  InfoSize,ImageSize;
  377.     int    SourceX,SourceY,SourceWidth,SourceHeight;
  378.  
  379.     // Get the control handle and data area
  380.     if (NULL==(hCtl=VBGetHwndControl(hWnd))) return FALSE;
  381.     pCtl=(LPCTL)VBDerefControl(hCtl);
  382.     if (!(pCtl->pict.hDC)) return FALSE;  // device context not available
  383.  
  384.     // extract the device independent bits from the bitmap
  385.     GetObject(hBM,sizeof(BITMAP),(LPSTR)&bm);              // get the dimension of bit map 
  386.    
  387.     //********** create the device independent bitmap ***********************
  388.     InfoSize=sizeof(BITMAPINFOHEADER)+256*sizeof(RGBQUAD);  // create a 256 color bitmap structure 
  389.  
  390.     if (NULL==(hInfo=GlobalAlloc(GMEM_MOVEABLE,InfoSize))
  391.       ||NULL==(pInfo=(LPBITMAPINFOHEADER)GlobalLock(hInfo)) ) {
  392.         MessageBox(hWnd,"Ran out of memory for Bitmap Info!",NULL,MB_OK);
  393.         return FALSE;
  394.     }
  395.  
  396.     //***** fill in the info structure ******
  397.     pInfo->biSize=sizeof(BITMAPINFOHEADER);
  398.     pInfo->biWidth=bm.bmWidth;
  399.     pInfo->biHeight=bm.bmHeight;
  400.     pInfo->biPlanes=1;                       // DIB have plane = 1 
  401.     pInfo->biBitCount=8;                     // 8 bits per pixel or color 
  402.     pInfo->biCompression=BI_RGB;             // no compression
  403.     pInfo->biSizeImage=0;                    // initialize to zero 
  404.     pInfo->biXPelsPerMeter=0;
  405.     pInfo->biYPelsPerMeter=0;
  406.     pInfo->biClrUsed=0;                      // depends on biBitCount 
  407.     pInfo->biClrImportant=0;                 // all colors important 
  408.  
  409.     if (!GetDIBits(GetDC(hBMWnd),hBM,0,bm.bmHeight,NULL,(LPBITMAPINFO)pInfo,DIB_RGB_COLORS)) {
  410.         MessageBox(hWnd,"Error Creating Device Independent Bitmap Structure!",NULL,MB_OK);
  411.         return FALSE;
  412.     }
  413.  
  414.     ImageSize=pInfo->biSizeImage;
  415.  
  416.     if (NULL==(hImage=GlobalAlloc(GMEM_MOVEABLE,ImageSize))
  417.       ||NULL==(pImage=GlobalLock(hImage)) ) {
  418.         MessageBox(hWnd,"Ran out of memory for Bitmap Image!",NULL,MB_OK);
  419.         return FALSE;
  420.     }
  421.  
  422.     if (!GetDIBits(GetDC(hBMWnd),hBM,0,bm.bmHeight,pImage,(LPBITMAPINFO)pInfo,DIB_RGB_COLORS)) {
  423.         MessageBox(hWnd,"Error Creating Device Independent Bitmap Image!",NULL,MB_OK);
  424.         return FALSE;
  425.     }
  426.  
  427.     // Convert percentage to pixel values
  428.     SourceX=(int)((((long)bm.bmWidth*x))/(100L));
  429.     SourceY=(int)((((long)bm.bmHeight*y))/(100L));
  430.     SourceWidth=(int)((((long)bm.bmWidth*width))/(100L));
  431.     SourceHeight=(int)((((long)bm.bmHeight*height))/(100L));
  432.  
  433.     // copy the bitmap
  434.     StretchDIBits(pCtl->pict.hDC,pCtl->pict.x,pCtl->pict.y,pCtl->pict.width,pCtl->pict.height,
  435.                    SourceX,SourceY,SourceWidth,SourceHeight,pImage,(LPBITMAPINFO)pInfo,DIB_RGB_COLORS,SRCCOPY);
  436.  
  437.     // release the resources
  438.     GlobalUnlock(hImage);
  439.     GlobalUnlock(hInfo);
  440.     GlobalFree(hImage);
  441.     GlobalFree(hInfo);
  442.  
  443.     return TRUE;
  444. }
  445.  
  446. /******************************************************************************
  447.     RvbFieldSelection:
  448.     This routine is called by the REP_FLD module to allow user to select 
  449.     a data field.
  450.     This routine will file FieldSelection event to the parent control.
  451.     The parent control gets the input field structure, and fills in the
  452.     required field.
  453. ******************************************************************************/
  454. int WINAPI _export RvbFieldSelection(HWND hWnd,struct StrField huge *field,int SortLevel)
  455. {
  456.     HCTL hCtl;
  457.     HWND hCtlWnd;
  458.     LPCTL pCtl;
  459.  
  460.     // Get the control handle and data area
  461.     if (NULL==(hCtlWnd=RepGetParent())) return FALSE;
  462.     if (NULL==(hCtl=VBGetHwndControl(hCtlWnd))) return FALSE;
  463.     pCtl=(LPCTL)VBDerefControl(hCtl);
  464.     
  465.     // Save the current field structure in the control area
  466.     field->name[0]=0;                       // reset the field name
  467.     FarMove(field,&(pCtl->CurField),sizeof(struct StrField));
  468.     pCtl->SortLevel=SortLevel;
  469.     pCtl->valid=FALSE;
  470.  
  471.     // fire the field selection event
  472.     VBFireEvent(hCtl,IEVENT_SELECT_FIELD,NULL);
  473.  
  474.     // return the modified field structure
  475.     pCtl=(LPCTL)VBDerefControl(hCtl);        // refresh the pointer
  476.     if (pCtl->valid) FarMove(&(pCtl->CurField),field,sizeof(struct StrField));
  477.    
  478.     return pCtl->valid;
  479. }
  480.  
  481. /******************************************************************************
  482.     RvbVerifyField:
  483.     This routine will fire FieldVerification event to the parent control.
  484.     The parent control gets the input field structure, and verifies the field
  485.     name.
  486.  
  487.     The function returns TRUE if the field is valid, otherwise it returns
  488.     a FALSE value.
  489. ******************************************************************************/
  490. int WINAPI _export RvbVerifyField(struct StrField huge *field,int SortLevel)
  491. {
  492.     HCTL hCtl;
  493.     HWND hCtlWnd;
  494.     LPCTL pCtl;
  495.  
  496.     // Get the control handle and data area
  497.     if (NULL==(hCtlWnd=RepGetParent())) return FALSE;
  498.     if (NULL==(hCtl=VBGetHwndControl(hCtlWnd))) return FALSE;
  499.     pCtl=(LPCTL)VBDerefControl(hCtl);
  500.     
  501.     // Save the current field structure in the control area
  502.     FarMove(field,&(pCtl->CurField),sizeof(struct StrField));
  503.     pCtl->SortLevel=SortLevel;
  504.     pCtl->valid=FALSE;
  505.  
  506.     // fire the field selection event
  507.     VBFireEvent(hCtl,IEVENT_VERIFY_FIELD,NULL);
  508.  
  509.     // return the validation flag
  510.     pCtl=(LPCTL)VBDerefControl(hCtl);        // refresh the pointer
  511.     if (pCtl->valid) FarMove(&(pCtl->CurField),field,sizeof(struct StrField));
  512.  
  513.     return pCtl->valid;
  514. }
  515.  
  516. /******************************************************************************
  517.     RvbDrawPicture:
  518.     This routine is called by the report executor to draw a specified
  519.     picture type field.  The first argument specifies the device context
  520.     of the reporting device.  If the report output is directed to a printer,
  521.     this device context belongs to a printer, otherwise it specifies a 
  522.     device context for a metafile.  You application should draw the picture
  523.     on this device context within the specified rectangle (last argument).
  524.  
  525.     The device context is in ANISOTROPIC mode.  The resolution in the X and
  526.     Y direction is given by the UNITS_PER_INCH constant.
  527.  
  528.     The second argument is the picture id.  The third and fourth arguments
  529.     are the file and field id for the picture field.
  530.  
  531.     The function returns TRUE if successful.
  532.  
  533.     In this demo program, this routine draws a logo for a given picture id.
  534.     This program uses only one bitmap, and draws different part of the same
  535.     bitmap for different picture id.
  536.  
  537. ******************************************************************************/
  538. int WINAPI _export RvbDrawPicture(HDC hDC,int PictId, int FileId, int FieldId, RECT far * rect)
  539. {
  540.     HCTL hCtl;
  541.     HWND hCtlWnd;
  542.     LPCTL pCtl;
  543.  
  544.  
  545.     // Get the control handle and data area
  546.     if (NULL==(hCtlWnd=RepGetParent())) return FALSE;
  547.     if (NULL==(hCtl=VBGetHwndControl(hCtlWnd))) return FALSE;
  548.     pCtl=(LPCTL)VBDerefControl(hCtl);
  549.  
  550.     // save the arguments
  551.     pCtl->pict.hDC=hDC;
  552.     pCtl->pict.PictId=PictId;
  553.     pCtl->pict.FileId=FileId;
  554.     pCtl->pict.FieldId=FieldId;
  555.     pCtl->pict.x = rect->left;
  556.     pCtl->pict.y = rect->top;
  557.     pCtl->pict.width = rect->right-rect->left;
  558.     pCtl->pict.height = rect->bottom-rect->top;
  559.  
  560.     // fire the picture draw event
  561.     VBFireEvent(hCtl,IEVENT_DRAW_PICTURE,NULL);
  562.  
  563.     // reset the hDC parameter
  564.     pCtl=(LPCTL)VBDerefControl(hCtl);
  565.     pCtl->pict.hDC=0;
  566.  
  567.     return TRUE;
  568. }
  569.  
  570.  
  571.  
  572. /******************************************************************************
  573.    LibMain: Function to initialize DLL
  574. ******************************************************************************/
  575. int CALLBACK LibMain(HINSTANCE hInstance, WORD wDataSeg, WORD cbHeapSize,  LPSTR lpszCmdLine)
  576. {
  577.     // Initialize the common global variables
  578.     hRvbInst=hInstance;
  579.  
  580.     // fill the model structure
  581.     model.usVersion=VB_VERSION;      // visual basic version supported
  582.     model.fl=MODEL_fArrows|MODEL_fFocusOk|MODEL_fInitMsg;
  583.     model.pctlproc=(PCTLPROC) RepCtlProc;
  584.     model.fsClassStyle=0;            // allocate a DC for this class 
  585.     model.flWndStyle=0;              // window styles
  586.     model.cbCtlExtra=sizeof(struct StrCtl);  // size to hold a pointer
  587.     model.idBmpPalette=IDR_TOOLBAR_UP;// first resource id for the icon
  588.     model.npszDefCtlName="Rep";      // control name
  589.     model.npszClassName="ReportEasePlus";// class name
  590.     model.npszParentClassName=NULL;  // parent class
  591.     model.npproplist=RvbProp;        // near pointer to the near property pointers
  592.     model.npeventlist=RvbEvent;      // near pointer to the near event pointers
  593.     model.nDefProp=0;                // index of the default property 
  594.     model.nDefEvent=0;               // index of the default event
  595.     model.nValueProp=0xFF;           // default property for asignement
  596.     model.usCtlVersion=20;           // V2.0 of REP 
  597.  
  598.     return TRUE;
  599. }
  600.  
  601. /*****************************************************************************
  602.     PaintControl:
  603.     Paint the control from the bitmap
  604. ******************************************************************************/
  605. PaintControl(LPCTL pCtl, HWND hWnd)
  606. {
  607.     HBITMAP hBM,hOldBM;
  608.     HDC hMemDC;
  609.     PAINTSTRUCT ps;
  610.  
  611.     // get the bitmap
  612.     if (NULL==(hBM=LoadBitmap(hRvbInst,MAKEINTRESOURCE(IDR_TOOLBAR_UP)))) return FALSE;
  613.     
  614.     BeginPaint(hWnd,&ps);
  615.     if (NULL==(hMemDC=CreateCompatibleDC(ps.hdc))) return NULL;
  616.     hOldBM=SelectObject(hMemDC,hBM);
  617.     
  618.     // display the bitmap
  619.     BitBlt(ps.hdc,0,0,pCtl->width,pCtl->height,hMemDC,0,0,SRCCOPY);
  620.  
  621.     // delete the resources
  622.     SelectObject(hMemDC,hOldBM);  // release the bitmap
  623.     DeleteObject(hBM);
  624.  
  625.     DeleteDC(hMemDC);
  626.  
  627.     EndPaint(hWnd,&ps);
  628.  
  629.     return TRUE;
  630. }
  631.  
  632. /*****************************************************************************
  633.     GetBitmapDim:
  634.     Get the dimension of the icon bitmap
  635. ******************************************************************************/
  636. GetBitmapDim(LPCTL pCtl)
  637. {
  638.     HBITMAP hBM;
  639.     BITMAP bm;
  640.  
  641.     // set a small dimension for the bitmap
  642.     pCtl->width=pCtl->height=100;
  643.  
  644.     if (NULL==(hBM=LoadBitmap(hRvbInst,MAKEINTRESOURCE(IDR_TOOLBAR_UP)))) return FALSE;
  645.     
  646.     // get the bitmap dimensions
  647.     GetObject(hBM,sizeof(BITMAP),(LPSTR)&bm);     // get the dimension of bit map 
  648.     pCtl->width=bm.bmWidth;
  649.     pCtl->height=bm.bmHeight;
  650.  
  651.     DeleteObject(hBM);
  652.  
  653.     return TRUE;
  654. }
  655.  
  656. /*****************************************************************************
  657.     WEP:
  658.     Library exit routine.
  659. ******************************************************************************/
  660. CALLBACK _export WEP(int nParameter)
  661. {
  662.     if (nParameter==WEP_SYSTEM_EXIT || nParameter==WEP_FREE_DLL) return 1;
  663.     
  664.     return TRUE;
  665. }
  666.  
  667. /******************************************************************************
  668.     OurPrintf:
  669.     This routine formats and display a given set of arguments.  The format
  670.     is given by the first argument.  The argument 2 to n contain the
  671.     arguments for the specified format.  The function uses MessageBox to
  672.     display the formatted string.
  673. ******************************************************************************/
  674. OurPrintf(LPSTR fmt,...)
  675. {
  676.     LPSTR ArgStart;
  677.     char string[256];
  678.  
  679.     ArgStart=(LPSTR) &fmt;  // pointer to first argument 
  680.     ArgStart=&ArgStart[4];  // go past the first argument 
  681.     wvsprintf(string,fmt,ArgStart);
  682.     if (FindWindow("DBWin",NULL)) { // debug window open
  683.         lstrcat(string,"\n");
  684.         OutputDebugString(string);  // send to the debug terminal
  685.     }
  686.     else MessageBox(NULL,string,NULL,MB_OK);
  687.     return TRUE;
  688. }
  689.  
  690. /******************************************************************************
  691.     Copy a specified number of bytes from the source to the destination location.
  692.     Both the source and destination locations are specified by using far pointers.
  693.     
  694.     When source and destination memory overlaps,  use FarMoveOl function for
  695.     a proper trasfer.
  696.  
  697.     Small/Medium Model Note:  This function will not work if compiled 
  698.     as an EXECUTABLE under small/medium model using the Borland compiler.
  699.     This is because Borland 'C' does not have a fmemmove library function.
  700. *******************************************************************************/
  701. void FarMove(void far * src,void far * dest, WORD count)
  702. {
  703.     WORD i,SrcOff,DestOff,SrcSeg,DestSeg;
  704.     char huge *SrcPtr,huge *DestPtr;
  705.  
  706.     if (count==0) return;             // nothing to move
  707.  
  708.     SrcSeg=HIWORD((DWORD)(src));     // source segment
  709.     DestSeg=HIWORD((DWORD)(dest));   // destination segment
  710.     SrcOff=LOWORD((DWORD)(src));     // source offset
  711.     DestOff=LOWORD((DWORD)(dest));   // destination offset
  712.  
  713.     // use _fmemmove function if source and destination do not wrap
  714.     if ((SrcOff+count)>SrcOff && (DestOff+count)>DestOff) _fmemmove(dest,src,count);
  715.     else {                            // move one by one if source of destination wrap
  716.         SrcPtr=(char huge *)src;
  717.         DestPtr=(char huge *)dest;
  718.  
  719.         if ( (GetSelectorBase(SrcSeg)+SrcOff)
  720.            > (GetSelectorBase(DestSeg)+DestOff) ){  // source at higher address
  721.            for (i=0;i<count;i++) DestPtr[i]=SrcPtr[i];
  722.         }
  723.         else {  // src at lower address, move in reverse order
  724.            for (i=count-1;i!=0xFFFF;i--) DestPtr[i]=SrcPtr[i];
  725.         }
  726.     }
  727.  
  728.     return;
  729. }
  730.  
  731. /******************************************************************************
  732.     FarMemSet:
  733.     This function every byte of the given far buffer to the specified character.
  734. ******************************************************************************/
  735. void FarMemSet(void far *ptr,char chr, WORD count)
  736. {
  737.     WORD i;
  738.     LPSTR lptr;
  739.  
  740.     lptr=(LPSTR)ptr;
  741.  
  742.     for (i=0;i<count;i++) lptr[i]=chr;
  743. }
  744.  
  745.