1.3 updates

This commit is contained in:
tengel 2024-03-20 09:28:18 -05:00
parent e32ba2d80d
commit 42d34dfa8b
13 changed files with 627 additions and 725 deletions

131
CB32.clw
View file

@ -2,13 +2,13 @@
[General Info]
Version=1
LastClass=CCB32View
LastTemplate=CPropertyPage
LastClass=CPMerge
LastTemplate=CDialog
NewFileInclude1=#include "stdafx.h"
NewFileInclude2=#include "cb32.h"
LastPage=0
ClassCount=25
ClassCount=26
Class1=CMainFrame
Class2=CPropAdd
Class3=CPropInfo
@ -25,32 +25,34 @@ Class13=CFindDlg
Class14=CTBComboBox
Class15=CComboToolBar
ResourceCount=15
Resource1=IDD_PPAGE
Resource2=IDR_CONTEXTMENU
Resource3=IDD_ABOUTBOX
Resource4=IDD_COLPAGE
Resource5=IDD_CONVERT
Resource6=IDR_MAINFRAME
Resource7=IDD_SETPAGE
ResourceCount=16
Resource1=IDD_COLPAGE
Resource2=IDD_GETNEW
Resource3=IDD_NPAGE
Resource4=IDD_PPAGE
Resource5=IDD_SETPAGE
Resource6=IDD_ABOUTBOX
Resource7=IDD_CONVERT
Resource8=IDR_TRAYMENU
Resource9=IDD_APAGE
Resource10=IDD_OPAGE
Resource9=IDD_OPAGE
Resource10=IDD_APAGE
Class16=CProgDlg
Class17=CSetPage
Class18=CDefPage
Class19=CColPage
Class20=CPrefPage
Resource11=IDD_CPAGE
Resource12=IDD_GETNEW
Resource13=IDD_ORDPAGE
Resource11=IDD_ORDPAGE
Resource12=IDR_CONTEXTMENU
Resource13=IDD_CPAGE
Class21=CGetNew
Class22=CPropComp
Class23=CMyHeaderCtrl
Class24=CHyperLink
Resource14=IDD_FIND
Resource14=IDD_PMERGE
Class25=COrdPage
Resource15=IDD_NPAGE
Resource15=IDD_FIND
Class26=CPMerge
Resource16=IDR_MAINFRAME
[CLS:CMainFrame]
Type=0
@ -220,7 +222,7 @@ Command1=ID_ENTRY_COPY
Command2=ID_EDIT_FIND
Command3=ID_FILE_NEW
Command4=ID_FILE_OPEN
Command5=ID_FILE_PRINT
Command5=ID_FILE_PRINT_MERGE
Command6=ID_FILE_SAVE
Command7=ID_EDIT_PASTE
Command8=ID_EDIT_UNDO
@ -269,33 +271,34 @@ Command5=ID_IMPORT_CSV
Command6=ID_IMPORT_TAB
Command7=ID_EXPORT_CSV
Command8=ID_EXPORT_TAB
Command9=ID_FILE_MRU_FILE1
Command10=ID_APP_EXIT
Command11=ID_EDIT_FIND
Command12=ID_VIEW_FIND_NEXT
Command13=ID_APP_PREFS
Command14=ID_ENTRY_ADD
Command15=ID_ENTRY_EDIT
Command16=ID_ENTRY_DELETE
Command17=ID_ENTRY_COPY
Command18=ID_DIAL_HOME
Command19=ID_DIAL_WORK
Command20=ID_DIAL_PAGER
Command21=ID_DIAL_FAX
Command22=ID_DIAL_CELL
Command23=ID_EMAIL_ADD1
Command24=ID_EMAIL_ADD2
Command25=ID_URL1
Command26=ID_URL2
Command27=ID_VIEW_TOOLBAR
Command28=ID_VIEW_STATUS_BAR
Command29=ID_VIEW_FLATBAR
Command30=ID_VIEW_WNDPOS
Command31=ID_VIEW_COLSET
Command32=ID_VIEW_COLPOS
Command33=ID_HELP_INDEX
Command34=ID_APP_ABOUT
CommandCount=34
Command9=ID_FILE_PRINT_MERGE
Command10=ID_FILE_MRU_FILE1
Command11=ID_APP_EXIT
Command12=ID_EDIT_FIND
Command13=ID_VIEW_FIND_NEXT
Command14=ID_APP_PREFS
Command15=ID_ENTRY_ADD
Command16=ID_ENTRY_EDIT
Command17=ID_ENTRY_DELETE
Command18=ID_ENTRY_COPY
Command19=ID_DIAL_HOME
Command20=ID_DIAL_WORK
Command21=ID_DIAL_PAGER
Command22=ID_DIAL_FAX
Command23=ID_DIAL_CELL
Command24=ID_EMAIL_ADD1
Command25=ID_EMAIL_ADD2
Command26=ID_URL1
Command27=ID_URL2
Command28=ID_VIEW_TOOLBAR
Command29=ID_VIEW_STATUS_BAR
Command30=ID_VIEW_FLATBAR
Command31=ID_VIEW_WNDPOS
Command32=ID_VIEW_COLSET
Command33=ID_VIEW_COLPOS
Command34=ID_HELP_INDEX
Command35=ID_APP_ABOUT
CommandCount=35
[DLG:IDD_CONVERT]
Type=1
@ -442,7 +445,7 @@ HeaderFile=FindDlg.h
ImplementationFile=FindDlg.cpp
BaseClass=CDialog
Filter=D
LastObject=IDC_FCOMBO
LastObject=CFindDlg
VirtualFilter=dWC
[CLS:CTBComboBox]
@ -766,3 +769,37 @@ Filter=D
VirtualFilter=idWC
LastObject=IDC_RESETCOL
[DLG:IDD_PMERGE]
Type=1
Class=CPMerge
ControlCount=20
Control1=IDC_PMTEMPLATE,combobox,1344340227
Control2=IDC_PMNEW,button,1342242816
Control3=IDC_PMDELETE,button,1342242816
Control4=IDC_PMHEAD,button,1342242816
Control5=IDC_PMBODY,button,1342242816
Control6=IDC_PMFOOT,button,1342242816
Control7=IDC_PM_FILE,edit,1350631552
Control8=IDC_PMBROW_FILE,button,1342242816
Control9=IDC_PM_EDIT,edit,1350631552
Control10=IDC_PMBROW_EDIT,button,1342242816
Control11=IDC_PM_VIEW,edit,1350631552
Control12=IDC_PMBROW_VIEW,button,1342242816
Control13=IDC_PMLAUNCH,button,1342242819
Control14=IDOK,button,1342242817
Control15=IDCANCEL,button,1342242816
Control16=IDC_STATIC,button,1342177287
Control17=IDC_STATIC,button,1342177287
Control18=IDC_STATIC,static,1342308352
Control19=IDC_STATIC,static,1342308352
Control20=IDC_STATIC,static,1342308352
[CLS:CPMerge]
Type=0
HeaderFile=PMerge.h
ImplementationFile=PMerge.cpp
BaseClass=CDialog
Filter=D
LastObject=IDC_PMBROW_VIEW
VirtualFilter=dWC

View file

@ -49,12 +49,14 @@ CCB32App theApp;
BOOL CCB32App::InitInstance()
{
// find the location of the exe from Help File Path
CString sHelp, sIni;
sHelp = m_pszHelpFilePath;
sIni = sHelp.Left(sHelp.ReverseFind('.'));
sIni += ".INI";
CString szHelp, szPath;
szHelp = m_pszHelpFilePath;
szPath = szHelp.Left(szHelp.ReverseFind('.')) + ".INI";
free((void*)m_pszProfileName);
m_pszProfileName = _tcsdup((LPCSTR)sIni);
m_pszProfileName = _tcsdup((LPCSTR)szPath);
// set global path to self
szPath = szHelp.Left(szHelp.ReverseFind('\\')) + '\\';
m_pszPathToExe = _tcsdup((LPCSTR)szPath);
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL

2
CB32.h
View file

@ -32,6 +32,8 @@ public:
virtual BOOL OnIdle(LONG lCount);
CCB32App();
CString m_pszPathToExe;
// Operations
public:
void UpdateIniFileWithDocPath(LPCTSTR lpszPathName);

49
CB32.rc
View file

@ -164,6 +164,14 @@ BEGIN
TOPMARGIN, 7
BOTTOMMARGIN, 162
END
IDD_PMERGE, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 195
TOPMARGIN, 7
BOTTOMMARGIN, 182
END
END
#endif // APSTUDIO_INVOKED
@ -179,7 +187,7 @@ BEGIN
"F", ID_EDIT_FIND, VIRTKEY, CONTROL, NOINVERT
"N", ID_FILE_NEW, VIRTKEY, CONTROL, NOINVERT
"O", ID_FILE_OPEN, VIRTKEY, CONTROL, NOINVERT
"P", ID_FILE_PRINT, VIRTKEY, CONTROL, NOINVERT
"P", ID_FILE_PRINT_MERGE, VIRTKEY, CONTROL, NOINVERT
"S", ID_FILE_SAVE, VIRTKEY, CONTROL, NOINVERT
"V", ID_EDIT_PASTE, VIRTKEY, CONTROL, NOINVERT
VK_BACK, ID_EDIT_UNDO, VIRTKEY, ALT, NOINVERT
@ -764,6 +772,38 @@ BEGIN
PUSHBUTTON "Reset",IDC_RESETCOL,168,98,50,14
END
IDD_PMERGE DIALOG DISCARDABLE 0, 0, 202, 189
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Print Merge"
FONT 8, "MS Sans Serif"
BEGIN
COMBOBOX IDC_PMTEMPLATE,13,21,104,88,CBS_DROPDOWNLIST | CBS_SORT |
WS_VSCROLL | WS_TABSTOP
PUSHBUTTON "New",IDC_PMNEW,13,43,50,14
PUSHBUTTON "Delete",IDC_PMDELETE,67,43,50,14
PUSHBUTTON "Header",IDC_PMHEAD,132,20,50,14
PUSHBUTTON "Body",IDC_PMBODY,132,36,50,14
PUSHBUTTON "Footer",IDC_PMFOOT,132,52,50,14
EDITTEXT IDC_PM_FILE,13,79,160,12,ES_AUTOHSCROLL
PUSHBUTTON "...",IDC_PMBROW_FILE,178,79,11,12
EDITTEXT IDC_PM_EDIT,13,106,160,12,ES_AUTOHSCROLL
PUSHBUTTON "...",IDC_PMBROW_EDIT,178,106,11,12
EDITTEXT IDC_PM_VIEW,13,133,160,12,ES_AUTOHSCROLL
PUSHBUTTON "...",IDC_PMBROW_VIEW,178,133,11,12
CONTROL "Launch File/Viewer Automatically",IDC_PMLAUNCH,"Button",
BS_AUTOCHECKBOX | WS_TABSTOP,40,149,121,10
DEFPUSHBUTTON "OK",IDOK,90,168,50,14
PUSHBUTTON "Cancel",IDCANCEL,145,168,50,14
GROUPBOX "Template ",IDC_STATIC,7,3,188,160
GROUPBOX "Edit ",IDC_STATIC,125,10,63,62
LTEXT "Output File: (include extension)",IDC_STATIC,13,68,100,
8
LTEXT "Editor: (must accept filename on commandline)",
IDC_STATIC,13,95,149,8
LTEXT "Viewer: (leave blank for default system viewer)",
IDC_STATIC,13,121,148,8
END
/////////////////////////////////////////////////////////////////////////////
//
@ -834,6 +874,8 @@ BEGIN
MENUITEM "&Tab Delimited", ID_EXPORT_TAB
END
MENUITEM SEPARATOR
MENUITEM "Print Merge\tCtrl+P", ID_FILE_PRINT_MERGE
MENUITEM SEPARATOR
MENUITEM "Recent File", ID_FILE_MRU_FILE1, GRAYED
MENUITEM SEPARATOR
MENUITEM "E&xit", ID_APP_EXIT
@ -1113,6 +1155,7 @@ BEGIN
ID_ENTRY_EDIT "Edit the Current Address\nEdit"
ID_ENTRY_DELETE "Delete the Current Address\nDelete"
ID_ENTRY_COPY "Copy the Current Address\nCopy"
ID_FILE_PRINT_MERGE "Generate a Print Merge file\nPrint Merge"
END
STRINGTABLE DISCARDABLE
@ -1198,6 +1241,10 @@ BEGIN
IDS_COLSAVE "Column widths have been saved."
IDS_POSSAVE "Column positions have been saved."
IDS_PREFS "Preferences"
IDS_PRN_PAGE_FORMAT "Page: %2d"
IDS_MISSTMPL "One of the template files appears to be missing. Please check the TMPL directory to ensure the 4 required files (.TPL, .HED, .BOD, .FOT) are present."
IDS_OFN_OUT "Type New Filename or Choose Existing File"
IDS_OFN_EXE "Select Executable File"
END
#endif // English (U.S.) resources

View file

@ -218,7 +218,7 @@ BOOL CCB32Doc::FileImport(CString fileName, char* whitesp, char* breakch)
CConvertDlg convertDlg;
if (inFile.ReadString(strLine,511)!=NULL)
{
newline = strstr(strLine, "\n");
newline = _tcsstr(strLine, "\n");
strpos = newline - strLine;
if (strpos != NULL)
strLine[strpos]='\0';
@ -386,7 +386,7 @@ BOOL CCB32Doc::FileImport(CString fileName, char* whitesp, char* breakch)
int z=0, next=0;
BOOL addexpr = FALSE;
CExpr *expr = new CExpr("contact");
CExpr *expr = new CExpr(_T("contact"));
inList.RemoveAll();
while(parser(0,strToken,sizeof(strLine),strLine,whitesp,breakch,
@ -402,7 +402,7 @@ BOOL CCB32Doc::FileImport(CString fileName, char* whitesp, char* breakch)
if (convertDlg.m_xlname>0 && convertDlg.m_xlname<z)
{
posIndex = inList.FindIndex(convertDlg.m_xlname-1);
expr->AddAttributeValueString("LastName", inList.GetAt(posIndex));
expr->AddAttributeValueString(_T("LastName"), inList.GetAt(posIndex));
addexpr = TRUE;
}
if (convertDlg.m_xfname>0 && convertDlg.m_xfname<z)
@ -804,7 +804,7 @@ BOOL CCB32Doc::FileExport(CString fileName, char* breakch)
// add firstline identifier
db.ClearDatabase();
CExpr *expr = new CExpr("contact");
expr->AddAttributeValueString("LastName", "LASTNAME");
expr->AddAttributeValueString(_T("LastName"), _T("LASTNAME"));
expr->AddAttributeValueString("FirstName", "FIRSTNAME");
expr->AddAttributeValueString("MiddleInitial", "MI");
expr->AddAttributeValueString("Title", "TITLE");
@ -861,7 +861,7 @@ BOOL CCB32Doc::FileExport(CString fileName, char* breakch)
if (convertDlg.m_xlname>0)
{
expr->GetAttributeValue("LastName", strTemp);
expr->GetAttributeValue(_T("LastName"), strTemp);
dataArray.SetAtGrow(convertDlg.m_xlname, strTemp);
}
if (convertDlg.m_xfname>0)

View file

@ -17,6 +17,7 @@
#include "FindDlg.h"
#include "GetNew.h"
#include "PrefPage.h"
#include "PMerge.h"
#ifdef _DEBUG
#define new DEBUG_NEW
@ -24,17 +25,6 @@
static char THIS_FILE[] = __FILE__;
#endif
#define HEADER_HEIGHT 2
#define FOOTER_HEIGHT 2
#define LEFT_MARGIN 4
#define RIGHT_MARGIN 4
#define TOP_MARGIN 1
#define BOTTOM_MARGIN 1
#define GAP 1
#define HIGHLIGHT_NORMAL 1
#define HIGHLIGHT_ALLCOLUMNS 2
#define HIGHLIGHT_ROW 3
/////////////////////////////////////////////////////////////////////////////
// CCB32View
@ -87,6 +77,7 @@ BEGIN_MESSAGE_MAP(CCB32View, CListView)
ON_COMMAND(ID_VIEW_COLPOS, OnViewColpos)
ON_COMMAND(ID_ENTRY_COPY, OnEntryCopy)
ON_UPDATE_COMMAND_UI(ID_ENTRY_COPY, OnUpdateEntryCopy)
ON_COMMAND(ID_FILE_PRINT_MERGE, OnFilePrintMerge)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CListView::OnFilePrint)
@ -99,7 +90,7 @@ END_MESSAGE_MAP()
CCB32View::CCB32View()
{
m_nHighlight = 1;
//m_nHighlight = 1;
m_iFirst = 0;
m_pFindDialog = new CFindDlg;
m_headerctrl.SetCallback( this, (void (CWnd::*)(int, int))DragColumn );
@ -132,9 +123,6 @@ void CCB32View::OnDraw(CDC* pDC)
{
CCB32Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
void CCB32View::OnInitialUpdate()
@ -150,6 +138,7 @@ void CCB32View::OnInitialUpdate()
// Add items to the list view.
CListCtrl& ctlList = (CListCtrl&) GetListCtrl();
FreeItems();
ctlList.DeleteAllItems();
ctlList.SetBkColor(GetSysColor(COLOR_WINDOW));
@ -288,648 +277,176 @@ void CCB32View::DrawItemText(CDC* pDC, CString text, CRect rect,
/////////////////////////////////////////////////////////////////////////////
// CCB32View printing
BOOL CCB32View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CCB32View::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
void CCB32View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
CListCtrl& ctlList = (CListCtrl&) GetListCtrl();
TEXTMETRIC tm;
CDC *pCurrentDC;
// OnBeginPrinting() is called after the user has committed to
// printing by OK'ing the Print dialog, and after the framework
// has created a CDC object for the printer or the preview view.
// This is the right opportunity to set up the page range.
// Given the CDC object, we can determine how many rows will
// fit on a page, so we can in turn determine how many printed
// pages represent the entire document.
ASSERT(pDC && pInfo);
if (!pDC || !pInfo) return;
int nMaxRowCount = ctlList.GetItemCount();
if (!nMaxRowCount) return;
// Get a DC for the current window (will be a screen DC for print previewing)
VERIFY(pCurrentDC = GetDC()); /* will have dimensions of the client area */
if (!pCurrentDC) return;
CSize PaperPixelsPerInch(pDC->GetDeviceCaps(LOGPIXELSX),
pDC->GetDeviceCaps(LOGPIXELSY));
CSize ScreenPixelsPerInch(pCurrentDC->GetDeviceCaps(LOGPIXELSX),
pCurrentDC->GetDeviceCaps(LOGPIXELSY));
// Create the printer font
int nFontSize = -9;
CString strFontName = _T("Times New Roman");
nFontSize = MulDiv(nFontSize, PaperPixelsPerInch.cy, ScreenPixelsPerInch.cy);
m_PrinterFont.CreateFont(nFontSize, 0,0,0, FW_NORMAL, 0,0,0, DEFAULT_CHARSET,
OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS,
DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE,
strFontName);
CFont *pOldFont = pDC->SelectObject(&m_PrinterFont);
// Get the average character width (in ListCtrl units)
pCurrentDC->GetTextMetrics(&tm);
m_nCharWidth = tm.tmAveCharWidth;
m_nCharWidth = MulDiv(m_nCharWidth, PaperPixelsPerInch.cy,
ScreenPixelsPerInch.cy);
int nMargins = (LEFT_MARGIN+RIGHT_MARGIN)*m_nCharWidth;
// Scale the x axis to the ListCtrl's device units
CRect rc;
ctlList.GetItemRect(0, &rc, LVIR_BOUNDS);
m_nRowHeight = rc.Height();
m_nRowHeight = MulDiv(m_nRowHeight, PaperPixelsPerInch.cy,
ScreenPixelsPerInch.cy);
// Get the page size
CSize LogicalPageSize;
CSize PaperSize(pDC->GetDeviceCaps(HORZRES),
pDC->GetDeviceCaps(VERTRES));
LogicalPageSize.cx = rc.Width()+nMargins;
LogicalPageSize.cy = MulDiv(LogicalPageSize.cx, PaperSize.cy,
PaperSize.cx);
pDC->SetMapMode(MM_ANISOTROPIC);
pDC->SetWindowExt(LogicalPageSize);
pDC->SetViewportExt(PaperSize);
/* This should set the preview DC's extents so preview works. It don't work! :(
if (pInfo->m_bPreview) {
CSize PreviewPageSize = PaperSize;
PreviewPageSize.cx = MulDiv(PaperSize.cx, ScreenPixelsPerInch.cx,
PaperPixelsPerInch.cx);
PreviewPageSize.cy = MulDiv(PaperSize.cy, ScreenPixelsPerInch.cy,
PaperPixelsPerInch.cy);
SetWindowExtEx(pDC->m_hAttribDC, LogicalPageSize.cx, LogicalPageSize.cy, NULL);
SetViewportExtEx(pDC->m_hAttribDC, PreviewPageSize.cx, PreviewPageSize.cy, NULL);
}
*/
// Calculate the number of rows per page
m_nRowsPerPage = LogicalPageSize.cy / m_nRowHeight;
m_nRowsPerPage -= (HEADER_HEIGHT+FOOTER_HEIGHT + 2*GAP); // Header and footer
m_nRowsPerPage -= 1; // List control header
int nMaxPage = nMaxRowCount/m_nRowsPerPage + 1;
pInfo->SetMaxPage(nMaxPage);
pInfo->m_nCurPage = 1; // start printing at page# 1
ReleaseDC(pCurrentDC);
pDC->SelectObject(pOldFont);
/* old code
// OnBeginPrinting() is called after the user has committed to
// printing by OK'ing the Print dialog, and after the framework
// has created a CDC object for the printer or the preview view.
// This is the right opportunity to set up the page range.
// Given the CDC object, we can determine how many rows will
// fit on a page, so we can in turn determine how many printed
// pages represent the entire document.
if(NULL == pDC || NULL == pInfo)
return;
int nMaxRowCount = ctlList.GetItemCount();
if(!nMaxRowCount)
return;
//let us do all dimesions in ListControl units (Device) rather than
//printer device units. Since we have more control on them
CDC *pCtlDC = GetDC();
if(NULL == pCtlDC)
return;
TEXTMETRIC tm;
pCtlDC->GetTextMetrics(&tm);
m_nCharWidth = tm.tmAveCharWidth;
pDC->SetMapMode(MM_ANISOTROPIC);
CRect rc;
ctlList.GetItemRect(0, &rc, LVIR_BOUNDS);
m_nRowHeight = rc.Height();
int nMargins = (LEFT_MARGIN+RIGHT_MARGIN)*m_nCharWidth;
//this will optimize the column widths. If we have more column than
//screen width and horizontal scroll on List control
//this will reduce the column widths proportonately to fit all of them
//on the page. If we have fewer column all the column
//widths will increased propertionately.
pDC->SetWindowExt(rc.Width() + nMargins, pCtlDC->GetDeviceCaps(LOGPIXELSX));
pDC->SetViewportExt(pDC->GetDeviceCaps(HORZRES),pDC->GetDeviceCaps(LOGPIXELSX));
double d = (double)pDC->GetDeviceCaps(LOGPIXELSY)/(double)pCtlDC->GetDeviceCaps(LOGPIXELSY);
ReleaseDC(pCtlDC);
nMargins = (int)(m_nRowHeight*d);
int nPageHeight = pDC->GetDeviceCaps(VERTRES);
m_nRowsPerPage = nPageHeight/nMargins; //nMargins reused
m_nRowsPerPage -= (HEADER_HEIGHT+FOOTER_HEIGHT);
m_nRowsPerPage -= 1; //adjustment for list control header
int nMaxPage = nMaxRowCount/m_nRowsPerPage + 1;
pInfo->SetMaxPage(nMaxPage);
pInfo->m_nCurPage = 1; // start printing at page# 1
*/ // old code
// nada
}
void CCB32View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
m_PrinterFont.DeleteObject();
// nada
}
void CCB32View::OnPrint(CDC* pDC, CPrintInfo* pInfo)
void CCB32View::OnFilePrintMerge()
{
CListCtrl& ctlList = (CListCtrl&) GetListCtrl();
if (!pDC || !pInfo) return;
CFont *pOldFont = pDC->SelectObject(&m_PrinterFont);
// Draw as many rows as will fit on the printed page.
// Clip the printed page so that there is no partially shown
// row at the bottom of the page (the same row which will be fully
// shown at the top of the next page).
int nStartRow = 0;
int nEndRow = 0;
int nMaxRowCount = ctlList.GetItemCount();
nStartRow = (pInfo->m_nCurPage - 1)*m_nRowsPerPage;
nEndRow = nStartRow+m_nRowsPerPage;
if(nEndRow > nMaxRowCount)
nEndRow = nMaxRowCount;
pDC->SetWindowOrg(-LEFT_MARGIN*m_nCharWidth, 0);
CRect rcPage(pInfo->m_rectDraw);
// Header
pInfo->m_rectDraw.top = 0;
pInfo->m_rectDraw.left = 0;
pInfo->m_rectDraw.right = rcPage.right - (LEFT_MARGIN+RIGHT_MARGIN)*m_nCharWidth;
pInfo->m_rectDraw.bottom = HEADER_HEIGHT*m_nRowHeight;
PrintHeader(pDC, pInfo);
pDC->OffsetWindowOrg(0, -HEADER_HEIGHT*m_nRowHeight);
// Gap between header and List control heading
pDC->OffsetWindowOrg(0, -GAP*m_nRowHeight);
// Print the header control.
CRect HeaderCtrlrc;
m_headerctrl.GetClientRect(&HeaderCtrlrc);
pInfo->m_rectDraw.bottom = HeaderCtrlrc.Height();
PrintColumnHeadings(pDC, pInfo);
//pDC->OffsetWindowOrg(0, -HeaderCtrlrc.Height());
// Print the list control
DRAWITEMSTRUCT DrawItemStruct;
DrawItemStruct.hDC = pDC->m_hDC;
for(int i = nStartRow; i < nEndRow; i++) {
DrawItemStruct.itemID = i;
DrawItem(&DrawItemStruct);
}
// Footer
pInfo->m_rectDraw.bottom = FOOTER_HEIGHT*m_nRowHeight;
pDC->SetWindowOrg(-LEFT_MARGIN*m_nCharWidth,
-rcPage.bottom + pInfo->m_rectDraw.bottom);
PrintFooter(pDC, pInfo);
// SetWindowOrg back for next page
pDC->SetWindowOrg(0,0);
pDC->SelectObject(pOldFont);
/* old code
if(NULL == pDC || NULL == pInfo)
return;
// Draw as many rows as will fit on the printed page.
// Clip the printed page so that there is no partially shown
// row at the bottom of the page (the same row which will be fully
// shown at the top of the next page).
int nStartRow = 0;
int nEndRow = 0;
int nMaxRowCount = ctlList.GetItemCount();
nStartRow = (pInfo->m_nCurPage - 1)*m_nRowsPerPage;
nEndRow = nStartRow+m_nRowsPerPage;
if(nEndRow > nMaxRowCount)
nEndRow = nMaxRowCount;
//create bold font for header and footer
CFont *pOldFont = NULL;
CFont BoldFont;
LOGFONT lf;
pOldFont = GetFont();
pOldFont->GetLogFont(&lf);
lf.lfWeight = FW_BOLD;
BoldFont.CreateFontIndirect(&lf);
pOldFont = pDC->SelectObject(&BoldFont);
int nPrevBkMode = pDC->SetBkMode(TRANSPARENT);
//print the header
PrintHeader(pDC, pInfo);
//Print the footer
PrintFooter(pDC, pInfo);
pDC->SetBkMode(nPrevBkMode);
pDC->SelectObject(pOldFont);
BoldFont.DeleteObject();
//Set origin to print header and Header control. Keep Y position at 0 to
//print header information
//Change Y position of origin to print List control header
//Adjust the List control origin to start printing after page margins
pDC->SetWindowOrg(-1*(LEFT_MARGIN*m_nCharWidth), -1*HEADER_HEIGHT*m_nRowHeight);
//send a message to Header control to print itsef. There is little scope to improve printing header.
//I have m_HeaderCtrl in my class. If not take by HeaderCtrl = GetDlgItem(0);
m_headerctrl.SendMessage(WM_PAINT, (WPARAM)pDC->m_hDC);
//Chage window position to take care of ListControl Horizontal scrolling.
//if List control is scrolled to left horizontally the above window origin
//will not start painting from first column, instead it starts painting from
//first visible column, because rcBounds etc are will have -ve left value
//Same thing with vertical scrolling also
CRect rcBounds;
ctlList.GetItemRect(nStartRow, &rcBounds, LVIR_BOUNDS);
//offset top margin of rcBounds by ListControl header
CRect rc;
m_headerctrl.GetClientRect(&rc);
rcBounds.OffsetRect(0, -rc.Height());
pDC->OffsetWindowOrg(rcBounds.left, rcBounds.top);
//start printing rows
for(int i = nStartRow; i < nEndRow; i++)
DrawRow(pDC, i);
//SetWindowOrg back for next page
pDC->SetWindowOrg(0,0);
return;
*/ // old code
}
void CCB32View::PrintColumnHeadings(CDC *pDC, CPrintInfo *pInfo)
{
CListCtrl& ctlList = (CListCtrl&) GetListCtrl();
int nColumns = m_headerctrl.GetItemCount();
//int nColumns = GetNumColumns();
//CHeaderCtrl *pHeader = GetHeaderCtrl();
int offset = pDC->GetTextExtent(_T(" "), 1 ).cx;
CFont *pOldFont = pDC->SelectObject(&m_PrinterFont);
// Get the bounds of the header control
CRect rc;
m_headerctrl.GetClientRect(rc);
rc.bottom = m_nRowHeight;
// Setup our HD_ITEM to get text, width and format
TCHAR buf[256];
HD_ITEM hditem;
hditem.mask = HDI_TEXT | HDI_FORMAT | HDI_WIDTH;
hditem.pszText = buf;
hditem.cchTextMax = 255;
rc.right = 0;
for (int i = 0; i < nColumns; i++)
{
// Get the column text and format and width
m_headerctrl.GetItem(i, &hditem);
//pHeader->GetItem(i, &hditem);
rc.left = rc.right;
rc.right += hditem.cxy;
// Workout the justification for the column heading
UINT uFormat = DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER;
if (hditem.fmt & HDF_CENTER) uFormat |= DT_CENTER;
else if( hditem.fmt & HDF_RIGHT) uFormat |= DT_RIGHT;
else uFormat |= DT_LEFT;
// Draw the column heading
CRect rcLabel(rc);
rcLabel.DeflateRect(offset, 0);
pDC->DrawText(buf,-1, rcLabel, uFormat);
}
// Draw a border around the header control
// NOTE: CDC::Rectangle doesn't draw to the edges of the bounding rectangle
CBrush* pOldBrush = (CBrush*) pDC->SelectStockObject(NULL_BRUSH);
CPen* pOldPen = (CPen*) pDC->SelectStockObject(BLACK_PEN);
rc.left = 0; rc.right++; rc.bottom++;
pDC->Rectangle(rc);
pDC->SelectObject(pOldBrush);
pDC->SelectObject(pOldPen);
pDC->SelectObject(pOldFont);
}
void CCB32View::PrintHeader(CDC *pDC, CPrintInfo *pInfo)
{
CRect rc(pInfo->m_rectDraw);
CString sTemp;
CFont BoldFont;
LOGFONT lf;
//create bold font for header and footer
m_PrinterFont.GetLogFont(&lf);
lf.lfWeight = FW_BOLD;
BoldFont.CreateFontIndirect(&lf);
CFont *pNormalFont = pDC->SelectObject(&BoldFont);
int nPrevBkMode = pDC->SetBkMode(TRANSPARENT);
//print App title on top right margin
sTemp.LoadString(AFX_IDS_APP_TITLE);
pDC->DrawText(sTemp, &rc,
DT_RIGHT | DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER);
pDC->SetBkMode(nPrevBkMode);
pDC->SelectObject(pNormalFont);
BoldFont.DeleteObject();
pDC->MoveTo(rc.left, rc.bottom);
pDC->LineTo(rc.right, rc.bottom);
/* old code
CRect rc(pInfo->m_rectDraw);
CString sTemp;
//Print App title
rc.left += LEFT_MARGIN*m_nCharWidth;
rc.right -= RIGHT_MARGIN*m_nCharWidth;
rc.bottom = rc.top+m_nRowHeight;
//print App title on top right margin
sTemp.LoadString(AFX_IDS_APP_TITLE);
pDC->DrawText(sTemp, &rc, DT_RIGHT | DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER);
//print Header. One row for each string
for (int pos = 0; pos<arLabel.GetSize(); pos++)
{
sTemp = arLabel[pos];
pDC->DrawText(sTemp, &rc, DT_LEFT | DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER);
rc.OffsetRect(0, m_nRowHeight);
}
*/ // old code
}
//print footer with a line and date, and page number
void CCB32View::PrintFooter(CDC *pDC, CPrintInfo *pInfo)
{
CRect rc(pInfo->m_rectDraw);
CFont BoldFont;
LOGFONT lf;
//draw line
pDC->MoveTo(rc.left, rc.top);
pDC->LineTo(rc.right, rc.top);
//create bold font for header and footer
m_PrinterFont.GetLogFont(&lf);
lf.lfWeight = FW_BOLD;
BoldFont.CreateFontIndirect(&lf);
CFont *pNormalFont = pDC->SelectObject(&BoldFont);
int nPrevBkMode = pDC->SetBkMode(TRANSPARENT);
//draw page number
CString sTemp ;
rc.OffsetRect(0, m_nRowHeight/2);
sTemp.Format(IDS_PRINT_PAGE_TITLE, pInfo->m_nCurPage, pInfo->GetMaxPage());
pDC->DrawText(sTemp,-1,rc,
DT_LEFT | DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER);
CTime t = CTime::GetCurrentTime();
sTemp = t.Format("%c");
pDC->DrawText(sTemp,-1,rc,
DT_RIGHT | DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER);
pDC->SetBkMode(nPrevBkMode);
pDC->SelectObject(pNormalFont);
BoldFont.DeleteObject();
/* old code
CRect rc(pInfo->m_rectDraw);
//draw line
rc.left += LEFT_MARGIN*m_nCharWidth;
rc.right -= RIGHT_MARGIN*m_nCharWidth;
rc.top = rc.bottom - FOOTER_HEIGHT*m_nRowHeight;
rc.bottom = rc.top + m_nRowHeight;
pDC->MoveTo(rc.left, rc.top);
pDC->LineTo(rc.right, rc.top);
//draw page number
CString sTemp ;
rc.OffsetRect(0, m_nRowHeight/2);
sTemp.Format(IDS_PRINT_PAGE_TITLE, pInfo->m_nCurPage);
pDC->DrawText(sTemp,-1,rc, DT_LEFT | DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER);
CTime t = CTime::GetCurrentTime();
sTemp = t.Format("%c");
pDC->DrawText(sTemp,-1,rc, DT_RIGHT | DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER);
*/ // old code
}
//this is drawing code copied RowList sample and from www.codeguru.com site
int CCB32View::DrawRow(CDC *pDC, int nItem)
{
CListCtrl& ctlList = (CListCtrl&) GetListCtrl();
CImageList *pImageList = NULL;
CFont *pOldFont = NULL;
CFont BoldFont;
CString sLabel;
UINT dtFlags = DT_SINGLELINE|DT_NOPREFIX|DT_VCENTER;
int nSaveDC = pDC->SaveDC();
if(!pDC->IsPrinting())
dtFlags |= (DT_NOCLIP | DT_END_ELLIPSIS); //no clip because we add ellipsis at the end
// get item data
LV_ITEM lvi;
lvi.mask = LVIF_IMAGE | LVIF_STATE | LVIF_INDENT;
lvi.iItem=nItem;
lvi.iSubItem=0;
lvi.stateMask=0xFFFF; // get all state flags
ctlList.GetItem(&lvi);
BOOL bHighlight = ((lvi.state & LVIS_DROPHILITED) || ((lvi.state & LVIS_SELECTED)
&& ((GetFocus() == this) || (GetStyle() & LVS_SHOWSELALWAYS))));
//Get rectangles for painting
CRect rcBounds, rcLabel, rcIcon;
ctlList.GetItemRect(nItem, rcBounds, LVIR_BOUNDS);
ctlList.GetItemRect(nItem, rcLabel, LVIR_LABEL);
ctlList.GetItemRect(nItem, rcIcon, LVIR_ICON);
CRect rcCol(rcBounds);
CRect rcWnd;
sLabel = ctlList.GetItemText(nItem, 0);
//Label offset
int offset = pDC->GetTextExtent(_T(" "), 1).cx;
CRect rcHighlight;
int nExt = 0;
switch(m_nHighlight)
{
case HIGHLIGHT_NORMAL:
nExt = pDC->GetOutputTextExtent(sLabel).cx + offset;
rcHighlight = rcLabel;
if(rcLabel.left + nExt < rcLabel.right)
rcHighlight.right = rcLabel.left + nExt;
break;
case HIGHLIGHT_ALLCOLUMNS:
rcHighlight = rcBounds;
rcHighlight.left = rcLabel.left;
break;
case HIGHLIGHT_ROW:
GetClientRect(&rcWnd);
rcHighlight = rcBounds;
rcHighlight.left = rcLabel.left;
rcHighlight.right = rcWnd.right;
break;
default:
rcHighlight.left = rcLabel.left;
break;
}
//draw highlight. printing may not be required
if(bHighlight)
{
pDC->SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
pDC->SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));
pDC->FillRect(rcHighlight, &CBrush(::GetSysColor(COLOR_HIGHLIGHT)));
}
else {
pDC->SetBkColor(::GetSysColor(COLOR_WINDOW));
pDC->FillRect(rcHighlight, &CBrush(::GetSysColor(COLOR_WINDOW)));
}
//set clip region
rcCol.right = rcCol.left + ctlList.GetColumnWidth(0);
//Nice to have regions but they are not working on printer DC we may need
//to take get device caps to support regions. Does not seems to help much now
//CRgn rgn;
//rgn.CreateRectRgnIndirect(&rcCol);
//pDC->SelectClipRgn(&rgn);
//rgn.DeleteObject();
//Draw state icon
if(lvi.state & LVIS_STATEIMAGEMASK)
{
int nImage = ((lvi.state & LVIS_STATEIMAGEMASK) >> 12) - 1;
pImageList = ctlList.GetImageList(LVSIL_STATE);
//offset the state image icon indent levels.
nExt = rcCol.left + lvi.iIndent*rcIcon.Width(); //nExt reused
if(pImageList)
pImageList->Draw(pDC, nImage, CPoint(nExt, rcCol.top), ILD_TRANSPARENT);
}
//Draw Normal and overlay icon
pImageList = ctlList.GetImageList(LVSIL_SMALL); //assuming printing in report mode only
if(pImageList)
{
UINT nOvlImageMask = lvi.state & LVIS_OVERLAYMASK;
pImageList->Draw(pDC, lvi.iImage, CPoint(rcIcon.left, rcIcon.top),
(bHighlight?ILD_BLEND50:0)|ILD_TRANSPARENT|nOvlImageMask);
}
//if state image mask is on and indent is 0 then consider it as Server row
if((lvi.state & LVIS_STATEIMAGEMASK) && !lvi.iIndent)
{
//create bold font
LOGFONT lf;
pOldFont = GetFont();;
pOldFont->GetLogFont(&lf);
lf.lfWeight = FW_BOLD;
BoldFont.CreateFontIndirect(&lf);
pOldFont = pDC->SelectObject(&BoldFont);
rcLabel.right = rcBounds.right; //draw server name to full row width
}
//Draw item label
rcLabel.left += offset/2;
rcLabel.right -= offset;
dtFlags |= DT_LEFT;
pDC->DrawText(sLabel, rcLabel, dtFlags);
if((lvi.state & LVIS_STATEIMAGEMASK) && !lvi.iIndent)
{
pOldFont = pDC->SelectObject(pOldFont);
BoldFont.DeleteObject();
//focus rect if required
if(lvi.state & LVIS_FOCUSED && (GetFocus() == this))
pDC->DrawFocusRect(rcHighlight);
pDC->RestoreDC(nSaveDC);
return 0;
}
//Draw labels for remaining columns
LV_COLUMN lvc;
lvc.mask = LVCF_FMT|LVCF_WIDTH;
if(m_nHighlight == HIGHLIGHT_NORMAL)
{
pDC->SetTextColor(::GetSysColor(COLOR_WINDOWTEXT));
pDC->SetBkColor(::GetSysColor(COLOR_WINDOW));
}
rcBounds.right = rcHighlight.right > rcBounds.right ? rcHighlight.right:rcBounds.right;
//Nice to have regions but they are not working on printer DC we may need
//to take get device caps to support regions. Does not seems to help much now
//rgn.CreateRectRgnIndirect(&rcBounds);
//pDC->SelectClipRgn(&rgn);
//rgn.DeleteObject();
for(int nColumn = 1; ctlList.GetColumn(nColumn, &lvc); nColumn++)
{
rcCol.left = rcCol.right;
rcCol.right += lvc.cx;
//draw background if needed
if(m_nHighlight == HIGHLIGHT_NORMAL)
pDC->FillRect(rcCol, &CBrush(::GetSysColor(COLOR_WINDOW)));
sLabel = ctlList.GetItemText(nItem, nColumn);
if(sLabel.IsEmpty())
continue;
//Get the text justification
UINT nJustify = DT_LEFT;
switch(lvc.fmt & LVCFMT_JUSTIFYMASK)
{
case LVCFMT_RIGHT:
nJustify = DT_RIGHT;
break;
case LVCFMT_CENTER:
nJustify = DT_CENTER;
break;
default:
break;
CPMerge pmDlg;
if (pmDlg.DoModal() == IDOK) {
CString myTmpl = theApp.GetProfileString(_T("Print"),_T("Template"),NULL);
if (!myTmpl.IsEmpty()) {
CFileStatus fsTest;
CFile tFile;
CString myFile = theApp.m_pszPathToExe + "TMPL\\" + myTmpl;
if (tFile.GetStatus(myFile+".tpl", fsTest) &&
tFile.GetStatus(myFile+".hed", fsTest) &&
tFile.GetStatus(myFile+".bod", fsTest) &&
tFile.GetStatus(myFile+".fot", fsTest)) {
// theMeat.
PrintMerge(myFile);
// Launch?
if (GetPrivateProfileInt("Template","Launch",0, myFile+".tpl")) {
char chTmpOut[_MAX_PATH], chTmpView[_MAX_PATH];
// Output file?
GetPrivateProfileString("Template","Output",NULL,
chTmpOut, sizeof(chTmpOut), myFile+".tpl");
// Viewer?
GetPrivateProfileString("Template","Viewer",NULL,
chTmpView, sizeof(chTmpView), myFile+".tpl");
if (tFile.GetStatus(chTmpOut, fsTest)) {
if (chTmpView[0] == NULL)
ShellExecute(NULL,_T("open"),chTmpOut,NULL,NULL,SW_SHOW);
else
ShellExecute(NULL,_T("open"),chTmpView,chTmpOut,NULL,SW_SHOW);
}
}
} else {
AfxMessageBox(IDS_MISSTMPL, MB_OK | MB_ICONSTOP);
}
}
rcLabel = rcCol;
rcLabel.left += offset;
rcLabel.right -= offset;
dtFlags &= ~DT_RIGHT;
dtFlags &= ~DT_CENTER;
dtFlags |= nJustify;
pDC->DrawText(sLabel, -1, rcLabel, dtFlags);
}
}
BOOL CCB32View::PrintMerge(CString strTemplate)
{
CListCtrl& ctlList = (CListCtrl&) GetListCtrl();
CWaitCursor wait;
CFile iFile;
CFileException e;
CString fileName;
char cBuffer[4096];
// open input body and read contents
fileName.Format("%s", strTemplate + ".bod");
if (!iFile.Open(fileName, CFile::modeRead |
CFile::shareDenyWrite, &e)) {
AfxThrowFileException(e.m_cause, e.m_lOsError, fileName);
return FALSE;
}
UINT uLen = iFile.Read(cBuffer, sizeof(cBuffer));
if (!uLen) {
AfxThrowFileException(e.m_cause, e.m_lOsError, fileName);
iFile.Close();
return FALSE;
}
cBuffer[uLen] = '\0';
iFile.Close();
// open body output for writing
fileName.Empty();
fileName.Format("%s", strTemplate + ".out");
if (!iFile.Open(fileName, CFile::modeCreate | CFile::modeWrite |
CFile::shareDenyWrite, &e)) {
AfxThrowFileException(e.m_cause, e.m_lOsError, fileName);
return FALSE;
}
//focus rect if required
if(lvi.state & LVIS_FOCUSED && (GetFocus() == this))
pDC->DrawFocusRect(rcHighlight);
pDC->RestoreDC(nSaveDC);
return 0;
// parse and write body
CString strBuffer;
CStringArray *pItem;
int iCount = ctlList.GetItemCount();
for(int i=0; i<iCount; i++) {
strBuffer.Format("%s", cBuffer);
pItem = (CStringArray*) ctlList.GetItemData(i);
strBuffer = Sub("@LASTNAME@", pItem->GetAt(0), strBuffer);
strBuffer = Sub("@FIRSTNAME@", pItem->GetAt(1), strBuffer);
strBuffer = Sub("@MIDINIT@", pItem->GetAt(2), strBuffer);
strBuffer = Sub("@TITLE@", pItem->GetAt(3), strBuffer);
strBuffer = Sub("@ADDRESS1@", pItem->GetAt(4), strBuffer);
strBuffer = Sub("@ADDRESS2@", pItem->GetAt(5), strBuffer);
strBuffer = Sub("@CITY@", pItem->GetAt(6), strBuffer);
strBuffer = Sub("@COUNTRY@", pItem->GetAt(7), strBuffer);
strBuffer = Sub("@STATE@", pItem->GetAt(8), strBuffer);
strBuffer = Sub("@ZIPCODE@", pItem->GetAt(9), strBuffer);
strBuffer = Sub("@COMPANY@", pItem->GetAt(10), strBuffer);
strBuffer = Sub("@DEPARTMENT@", pItem->GetAt(11), strBuffer);
strBuffer = Sub("@POSITION@", pItem->GetAt(12), strBuffer);
strBuffer = Sub("@MANAGER@", pItem->GetAt(13), strBuffer);
strBuffer = Sub("@ADDITIONAL1@", pItem->GetAt(14), strBuffer);
strBuffer = Sub("@ADDITIONAL2@", pItem->GetAt(15), strBuffer);
strBuffer = Sub("@HOMEPHONE@", pItem->GetAt(16), strBuffer);
strBuffer = Sub("@HOMEEXT@", pItem->GetAt(17), strBuffer);
strBuffer = Sub("@WORKPHONE@", pItem->GetAt(18), strBuffer);
strBuffer = Sub("@WORKEXT", pItem->GetAt(19), strBuffer);
strBuffer = Sub("@CELLPHONE@", pItem->GetAt(20), strBuffer);
strBuffer = Sub("@CELLEXT@", pItem->GetAt(21), strBuffer);
strBuffer = Sub("@PAGER@", pItem->GetAt(22), strBuffer);
strBuffer = Sub("@PAGERCARD@", pItem->GetAt(23), strBuffer);
strBuffer = Sub("@PAGEREXT@", pItem->GetAt(24), strBuffer);
strBuffer = Sub("@FAXPHONE@", pItem->GetAt(25), strBuffer);
strBuffer = Sub("@FAXEXT@", pItem->GetAt(26), strBuffer);
strBuffer = Sub("@EMAIL1@", pItem->GetAt(27), strBuffer);
strBuffer = Sub("@EMAIL2@", pItem->GetAt(28), strBuffer);
strBuffer = Sub("@WEB1@", pItem->GetAt(29), strBuffer);
strBuffer = Sub("@WEB2@", pItem->GetAt(30), strBuffer);
strBuffer = Sub("@NOTES@", Sub("<p>","\x0d\x0a",
pItem->GetAt(31)), strBuffer);
iFile.Write(strBuffer, strBuffer.GetLength());
}
iFile.Close();
// open output file
char chTmp[_MAX_PATH];
GetPrivateProfileString("Template","Output",strTemplate+".tmp",
chTmp, sizeof(chTmp), strTemplate+".tpl");
fileName.Empty();
fileName.Format("%s", chTmp);
if (!iFile.Open(fileName, CFile::modeCreate | CFile::modeWrite |
CFile::shareDenyWrite, &e)) {
AfxThrowFileException(e.m_cause, e.m_lOsError, fileName);
return FALSE;
}
// read in .hed, .out, .fot and write to .rtf
char *files[3] = {".hed",".out",".fot"};
CFile tFile;
CString tName;
for (int z=0; z<3; z++) {
cBuffer[0] = '\0';
tName.Format("%s", strTemplate + files[z]);
if (!tFile.Open(tName, CFile::modeRead |
CFile::shareDenyWrite, &e)) {
AfxThrowFileException(e.m_cause, e.m_lOsError, fileName);
iFile.Close();
return FALSE;
}
uLen = tFile.Read(cBuffer, sizeof(cBuffer));
while (uLen) {
cBuffer[uLen+1] = '\0';
iFile.Write(cBuffer, uLen);
uLen = tFile.Read(cBuffer, sizeof(cBuffer));
}
tFile.Close();
}
iFile.Close();
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
@ -1409,7 +926,7 @@ BOOL CCB32View::AddDocItemToListView(CExpr* expr)
// Initialize the CStringArray structure's fields.
CString sText;
if(expr->GetAttributeValue("LastName", sText))
if(expr->GetAttributeValue(_T("LastName"), sText))
pItem->SetAt(0, sText);
if(expr->GetAttributeValue("FirstName", sText))
pItem->SetAt(1, sText);
@ -1660,7 +1177,7 @@ int CALLBACK CCB32View::CompareFuncDec (LPARAM lParam1, LPARAM lParam2,
BOOL CCB32View::MakeExpr(CExpr* expr, CStringArray* pItem)
{
expr->AddAttributeValueString("LastName", pItem->GetAt(0));
expr->AddAttributeValueString(_T("LastName"), pItem->GetAt(0));
expr->AddAttributeValueString("FirstName", pItem->GetAt(1));
expr->AddAttributeValueString("MiddleInitial", pItem->GetAt(2));
expr->AddAttributeValueString("Title", pItem->GetAt(3));
@ -1711,7 +1228,7 @@ void CCB32View::MakeDatabase()
// db.ClearDatabase();
for (int i=0; i<iNumItems; i++)
{
CExpr *expr = new CExpr("contact");
CExpr *expr = new CExpr(_T("contact"));
pItem = (CStringArray*) ctlList.GetItemData(i);
MakeExpr(expr, pItem);
db.Append(expr);
@ -1734,7 +1251,7 @@ void CCB32View::AddDatabase()
{
CExpr *expr = (CExpr *)node->Data();
CString strType = expr->Functor();
if (strType == "contact")
if (strType == _T("contact"))
{
if (!AddDocItemToListView (expr))
break;

View file

@ -35,12 +35,6 @@ protected:
int nSortedCol;
BOOL bSortAscending;
int m_nCharWidth;
int m_nRowHeight;
int m_nRowsPerPage;
int m_nHighlight;
CFont m_PrinterFont;
// Operations
public:
void MakeDatabase();
@ -61,7 +55,6 @@ public:
virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnPrint(CDC* pDC, CPrintInfo* pInfo);
//}}AFX_VIRTUAL
// Implementation
@ -95,10 +88,7 @@ protected:
void SaveColPos();
void SetupColumns();
void PrintColumnHeadings(CDC *pDC, CPrintInfo *pInfo);
void PrintHeader(CDC *pDC, CPrintInfo *pInfo);
void PrintFooter(CDC *pDC, CPrintInfo *pInfo);
int DrawRow(CDC *pDC, int nItem);
BOOL PrintMerge(CString strTemplate);
// Generated message map functions
protected:
@ -148,6 +138,7 @@ protected:
afx_msg void OnViewColpos();
afx_msg void OnEntryCopy();
afx_msg void OnUpdateEntryCopy(CCmdUI* pCmdUI);
afx_msg void OnFilePrintMerge();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
void ChangeListCtrlStyle(long lStyle, BOOL bSetBit);

View file

@ -129,13 +129,6 @@ InputPath=.\hlp\CB32.hpj
# Begin Source File
SOURCE=.\CB32.rc
!IF "$(CFG)" == "CB32 - Win32 Release"
!ELSEIF "$(CFG)" == "CB32 - Win32 Debug"
!ENDIF
# End Source File
# Begin Source File
@ -191,6 +184,10 @@ SOURCE=.\Parser.cpp
# End Source File
# Begin Source File
SOURCE=.\PMerge.cpp
# End Source File
# Begin Source File
SOURCE=.\PrefPage.cpp
# End Source File
# Begin Source File
@ -296,6 +293,10 @@ SOURCE=.\Parser.h
# End Source File
# Begin Source File
SOURCE=.\PMerge.h
# End Source File
# Begin Source File
SOURCE=.\PrefPage.h
# End Source File
# Begin Source File

View file

@ -11,6 +11,9 @@ Package=<5>
Package=<4>
{{{
Begin Project Dependency
Project_Dep_Name cexpr
End Project Dependency
}}}
###############################################################################

223
PMerge.cpp Normal file
View file

@ -0,0 +1,223 @@
// PMerge.cpp : implementation file
//
#include "stdafx.h"
#include "cb32.h"
#include "PMerge.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPMerge dialog
CPMerge::CPMerge(CWnd* pParent /*=NULL*/)
: CDialog(CPMerge::IDD, pParent)
{
//{{AFX_DATA_INIT(CPMerge)
m_pmLaunch = FALSE;
//}}AFX_DATA_INIT
}
void CPMerge::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPMerge)
DDX_Control(pDX, IDC_PMLAUNCH, m_cLaunch);
DDX_Control(pDX, IDC_PM_VIEW, m_pmcView);
DDX_Control(pDX, IDC_PM_FILE, m_pmcFile);
DDX_Control(pDX, IDC_PM_EDIT, m_pmcEdit);
DDX_Control(pDX, IDC_PMTEMPLATE, m_pmTemplate);
DDX_Check(pDX, IDC_PMLAUNCH, m_pmLaunch);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPMerge, CDialog)
//{{AFX_MSG_MAP(CPMerge)
ON_CBN_SELCHANGE(IDC_PMTEMPLATE, OnSelchangePmtemplate)
ON_CBN_SELENDOK(IDC_PMTEMPLATE, OnSelendokPmtemplate)
ON_BN_CLICKED(IDC_PMBROW_EDIT, OnPmbrowEdit)
ON_BN_CLICKED(IDC_PMBROW_FILE, OnPmbrowFile)
ON_BN_CLICKED(IDC_PMBROW_VIEW, OnPmbrowView)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPMerge message handlers
BOOL CPMerge::OnInitDialog()
{
CDialog::OnInitDialog();
CString strTpl = theApp.m_pszPathToExe + "TMPL\\*.TPL";
WIN32_FIND_DATA fileData;
HANDLE hFind = FindFirstFile(strTpl, &fileData);
if (hFind != INVALID_HANDLE_VALUE) {
CString szTemp = fileData.cFileName;
szTemp = szTemp.Left(szTemp.ReverseFind('.'));
CString myFile = theApp.m_pszPathToExe + "TMPL\\" + szTemp;
if (TestForTemplate(myFile))
m_pmTemplate.AddString(szTemp);
while (FindNextFile(hFind, &fileData)) {
szTemp = fileData.cFileName;
szTemp = szTemp.Left(szTemp.ReverseFind('.'));
myFile = theApp.m_pszPathToExe + "TMPL\\" + szTemp;
if (TestForTemplate(myFile))
m_pmTemplate.AddString(szTemp);
}
}
FindClose(hFind);
// change to search for last template
strTpl = theApp.GetProfileString(_T("Print"),_T("Template"),NULL);
if (!strTpl.IsEmpty())
m_pmTemplate.SetCurSel(m_pmTemplate.FindString(-1, strTpl));
else
m_pmTemplate.SetCurSel(0);
LoadTemplateData();
return TRUE;
}
void CPMerge::OnOK()
{
if (m_pmTemplate.GetCount() > 0) {
SaveTemplateData();
CString myTmpl;
m_pmTemplate.GetLBText(m_pmTemplate.GetCurSel(),myTmpl);
theApp.WriteProfileString(_T("Print"),_T("Template"),myTmpl);
}
CDialog::OnOK();
}
void CPMerge::LoadTemplateData()
{
if (m_pmTemplate.GetCount() > 0) {
CString myTmpl;
char chTmp[_MAX_PATH];
m_pmTemplate.GetLBText(m_pmTemplate.GetCurSel(),myTmpl);
GetPrivateProfileString("Template","Editor",NULL,chTmp,sizeof(chTmp),
theApp.m_pszPathToExe+"TMPL\\"+ myTmpl+".tpl");
m_pmcEdit.SetWindowText(chTmp);
GetPrivateProfileString("Template","Output",NULL,chTmp,sizeof(chTmp),
theApp.m_pszPathToExe+"TMPL\\"+ myTmpl+".tpl");
m_pmcFile.SetWindowText(chTmp);
GetPrivateProfileString("Template","Viewer",NULL,chTmp,sizeof(chTmp),
theApp.m_pszPathToExe+"TMPL\\"+ myTmpl+".tpl");
m_pmcView.SetWindowText(chTmp);
m_pmLaunch = GetPrivateProfileInt("Template","Launch",0,
theApp.m_pszPathToExe+"TMPL\\"+ myTmpl+".tpl");
m_cLaunch.SetCheck((m_pmLaunch)?1:0);
}
}
void CPMerge::SaveTemplateData()
{
if (m_pmTemplate.GetCount() > 0) {
CString myTmpl;
char chTmp[_MAX_PATH];
m_pmTemplate.GetLBText(m_pmTemplate.GetCurSel(),myTmpl);
UpdateData(TRUE);
m_pmcEdit.GetWindowText(chTmp, sizeof(chTmp));
WritePrivateProfileString("Template","Editor",chTmp,
theApp.m_pszPathToExe+"TMPL\\"+ myTmpl+".tpl");
m_pmcFile.GetWindowText(chTmp, sizeof(chTmp));
WritePrivateProfileString("Template","Output",chTmp,
theApp.m_pszPathToExe+"TMPL\\"+ myTmpl+".tpl");
m_pmcView.GetWindowText(chTmp, sizeof(chTmp));
WritePrivateProfileString("Template","Viewer",chTmp,
theApp.m_pszPathToExe+"TMPL\\"+ myTmpl+".tpl");
sprintf(chTmp,"%d",(m_pmLaunch)?'1':'0');
WritePrivateProfileString("Template","Launch",chTmp,
theApp.m_pszPathToExe+"TMPL\\"+ myTmpl+".tpl");
}
}
BOOL CPMerge::TestForTemplate(CString strTName)
{
CFileStatus fsTest;
CFile tFile;
if (tFile.GetStatus(strTName+".tpl", fsTest) &&
tFile.GetStatus(strTName+".hed", fsTest) &&
tFile.GetStatus(strTName+".bod", fsTest) &&
tFile.GetStatus(strTName+".fot", fsTest))
return TRUE;
else
return FALSE;
}
void CPMerge::OnSelchangePmtemplate()
{
SaveTemplateData();
}
void CPMerge::OnSelendokPmtemplate()
{
LoadTemplateData();
}
void CPMerge::OnPmbrowEdit()
{
CFileDialog FileDlg(TRUE, NULL, NULL,
OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST,
TEXT("All Files (*.*)|*.*||"),
AfxGetMainWnd());
CString strTemp;
strTemp.LoadString(IDS_OFN_EXE);
FileDlg.m_ofn.lpstrTitle = strTemp;
if (FileDlg.DoModal() == IDOK) {
CString fileName = FileDlg.GetPathName();
m_pmcEdit.SetWindowText(fileName);
}
}
void CPMerge::OnPmbrowFile()
{
CFileDialog FileDlg(FALSE, NULL, NULL, OFN_HIDEREADONLY |
OFN_OVERWRITEPROMPT | OFN_NOTESTFILECREATE,
TEXT("All Files (*.*)|*.*||"), AfxGetMainWnd());
CString strTemp;
strTemp.LoadString(IDS_OFN_OUT);
FileDlg.m_ofn.lpstrTitle = strTemp;
if (FileDlg.DoModal() == IDOK) {
CString fileName = FileDlg.GetPathName();
m_pmcFile.SetWindowText(fileName);
}
}
void CPMerge::OnPmbrowView()
{
CFileDialog FileDlg(TRUE, NULL, NULL,
OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST,
TEXT("All Files (*.*)|*.*||"),
AfxGetMainWnd());
CString strTemp;
strTemp.LoadString(IDS_OFN_EXE);
FileDlg.m_ofn.lpstrTitle = strTemp;
if (FileDlg.DoModal() == IDOK) {
CString fileName = FileDlg.GetPathName();
m_pmcView.SetWindowText(fileName);
}
}

60
PMerge.h Normal file
View file

@ -0,0 +1,60 @@
#if !defined(AFX_PMERGE_H__3AC42F52_D7CA_11D1_B01A_000000000000__INCLUDED_)
#define AFX_PMERGE_H__3AC42F52_D7CA_11D1_B01A_000000000000__INCLUDED_
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
// PMerge.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CPMerge dialog
class CPMerge : public CDialog
{
// Construction
public:
CPMerge(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CPMerge)
enum { IDD = IDD_PMERGE };
CButton m_cLaunch;
CEdit m_pmcView;
CEdit m_pmcFile;
CEdit m_pmcEdit;
CComboBox m_pmTemplate;
BOOL m_pmLaunch;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CPMerge)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
void LoadTemplateData();
void SaveTemplateData();
BOOL TestForTemplate(CString strTName);
// Generated message map functions
//{{AFX_MSG(CPMerge)
virtual BOOL OnInitDialog();
virtual void OnOK();
afx_msg void OnSelchangePmtemplate();
afx_msg void OnSelendokPmtemplate();
afx_msg void OnPmbrowEdit();
afx_msg void OnPmbrowFile();
afx_msg void OnPmbrowView();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_PMERGE_H__3AC42F52_D7CA_11D1_B01A_000000000000__INCLUDED_)

View file

@ -23,6 +23,7 @@
#define IDD_FIND 137
#define IDS_COUNTRY 137
#define IDS_STATE 138
#define IDD_PMERGE 138
#define IDD_COLPAGE 139
#define IDS_ZIPCODE 139
#define IDS_COMP 140
@ -71,6 +72,10 @@
#define IDS_COLSAVE 178
#define IDS_POSSAVE 179
#define IDS_PREFS 180
#define IDS_PRN_PAGE_FORMAT 181
#define IDS_MISSTMPL 182
#define IDS_OFN_OUT 183
#define IDS_OFN_EXE 184
#define IDC_FNAME 1000
#define IDC_SETPOS 1000
#define IDC_STATIC1 1001
@ -109,30 +114,43 @@
#define IDC_MYWEB 1012
#define IDC_XFAX 1013
#define IDC_EMAIL2 1013
#define IDC_PMHEAD 1013
#define IDC_XEMAIL2 1014
#define IDC_PAGERC 1014
#define IDC_PMBODY 1014
#define IDC_XWEB1 1015
#define IDC_WEB1 1015
#define IDC_PMFOOT 1015
#define IDC_XWEB2 1016
#define IDC_FAX 1016
#define IDC_PMNEW 1016
#define IDC_MI 1017
#define IDC_XPOSN 1017
#define IDC_PMDELETE 1017
#define IDC_XSTATE 1018
#define IDC_WEB2 1018
#define IDC_PM_FILE 1018
#define IDC_XCELL 1019
#define IDC_CELLULAR 1019
#define IDC_PMBROW_FILE 1019
#define IDC_TITLE 1020
#define IDC_XCOMP 1020
#define IDC_PM_EDIT 1020
#define IDC_XZIP 1021
#define IDC_HPHONEX 1021
#define IDC_PMBROW_EDIT 1021
#define IDC_XCELLX 1022
#define IDC_NOTES 1022
#define IDC_PMTEMPLATE 1022
#define IDC_XFAXX 1023
#define IDC_WPHONEX 1023
#define IDC_PM_VIEW 1023
#define IDC_XEMAIL1 1024
#define IDC_PAGERX 1024
#define IDC_PMBROW_VIEW 1024
#define IDC_XNOTES 1025
#define IDC_FAXX 1025
#define IDC_PMLAUNCH 1025
#define IDC_XDEPT 1026
#define IDC_CELLULARX 1026
#define IDC_XMGR 1027
@ -275,6 +293,7 @@
#define ID_ENTRY_EDIT 32774
#define ID_ENTRY_DELETE 32775
#define ID_ENTRY_COPY 32776
#define ID_FILE_PRINT_MERGE 32780
#define ID_FILE_IMPORT 32803
#define ID_IMPORT_CSV 32804
#define ID_IMPORT_TAB 32805
@ -307,9 +326,9 @@
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_3D_CONTROLS 1
#define _APS_NEXT_RESOURCE_VALUE 137
#define _APS_NEXT_COMMAND_VALUE 32780
#define _APS_NEXT_CONTROL_VALUE 1013
#define _APS_NEXT_RESOURCE_VALUE 139
#define _APS_NEXT_COMMAND_VALUE 32781
#define _APS_NEXT_CONTROL_VALUE 1026
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

View file

@ -19,7 +19,7 @@
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT
#include <afxtempl.h>
//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.