Mark Ebden
asked on
Debugging a printing problem
This is driving me crazy. The following code fragment compiles, and works in Windows NT, but when run in Windows 95 it fails. Specifically, the Print dialog box appears, but when I click the button to print, nothing happens! I am simply returned to the main program. Please let me know if you see anything in the code that would not work in Windows 95. If I can solve this before Friday (Sept. 4) afternoon I will raise the point value. Thanks,
Mark.
void CMainFrame::OnPlayersPrint All()
{
int nYear = COleDateTime::GetCurrentTi me().GetYe ar();
int nMonth = COleDateTime::GetCurrentTi me().GetMo nth();
int nDay = COleDateTime::GetCurrentTi me().GetDa y();
// Print the waiting list
CPrintDialog PrtDlg(FALSE, PD_USEDEVMODECOPIES |
PD_PAGENUMS | PD_HIDEPRINTTOFILE | PD_NOSELECTION, this);
PrtDlg.m_pd.nMinPage = 1;
PrtDlg.m_pd.nMaxPage = maxplayers;
PrtDlg.m_pd.nFromPage = 1;
PrtDlg.m_pd.nToPage = 1;
if (PrtDlg.DoModal() == IDOK) {
int b = PrtDlg.m_pd.nFromPage;
int c = PrtDlg.m_pd.nToPage;
CDC PrtDC;
DOCINFO DocInf;
PrtDC.Attach(PrtDlg.GetPri nterDC());
DocInf.cbSize = sizeof(DOCINFO);
DocInf.lpszDocName = "MMHA Database";
DocInf.lpszOutput = NULL;
PrtDC.StartDoc(&DocInf);
while (b <= c) {
PrtDC.StartPage();
{
CFont *OldFntPtr;
LOGFONT LogFnt; // For testing. To see the name of the font obtained.
CFont NewFnt;
char str[300];
// X offset between edge of page and start of print area:
int OffsetX = PrtDC.GetDeviceCaps(PHYSIC ALOFFSETX) ;
// Y offset between edge of page and start of print area:
int OffsetY = PrtDC.GetDeviceCaps(PHYSIC ALOFFSETY) ;
PrtDC.SetMapMode(MM_HIENGL ISH); // map to 0.001 inch.
// Shift coordinates to measure from paper edge rather than printable area:
PrtDC.SetViewportOrg(-Offs etX,-Offse tY);
NewFnt.CreateFont(139,0,0, 0,FW_DONTC ARE,FALSE, FALSE,FALS E,
ANSI_CHARSET,OUT_CHARACTER _PRECIS,CL IP_CHARACT ER_PRECIS,
DEFAULT_QUALITY,VARIABLE_P ITCH | FF_ROMAN,"ARIAL");
/* Note font height is 139/1000 of an inch, or about 10 point.
(1 point is 1/72 of an inch.) */
NewFnt.GetLogFont(&LogFnt) ; // get data on font created for testing.
OldFntPtr = PrtDC.SelectObject(&NewFnt );
sprintf (str, "MMHA Database");
PrtDC.TextOut(1000,-1000, str, strlen(str));
sprintf (str, "%d/%d/%d", nDay, nMonth, nYear);
PrtDC.TextOut(6760,-1000, str, strlen(str));
PrtDC.MoveTo(1000,-1200);
PrtDC.LineTo(7300,-1200);
PrtDC.MoveTo(1000,-1210);
PrtDC.LineTo(7300,-1210);
PrtDC.MoveTo(1000,-9900);
PrtDC.LineTo(7300,-9900);
PrtDC.MoveTo(1000,-9910);
PrtDC.LineTo(7300,-9910);
for (int counter = 1; counter <= 45 && b <= c; counter++)
{
int coord = -counter*170 - 1500;
sprintf (str, "%d. %-15s", b, surname[b]);
PrtDC.TextOut(1010, coord, str, strlen(str));
sprintf (str, "%-15s", firstname[b]);
PrtDC.TextOut(2400, coord, str, strlen(str));
sprintf (str, "%8s", reg_no[b]);
PrtDC.TextOut(3500, coord, str, strlen(str));
sprintf (str, "%-19s", telephone[b]);
PrtDC.TextOut(4100, coord, str, strlen(str));
if (HC[b]) {
sprintf (str, "HC");
PrtDC.TextOut(5350, coord, str, strlen(str));
}
if (AC[b]) {
sprintf (str, "AC");
PrtDC.TextOut(5600, coord, str, strlen(str));
}
if (C[b]) {
sprintf (str, "C");
PrtDC.TextOut(5850, coord, str, strlen(str));
}
if (S[b]) {
sprintf (str, "S");
PrtDC.TextOut(6100, coord, str, strlen(str));
}
if (refund[b] > 0) {
sprintf (str, "Refund: $%6.2f", refund[b]);
PrtDC.TextOut(6400, coord, str, strlen(str));
}
b++;
}
PrtDC.SelectObject(OldFntP tr); // Select back old font.
} // finish page
PrtDC.EndPage();
} // finish printing
PrtDC.EndDoc();
GlobalFree(PrtDlg.m_pd.hDe vMode);
GlobalFree(PrtDlg.m_pd.hDe vNames);
} // end DoModal
}
Mark.
void CMainFrame::OnPlayersPrint
{
int nYear = COleDateTime::GetCurrentTi
int nMonth = COleDateTime::GetCurrentTi
int nDay = COleDateTime::GetCurrentTi
// Print the waiting list
CPrintDialog PrtDlg(FALSE, PD_USEDEVMODECOPIES |
PD_PAGENUMS | PD_HIDEPRINTTOFILE | PD_NOSELECTION, this);
PrtDlg.m_pd.nMinPage = 1;
PrtDlg.m_pd.nMaxPage = maxplayers;
PrtDlg.m_pd.nFromPage = 1;
PrtDlg.m_pd.nToPage = 1;
if (PrtDlg.DoModal() == IDOK) {
int b = PrtDlg.m_pd.nFromPage;
int c = PrtDlg.m_pd.nToPage;
CDC PrtDC;
DOCINFO DocInf;
PrtDC.Attach(PrtDlg.GetPri
DocInf.cbSize = sizeof(DOCINFO);
DocInf.lpszDocName = "MMHA Database";
DocInf.lpszOutput = NULL;
PrtDC.StartDoc(&DocInf);
while (b <= c) {
PrtDC.StartPage();
{
CFont *OldFntPtr;
LOGFONT LogFnt; // For testing. To see the name of the font obtained.
CFont NewFnt;
char str[300];
// X offset between edge of page and start of print area:
int OffsetX = PrtDC.GetDeviceCaps(PHYSIC
// Y offset between edge of page and start of print area:
int OffsetY = PrtDC.GetDeviceCaps(PHYSIC
PrtDC.SetMapMode(MM_HIENGL
// Shift coordinates to measure from paper edge rather than printable area:
PrtDC.SetViewportOrg(-Offs
NewFnt.CreateFont(139,0,0,
ANSI_CHARSET,OUT_CHARACTER
DEFAULT_QUALITY,VARIABLE_P
/* Note font height is 139/1000 of an inch, or about 10 point.
(1 point is 1/72 of an inch.) */
NewFnt.GetLogFont(&LogFnt)
OldFntPtr = PrtDC.SelectObject(&NewFnt
sprintf (str, "MMHA Database");
PrtDC.TextOut(1000,-1000, str, strlen(str));
sprintf (str, "%d/%d/%d", nDay, nMonth, nYear);
PrtDC.TextOut(6760,-1000, str, strlen(str));
PrtDC.MoveTo(1000,-1200);
PrtDC.LineTo(7300,-1200);
PrtDC.MoveTo(1000,-1210);
PrtDC.LineTo(7300,-1210);
PrtDC.MoveTo(1000,-9900);
PrtDC.LineTo(7300,-9900);
PrtDC.MoveTo(1000,-9910);
PrtDC.LineTo(7300,-9910);
for (int counter = 1; counter <= 45 && b <= c; counter++)
{
int coord = -counter*170 - 1500;
sprintf (str, "%d. %-15s", b, surname[b]);
PrtDC.TextOut(1010, coord, str, strlen(str));
sprintf (str, "%-15s", firstname[b]);
PrtDC.TextOut(2400, coord, str, strlen(str));
sprintf (str, "%8s", reg_no[b]);
PrtDC.TextOut(3500, coord, str, strlen(str));
sprintf (str, "%-19s", telephone[b]);
PrtDC.TextOut(4100, coord, str, strlen(str));
if (HC[b]) {
sprintf (str, "HC");
PrtDC.TextOut(5350, coord, str, strlen(str));
}
if (AC[b]) {
sprintf (str, "AC");
PrtDC.TextOut(5600, coord, str, strlen(str));
}
if (C[b]) {
sprintf (str, "C");
PrtDC.TextOut(5850, coord, str, strlen(str));
}
if (S[b]) {
sprintf (str, "S");
PrtDC.TextOut(6100, coord, str, strlen(str));
}
if (refund[b] > 0) {
sprintf (str, "Refund: $%6.2f", refund[b]);
PrtDC.TextOut(6400, coord, str, strlen(str));
}
b++;
}
PrtDC.SelectObject(OldFntP
} // finish page
PrtDC.EndPage();
} // finish printing
PrtDC.EndDoc();
GlobalFree(PrtDlg.m_pd.hDe
GlobalFree(PrtDlg.m_pd.hDe
} // end DoModal
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER