home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic 4 Unleashed
/
Visual_Basic_4_Unleashed_SAMS_Publishing_1995.iso
/
repease
/
rep_rep1.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-02-23
|
35KB
|
948 lines
/*==============================================================================
REP_REP1.C
Report Ease: Report Executer report painting and printing routines.
ReportEase Plus
Sub Systems, Inc.
ReportEase Plus, Copyright (c) 1993, Sub Systems, Inc. All Rights Reserved.
159 Main Street, #8C, Stoneham, MA 02180
(617) 438-8901.
Software License Agreement (1993)
----------------------------------
This license agreement allows the purchaser the right to modify the
source code to incorporate in their application.
The target application must not be distributed as a standalone report writer
or a mail merge product.
Sub Systems, Inc. reserves the right to prosecute anybody found to be
making illegal copies of the executable software or compiling the source
code for the purpose of selling there after.
===============================================================================*/
#include "windows.h"
#if defined (_WIN32)
#if !defined(WIN32)
#define WIN32
#endif
#endif
#if !defined(WIN32)
#include "print.h"
#endif
#include "stdio.h"
#include "stdlib.h"
#include "ctype.h"
#include "fcntl.h"
#include "io.h"
#include "sys\types.h"
#include "sys\stat.h"
#include "string.h"
#include "dos.h"
#include "setjmp.h"
#include "rep.h"
#define PREFIX extern
#include "rep1.h"
#include "rep_dlg.h"
/****************************************************************************
RepWndProc:
This routine process the messages coming to the report output
window.
****************************************************************************/
long CALLBACK _export RepWndProc(HWND hWnd,unsigned message,WPARAM wParam,LPARAM lParam)
{
int LastCompletePage,NewPage;
long CurPos,LastPos;
int ScrollPos;
//*********** translate accelerator ***********
if (FrTranslateAccelerator(hWnd,message,wParam,lParam)) return TRUE; // accelerator translated
if (ReportStage==IN_EXIT) LastCompletePage=PageCount;
else LastCompletePage=PageCount-1;
switch (message) {
case WM_VSCROLL: // vertical scroll bar commands
switch (SCROLL_MSG(wParam,lParam)) {
case SB_LINEDOWN: // scroll window one line down
RepDown(FrWinHeight/20);break;
case SB_LINEUP: // scroll window one line up
RepUp(FrWinHeight/20);break;
case SB_PAGEDOWN: // next page
RepDown(FrWinHeight);break;
case SB_PAGEUP: // previous page
RepUp(FrWinHeight);break;
case SB_THUMBTRACK: // absolute line position as the thump moves
NewPage=(int)(((long)LastCompletePage*THUMB_POS(wParam,lParam))/(VER_SCROLL_MAX-VER_SCROLL_MIN));
if (NewPage>=LastCompletePage) NewPage=LastCompletePage-1;
if (NewPage!=ScrPage) {
ScrPage=NewPage;
hMetaFile=ReadMetaFilePage(ScrPage,ScrMetaFile,hMetaFile); // read next print page
FrWinOrgY=0; // show the top of the page
PaintRepScr(); // paint the new screen page
}
break;
default:
break;
}
break;
case WM_HSCROLL: // horizontal scroll bar commands
switch (SCROLL_MSG(wParam,lParam)) {
case SB_LINEDOWN: // scroll window one column toward right
RepRight(FrWinWidth/10);break;
case SB_LINEUP: // scroll window one column toward left
RepLeft(FrWinWidth/10);break;
case SB_PAGEDOWN: // next horizontal page
RepRight(FrWinWidth);break;
case SB_PAGEUP: // previous horizontal page
RepLeft(FrWinWidth);break;
case SB_THUMBTRACK: // absolute line position as the thump moves
FrWinOrgX=(int)(((long)PrintWidth*THUMB_POS(wParam,lParam))/(VER_SCROLL_MAX-VER_SCROLL_MIN));
PaintRepScr(); // paint the new screen page
break;
default:
break;
}
break;
case WM_COMMAND:
switch (COMMAND_ID(wParam,lParam)) {
case ID_JUMP: // jump to a specify page
PageJump();
break;
case ID_PRINT: // print range of processed pages
SelectivePrint(); // print selected pages
break;
case ID_EXIT:
if (ReportStage==IN_EXIT) return RepCleanup();
ReportStatus=REP_ABORT;
break;
//*********************************************************
// Navigation commands
//*********************************************************
case ID_PGUP: // process page-up key
RepUp(FrWinHeight);break;
case ID_PGDN: // process page-down key
RepDown(FrWinHeight);break;
case ID_UP: // process the up arrow key
RepUp(FrWinHeight/20);break;
case ID_DOWN: // process the down arrow key
RepDown(FrWinHeight/20);break;
case ID_LEFT: // process the left arrow
RepLeft(FrWinWidth/10);break;
case ID_RIGHT: // process the right arrow
RepRight(FrWinWidth/10);break;
default:
return (DefWindowProc(hWnd, message, wParam, lParam));
}
break;
case WM_CLOSE:
if (ReportStage==IN_EXIT) return RepCleanup();
else if (ReportStage!=IN_TOTALS) ReportStatus=REP_ABORT;
break;
case WM_PAINT:
RepaintRepScr();
break;
default:
return (DefWindowProc(hWnd, message, wParam, lParam));
}
RepInitMenu(hFrMenu); // update the menu display
//******************* set vertical and horizontal scroll bars************
if (LastCompletePage>0) {
//******************* set vertical scroll bar ***********************
CurPos=(long)ScrPage*(long)PageHeight+FrWinOrgY;
LastPos=(long)LastCompletePage*(long)PageHeight;
ScrollPos=VER_SCROLL_MIN+(int)(CurPos*(VER_SCROLL_MAX-VER_SCROLL_MIN)/LastPos);
if (ScrollPos!=VerScrollPos) { /* redraw */
VerScrollPos=ScrollPos;
SetScrollPos(hFrWnd,SB_VERT,VerScrollPos,TRUE);
}
//******************* set horizontal scroll bar ***********************
if (PrintWidth>FrWinWidth) {
ScrollPos=HOR_SCROLL_MIN+(int)((long)FrWinOrgX*(HOR_SCROLL_MAX-HOR_SCROLL_MIN)/PrintWidth);
if (ScrollPos>HOR_SCROLL_MAX) ScrollPos=HOR_SCROLL_MAX;
if (ScrollPos!=HorScrollPos) { /* redraw */
HorScrollPos=ScrollPos;
SetScrollPos(hFrWnd,SB_HORZ,HorScrollPos,TRUE);
}
}
}
return (LRESULT)(NULL);
}
/******************************************************************************
RepInitMenu:
Initialzes and redraws the report menu bar
******************************************************************************/
RepInitMenu(HMENU hMenu)
{
int LastCompletePage;
if (ReportStage==IN_EXIT) LastCompletePage=PageCount;
else LastCompletePage=PageCount-1;
EnableMenuItem(hMenu,ID_JUMP ,LastCompletePage>1 ? MF_ENABLED : MF_GRAYED);
EnableMenuItem(hMenu,ID_PRINT ,LastCompletePage>0 && !printing ? MF_ENABLED : MF_GRAYED);
DrawMenuBar(hFrWnd); // redraw the menu bar
return TRUE;
}
/******************************************************************************
RepaintRepScr:
This routine is called when a paint message is received by the RepWndProc
function.
This routine repaint the entire client area.
*******************************************************************************/
RepaintRepScr()
{
PAINTSTRUCT PaintData;
BeginPaint(hFrWnd,&PaintData);
EndPaint(hFrWnd,&PaintData);
if (WindowBeingCreated) return TRUE;
GetWinDimension(); // get window dimensions
PaintRepScr();
return TRUE;
}
/****************************************************************************
PaintRepScr:
Paint the report screen window.
****************************************************************************/
PaintRepScr()
{
RECT rect;
HRGN rgn;
if (!PaintEnabled) return TRUE; // painting disabled
FrSetViewWindow(); // set the window origin
ShowScrRepStatus(); // print screen reporting status
// Clear the remaining area
rect.left=FrWinOrgX; // build the drawing area rectangle
rect.right=rect.left+FrWinWidth;
rect.top=FrWinOrgY;
rect.bottom=FrWinOrgY+FrWinHeight;
FillRect(hMemDC,&rect,hBackBrush);
// select clipping region to include only the drawing area
rgn=CreateRectRgn(FrRect.left,FrRect.top,FrRect.right,FrRect.bottom);
SelectClipRgn(hMemDC,rgn);
DeleteObject(rgn); // delete the temporary region
// Play the current metafile
if (hMetaFile) PlayMetaFile(hMemDC,hMetaFile);
// print the page break line
if (ReportStage==IN_EXIT && ScrPage==PageCount-1)
SelectObject(hMemDC,hSelectionPen); // mark end of report
else SelectObject(hMemDC,hFocusPen); // mark end of page
MoveToEx(hMemDC,0,PageHeight,NULL);
LineTo(hMemDC,PrintWidth,PageHeight);
// Copy the memory bitmap to the device
BitBlt(hFrDC,rect.left,rect.top,rect.right-rect.left,rect.bottom-rect.top,hMemDC,rect.left,rect.top,SRCCOPY);
ValidateRect(hFrWnd,NULL); // remove any pending paint messages
SelectClipRgn(hMemDC,NULL);
return TRUE;
}
/******************************************************************************
ShowScrRepStatus:
Display the progress of the screen reporting
******************************************************************************/
ShowScrRepStatus()
{
RECT rect;
char string[100];
int LabelLen;
// clear the status area
rect.left=FrWinOrgX; // build the status area rectangle
rect.right=rect.left+FrWinWidth;
rect.top=FrWinOrgY-FrWinRect.top;
rect.bottom=rect.top+(InputRect.bottom-InputRect.top);
FillRect(hMemDC,&rect,hInputAreaBrush);
// display status info
SetFont(hMemDC,DEFAULT_CFMT);
SetTextColor(hMemDC,DrawColor);
SetBkMode(hMemDC,TRANSPARENT);
if (ReportStage==IN_EXIT) { // report completely processed
// print page count
wsprintf(string," Last Page: %d",PageCount);
ExtTextOut(hMemDC,rect.left,rect.top,ETO_CLIPPED,&rect,string,lstrlen(string),NULL);
// print record count
wsprintf(string," Record Count: %d",RecCount);
ExtTextOut(hMemDC,rect.left,rect.top+CharHeight,ETO_CLIPPED,&rect,string,lstrlen(string),NULL);
}
else { // records being processed
// print page count
wsprintf(string," Processing Page# %d",PageCount);
ExtTextOut(hMemDC,rect.left,rect.top,ETO_CLIPPED,&rect,string,lstrlen(string),NULL);
// print record count
wsprintf(string," Processing Record#: %d",RecCount);
ExtTextOut(hMemDC,rect.left,rect.top+CharHeight,ETO_CLIPPED,&rect,string,lstrlen(string),NULL);
}
// print current screen page number
if (ReportStage==IN_EXIT || PageCount>1) {
wsprintf(string,"Current Page: %d ",ScrPage+1);
LabelLen=GetLabelLen(string,DEFAULT_CFMT);
ExtTextOut(hMemDC,rect.right-LabelLen,rect.top+CharHeight,ETO_CLIPPED,&rect,string,lstrlen(string),NULL);
}
// Copy the memory bitmap to the device
BitBlt(hFrDC,rect.left,rect.top,rect.right-rect.left,rect.bottom-rect.top,hMemDC,rect.left,rect.top,SRCCOPY);
return TRUE;
}
/******************************************************************************
RepUp:
Move the window upward.
******************************************************************************/
RepUp(int height)
{
int LastCompletePage;
if (ReportStage==IN_EXIT) LastCompletePage=PageCount;
else LastCompletePage=PageCount-1;
if (LastCompletePage==0) return TRUE;
if (FrWinOrgY>0) {
FrWinOrgY-=height;
if (FrWinOrgY<0) FrWinOrgY=0;
PaintRepScr(); // paint new screen page
}
else if (ScrPage>0) {
ScrPage--;
hMetaFile=ReadMetaFilePage(ScrPage,ScrMetaFile,hMetaFile); // read next print page
FrWinOrgY=PageHeight-(height-CharHeight); // show the bottom of the page
PaintRepScr(); // paint the new screen page
}
return TRUE;
}
/******************************************************************************
RepDown:
Move the window downward
******************************************************************************/
RepDown(int height)
{
int LastCompletePage;
if (ReportStage==IN_EXIT) LastCompletePage=PageCount;
else LastCompletePage=PageCount-1;
if (LastCompletePage==0) return TRUE;
if (FrWinOrgY+height<PageHeight) {
FrWinOrgY+=height;
PaintRepScr(); // paint new screen page
}
else if ((ScrPage+1)<LastCompletePage) {
ScrPage++;
hMetaFile=ReadMetaFilePage(ScrPage,ScrMetaFile,hMetaFile); // read next print page
FrWinOrgY=0; // show the top of the page
PaintRepScr(); // paint the new screen page
}
return TRUE;
}
/******************************************************************************
RepLeft:
Move the window leftward.
******************************************************************************/
RepLeft(int width)
{
int LastCompletePage;
if (ReportStage==IN_EXIT) LastCompletePage=PageCount;
else LastCompletePage=PageCount-1;
if (LastCompletePage==0) return TRUE;
if (FrWinOrgX>0) {
FrWinOrgX-=width;
if (FrWinOrgX<0) FrWinOrgX=0;
PaintRepScr(); // paint new screen page
}
return TRUE;
}
/******************************************************************************
RepRight:
Move the window rightward.
******************************************************************************/
RepRight(int width)
{
int LastCompletePage;
if (ReportStage==IN_EXIT) LastCompletePage=PageCount;
else LastCompletePage=PageCount-1;
if (LastCompletePage==0) return TRUE;
if (FrWinOrgX<PrintWidth) {
FrWinOrgX+=width;
PaintRepScr(); // paint new screen page
}
return TRUE;
}
/******************************************************************************
ProcessUserCommands:
This routine is called from the RepRec function after processing a record.
This routine retrieve the user commands to scroll
the output window or carryout menu functions. This function returns
when all messages are processed.
*******************************************************************************/
ProcessUserCommands()
{
MSG msg;
//*** process messages but do not yield ***
while (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) {
if (!TranslateAccelerator(msg.hwnd,hFrAccTable,&msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
if (ReportStatus==REP_ABORT) break;
}
// check if user wishes to abort the processing
if (ReportStatus==REP_ABORT && ReportStage==IN_RECORDS) {
ErrorCode=ERR_SUSPEND;
// return the error code
#if defined (WIN32)
longjmp(FrAbort,-1);
#else
Throw((LPCATCHBUF) &FrAbort,-1);
#endif
}
return TRUE;
}
/******************************************************************************
PageJump:
Position at the requested screen page.
*******************************************************************************/
PageJump()
{
int page;
page=CallDialogBox("JumpParam",JumpParam,0);
if (page==0) return TRUE; // cancelled by the user
if (page-1!=ScrPage) { // jump
ScrPage=page-1; // screen page number to jump to
hMetaFile=ReadMetaFilePage(ScrPage,ScrMetaFile,hMetaFile); // read next print page
FrWinOrgY=0; // show the top of the page
PaintRepScr(); // paint the new screen page
}
return TRUE;
}
/******************************************************************************
SelectivePrint:
Print selected pages from the screen
*******************************************************************************/
SelectivePrint()
{
HDC hPrtDC;
char line[LINE_WIDTH+1];
FARPROC lpProc;
int i,SaveReportStatus,SavePageCount,SaveResX,SaveResY;
HMETAFILE hMetaFile=NULL;
if (!CallDialogBox("PrintParam",PrintParam,0)) return TRUE;
FirstPrintPage--; // convert to 0 base
LastPrintPage--;
// open the printer
strcpy(line,PrinterDriver);
line[strlen(line)-4]=0; // strip the .drv extension
if (NULL==(hPrtDC=CreateDC(line,PrinterName,PrinterPort,pDevMode))) {
MessageBox(hFrWnd,"Can not initialize printing",NULL,MB_OK);
return FALSE;
}
// preprare for printing
lpProc = MakeProcInstance((FARPROC)ScrPrintProc, hFrInst);
lpAbortDlg = MakeProcInstance((FARPROC)ScrPrintAbortParam, hFrInst);
Escape(hPrtDC,SETABORTPROC,0,(LPSTR)(long)lpProc,NULL); // activate the abort routine
if (Escape(hPrtDC,STARTDOC,strlen(FormHdr.name),FormHdr.name,NULL)<0) {
MessageBox(hFrWnd,"Unable to Start the Print Job",NULL,MB_OK);
return FALSE;
}
hAbortWnd=CreateDialog(hFrInst,"ScrPrintAbortParam",hFrWnd,(DLGPROC)lpAbortDlg);
ShowWindow(hAbortWnd,SW_NORMAL);
UpdateWindow(hAbortWnd);
if (hFrWnd) EnableWindow(hFrWnd,FALSE); // disable the main window
// set the printer status
SaveReportStatus=ReportStatus; // save the current report status
SavePageCount=PageCount; // save the current page count
SaveResX=ResX; // save the screen resolution
SaveResY=ResY;
ResX=GetDeviceCaps(hPrtDC,LOGPIXELSX); // number of pixels per inch of X direction
ResY=GetDeviceCaps(hPrtDC,LOGPIXELSY); // number of pixels per inch of Y direction
PageCount=1;
// print each page
for (i=FirstPrintPage;i<=LastPrintPage;i++) {
SetLogicalUnit(hPrtDC); // set the logical units
hMetaFile=ReadMetaFilePage(i,PrtMetaFile,hMetaFile); // read next print page
if (hMetaFile) PlayMetaFile(hPrtDC,hMetaFile); // play the metafile page
Escape(hPrtDC,NEWFRAME,0,0L,0L); // advance to the next page
if (ReportStatus==REP_ABORT) break;
PageCount++;
}
//reset the print status
ResX=SaveResX; // restore the screen resolution
ResY=SaveResY;
ReportStatus=SaveReportStatus; // restore the current report status
PageCount=SavePageCount; // restore the current page count
// end the printing
Escape(hPrtDC,ENDDOC,0,0L,0L); // end of print job
if (hFrWnd) EnableWindow(hFrWnd,TRUE); // activate the parent window
if (hMetaFile) DeleteMetaFile(hMetaFile);
DestroyWindow(hAbortWnd); // destroy the abort window
FreeProcInstance(lpProc); // free the process instances
FreeProcInstance(lpAbortDlg);
DeleteDC(hPrtDC);
hPrtDC=NULL;
return TRUE;
}
/******************************************************************************
AdvancePage:
Advance to the next page.
*******************************************************************************/
AdvancePage(int CurSec)
{
int i,sec;
int fld;
BOOL calculated=FALSE;
if (ReportStatus==REP_ABORT) return TRUE;
if (PageAdvanced || AdvancingPage) return FALSE; // page already advanced
AdvancingPage=TRUE; // advancing to next page
CurHeight=PrintHeight;
PrintSection(SEC_FTR_PAGE); // print page footer
if (UseScreen) {
TransferMetaFile(); // transfer the current page to the meta file
}
else {
Escape(hFrDC,NEWFRAME,0,0L,0L); // advance to the next page
PrintProc(hFrDC,0); // show the last status
if (ReportStatus==REP_ABORT) {
if (ReportStage==IN_EXIT) return FALSE;
else {
ErrorCode=ERR_SUSPEND;
// return error code
#if defined (WIN32)
longjmp(FrAbort,-1);
#else
Throw((LPCATCHBUF) &FrAbort,-1);
#endif
}
}
StartPage(hFrDC);
SetLogicalUnit(hFrDC); // set the logical units
}
PageCount++;
CurHeight=TopMargin;
//******************** zero the page totals **************
for(fld=0;fld<TotalFields;fld++) {
if (field[fld].InUse && field[fld].section==SEC_FTR_PAGE) {
if (!(FLAG_RETAIN&field[fld].flags)) {
field[fld].HoldNum=0;
field[fld].HoldDbl=0;
field[fld].count=0;
if (field[fld].SumType==SUM_MAX || field[fld].SumType==SUM_MIN) {
field[fld].HoldNum=UserField[fld].NumData;
field[fld].HoldDbl=UserField[fld].DblData;
}
}
}
//** update the system page count fields **
if (field[fld].source==SRC_SYS && field[fld].SysIdx==SYS_PAGE) field[fld].NumData=PageCount;
}
//*************** Initialize the next page ***************
if (!TrialMode) {
PrintSection(SEC_HDR_PAGE); // print page headers
if (CurSec>=SEC_DETAIL1 && CurSec<=SEC_DETAIL9) {
for (i=0;i<TotalBreakFields;i++) { // print group headers if needed
sec=BreakField[i].section;
if (SFLAG_REPRINT&(section[sec].flags)) {
if (!calculated) {
CalculateFields(0,SEC_HDR_LVL9); // calculate all fields for all section
calculated=TRUE;
}
PrintSection(sec);
}
}
}
}
AdvancingPage=FALSE; // page advance complete
PageAdvanced=TRUE;
// show screen pages and update menu
if (UseScreen) {
if (PageCount==2) {
RepInitMenu(hFrMenu); // enable screen printing
PaintRepScr(); // show the first screen
}
else if (PageCount==3) RepInitMenu(hFrMenu); // enable page jump
}
return TRUE;
}
/*****************************************************************************
CreateNewMetaFiles:
Create permanent and temporary meta files.
*****************************************************************************/
CreateNewMetaFiles()
{
char prefix[13];
// build directory path
if (lstrlen(RepArg.SwapDir)==0) RepGetCurDir(RepArg.SwapDir);
if (lstrlen(RepArg.SwapDir)!=0) {
if (RepArg.SwapDir[lstrlen(RepArg.SwapDir)-1]!='\\') lstrcat(RepArg.SwapDir,"\\");
}
// build file prefix - make unique by using the current system time
lstrcpy(prefix,SystemTime);
prefix[2]=prefix[5]='R'; // replace ':' in time by a letter
// create permanent metafile
lstrcpy(MetaFile,RepArg.SwapDir);
lstrcat(MetaFile,prefix);
lstrcat(MetaFile,".MF");
// create temporary metafile name
lstrcpy(TempMetaFile,RepArg.SwapDir);
lstrcat(TempMetaFile,prefix);
lstrcat(TempMetaFile,".MFT");
// create screen metafile name
lstrcpy(ScrMetaFile,RepArg.SwapDir);
lstrcat(ScrMetaFile,prefix);
lstrcat(ScrMetaFile,".MFS");
// create selective print metafile name
lstrcpy(PrtMetaFile,RepArg.SwapDir);
lstrcat(PrtMetaFile,prefix);
lstrcat(PrtMetaFile,".MFP");
return TRUE;
}
/*****************************************************************************
TransferMetaFile:
Transfer the current page meta file to the permanent file.
*****************************************************************************/
TransferMetaFile()
{
HMETAFILE hMeta1,hMeta2;
long FileSize;
if (PageCount==1) {
CreateNewMetaFiles(); // Create permanent and temporary metafiles
PageLoc[0]=0;
}
if (NULL==(hMeta1=CloseMetaFile(hMetaDC))) AbortFr("Error Creating Meta File(TransferMetaFile)",ERR_NO_FILE);
unlink(TempMetaFile); // delete any old temporary disk meta file
if (NULL==(hMeta2=CopyMetaFile(hMeta1,TempMetaFile))) AbortFr("Error Copying Meta File(TransferMetaFile)",ERR_NO_FILE);
DeleteMetaFile(hMeta2); // delete temporary memory meta files
// transfer temporary disk meta file to the permanent disk meta file
FileSize=GetFileLength(TempMetaFile);
CopyFileData(TempMetaFile,0,MetaFile,PageLoc[PageCount-1],FileSize);
// record the page location data
PageLoc[PageCount]=PageLoc[PageCount-1]+FileSize;
// create new memory meta file device context
if (NULL==(hMetaDC=CreateMetaFile(NULL))) AbortFr("Error creating metafile(TransferMetaFile)",ERR_NO_FILE);
// assign the first screen meta file
if (PageCount==1 && !hMetaFile) hMetaFile=hMeta1;
else DeleteMetaFile(hMeta1);
return TRUE;
}
/*****************************************************************************
ReadMetaFilePage:
Read one page from the permanent disk file to the new meta file and
returns a meta file handle.
*****************************************************************************/
HMETAFILE ReadMetaFilePage(int page,LPSTR NewMetaFile,HMETAFILE hMetaFile)
{
HMETAFILE hNewMeta;
// delete old memory meta file
if (hMetaFile) {
DeleteMetaFile(hMetaFile);
hMetaFile=0;
}
unlink(NewMetaFile); // delete any existing temp file
CopyFileData(MetaFile,PageLoc[page],NewMetaFile,0,PageLoc[page+1]-PageLoc[page]);
// get a meta file from the temporary disk file
if (NULL==(hMetaFile=GetMetaFile(NewMetaFile))) AbortFr("Error getting the disk meta file(ReadMetaFilePage)",ERR_NO_FILE);
// create the memory metafile
if (NULL==(hNewMeta=CopyMetaFile(hMetaFile,NULL))) return hMetaFile; // forced to used slow disk meta file
else { // use fast memory meta file
DeleteMetaFile(hMetaFile); // delete the disk meta file
return hNewMeta;
}
}
/*****************************************************************************
PrintTrial:
This routine prints the trial records. Trials records can be used
to adjust the form before printing the data records.
*****************************************************************************/
PrintTrial()
{
int i,j;
if (IDNO==MessageBox(hFrWnd,"Print a Trial Record Now?","Trial Print",MB_YESNO)) return TRUE;
PRINT_ONE_RECORD:
TrialMode=TRUE;
for (i=0;i<MAX_SECTIONS;i++) {
if (i==SEC_DETAIL1 && section[i].columns>1) {
for (j=0;j<section[i].columns;j++) PrintSection(i);
}
else PrintSection(i);
}
//***** Advance page if other than detail section used *****************
for (i=0;i<MAX_SECTIONS;i++) {
if ((i<SEC_DETAIL1 || i>SEC_DETAIL9) && section[i].InUse) {
AdvancePage(i);
PageCount=1;
break;
}
}
TrialMode=FALSE;
if (IDYES==MessageBox(hFrWnd,"Print another Trial Record?","Trial Record",MB_YESNO)) goto PRINT_ONE_RECORD;
return TRUE;
}
/******************************************************************************
PrintProc:
Dispatches the messages to the PrintAbort routine, and checks
if the user cancelled the printing
******************************************************************************/
int CALLBACK _export PrintProc(HDC hPr, int code)
{
MSG msg;
char string[20];
int count;
//**************** show the page and record counters ******
count=GetDlgItemInt(hAbortDlg,IDC_CUR_REC,NULL,FALSE);
if (count!=RecCount) {
itoa(PageCount,string,10);
SetDlgItemText(hAbortDlg,IDC_CUR_PAGE,string);
ltoa(RecCount,string,10);
SetDlgItemText(hAbortDlg,IDC_CUR_REC,string);
}
//**************** yield to other processes *****************
while (ReportStatus!=REP_ABORT && hPr==hFrDC && PeekMessage(&msg,NULL,0,0,TRUE)) { // process message until abort
if (!IsDialogMessage(hAbortWnd,&msg)) { // dispatch modeless dialog messages
TranslateMessage(&msg); // translate/dispatch other window messages
DispatchMessage(&msg);
}
if (code) ReportStatus=REP_ABORT;
}
return TRUE;
}
/******************************************************************************
ScrPrintProc:
Dispatches the messages to the ScrPrintAbort routine, and checks
if the user cancelled the printing
******************************************************************************/
int CALLBACK _export ScrPrintProc(HDC hPr, int code)
{
MSG msg;
char string[20];
int count;
//**************** show the page counter ******
count=GetDlgItemInt(hAbortDlg,IDC_CUR_PAGE,NULL,FALSE);
if (count!=PageCount) {
itoa(PageCount,string,10);
SetDlgItemText(hAbortDlg,IDC_CUR_PAGE,string);
}
//**************** yield to other processes *****************
while (ReportStatus!=REP_ABORT && PeekMessage(&msg,0,0,0,TRUE)) { // process message until abort
if (!IsDialogMessage(hAbortWnd,&msg)) { // dispatch modeless dialog messages
TranslateMessage(&msg); // translate/dispatch other window messages
DispatchMessage(&msg);
}
if (code) ReportStatus=REP_ABORT;
}
return TRUE;
}
/******************************************************************************
RepGetCurDir:
get full path name of the current working directory
*******************************************************************************/
LPSTR RepGetCurDir(LPSTR CurDir)
{
#if defined (WIN32)
GetCurrentDirectory(LINE_WIDTH/2,CurDir);
#else
char CurDrv[4],TempDir[64];
union REGS reg;
struct SREGS sreg;
/*********** get default drive ***********/
segread(&sreg);
reg.h.ah=0x19;
int86x(0x21,®,®,&sreg);
CurDrv[0]=reg.h.al+'A';
CurDrv[1]=0;
lstrcat(CurDrv,":\\");
/* get current sub directory ******/
reg.h.ah=0x47;
reg.h.dl=0;
sreg.ds=(WORD)(((unsigned long)(LPSTR)TempDir)>>16);
sreg.es=sreg.ds; /* must provide a valid selector in ES */
reg.x.si=(WORD)((((unsigned long)(LPSTR)TempDir)<<16)>>16);
int86x(0x21,®,®,&sreg);
lstrcpy(CurDir,CurDrv);
lstrcat(CurDir,TempDir);
#endif
return CurDir;
}
/******************************************************************************
CopyFileData:
Copy specified number if bytes from the source file to the destination file.
*******************************************************************************/
int CopyFileData(LPSTR SrcFile, long SrcPos, LPSTR DstFile, long DstPos, long count)
{
HFILE iFile,oFile;
OFSTRUCT OpenBuf;
int bytes;
// open the source file
if ((iFile=OpenFile(SrcFile,&OpenBuf,OF_READ))==HFILE_ERROR) AbortFr("Error opening the input file(CopyFileData)",ERR_NO_FILE);
if (_llseek(iFile,SrcPos,0)==HFILE_ERROR) AbortFr("Error seeking the input file(CopyFileData)",ERR_NO_FILE);
// open the destination file
if (OpenFile(DstFile,&OpenBuf,OF_EXIST)!=HFILE_ERROR) {
if ((oFile=OpenFile(DstFile,&OpenBuf,OF_READWRITE))==HFILE_ERROR) AbortFr("Error opening the output file(CopyFileData)",ERR_NO_FILE);
if (_llseek(oFile,DstPos,0)==HFILE_ERROR) AbortFr("Error seeking the output file(CopyFileData)",ERR_NO_FILE);
}
else if ((oFile=OpenFile(DstFile,&OpenBuf,OF_WRITE|OF_CREATE))==HFILE_ERROR) AbortFr("Error opening the output file(CopyFileData A)",ERR_NO_FILE);
// copy the file data
while(count>0) {
bytes=BUF_SIZE; //transfer size
if ((long)bytes>count) bytes=(int)count;
if (_lread(iFile,FileBuf,bytes)==(UINT)HFILE_ERROR) AbortFr("Error reading the input file(CopyFileData)",ERR_NO_FILE); // read
if (_lwrite(oFile,FileBuf,bytes)==(UINT)HFILE_ERROR) AbortFr("Error writing the output file(CopyFileData)",ERR_NO_FILE); // write
count-=bytes;
}
// close the files
_lclose(iFile);
_lclose(oFile);
return TRUE;
}