Hallo allemaal,
Ik heb een richedit control en een printfunctie hierbij....
De richedit control heb ik door middel van de charformat structuur voorzien van een (niet standaard) lettertype en dus staat in de cf.szFaceName parameter het huidige lettertype opgeslagen.
Nu heb ik de volgende printfunctie waar mee ik tekst wil uit printen, hierbij wil ik gebruik maken van het zelfde lettertype als in cf.szFaceName. Ik heb al geprobeerd op de volgende manier de font in te stellen:
maar helaas werkt dit niet:S
Een tweede probleem waar ik mee zit is dat ik nadat de te printen tekst geprint is, oneindig veel lege pagina's uit de printer zie rollen, want natuurlijk niet de bedoeling is.
Ik hoop dat er iemand is die hier raad mee weet
BVD, Erik
Dit is mijn printfunctie:
Ik heb een richedit control en een printfunctie hierbij....
De richedit control heb ik door middel van de charformat structuur voorzien van een (niet standaard) lettertype en dus staat in de cf.szFaceName parameter het huidige lettertype opgeslagen.
Nu heb ik de volgende printfunctie waar mee ik tekst wil uit printen, hierbij wil ik gebruik maken van het zelfde lettertype als in cf.szFaceName. Ik heb al geprobeerd op de volgende manier de font in te stellen:
code:
1
2
3
| [b][/b]HFONT hfont = (HFONT)&cf; SetMapMode(pd.hDC, MM_TEXT); SelectObject(pd.hDC, hfont); |
maar helaas werkt dit niet:S
Een tweede probleem waar ik mee zit is dat ik nadat de te printen tekst geprint is, oneindig veel lege pagina's uit de printer zie rollen, want natuurlijk niet de bedoeling is.
Ik hoop dat er iemand is die hier raad mee weet
BVD, Erik
Dit is mijn printfunctie:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
| BOOL Print(HWND hwnd)
{
PRINTDLG pd;
ZeroMemory(&pd, sizeof(PRINTDLG));
// populate it
pd.lStructSize = sizeof(PRINTDLG);
pd.hwndOwner = hwnd;
pd.hDevMode = NULL;
pd.hDevNames = NULL;
pd.Flags = PD_USEDEVMODECOPIESANDCOLLATE | PD_RETURNDC | PD_DISABLEPRINTTOFILE;
pd.nCopies = 1;
pd.nFromPage = 1;
pd.nToPage = 1;
pd.nMinPage = 1;
pd.nMaxPage = 0xFFFF;
// bail out on cancel or error
if (!PrintDlg(&pd)) return FALSE;
FORMATRANGE fr;
int nHorizRes = GetDeviceCaps(pd.hDC, HORZRES),
nVertRes = GetDeviceCaps(pd.hDC, VERTRES),
nLogPixelsX = GetDeviceCaps(pd.hDC, LOGPIXELSX),
nLogPixelsY = GetDeviceCaps(pd.hDC, LOGPIXELSY);
LONG lTextLength; // Length of document.
LONG lTextPrinted; // Amount of document printed.
// Ensure the printer DC is in MM_TEXT mode.
SetMapMode ( pd.hDC, MM_TEXT );
// Rendering to the same DC we are measuring.
ZeroMemory(&fr, sizeof(fr));
fr.hdc = fr.hdcTarget = pd.hDC;
// Set up the page.
fr.rcPage.left = 0;
fr.rcPage.top = 0;
fr.rcPage.right = (nHorizRes/nLogPixelsX) * 1440;
fr.rcPage.bottom = (nVertRes/nLogPixelsY) * 1440;
// Set up 1" margins all around.
fr.rc.left = fr.rcPage.left + 1440; // 1440 TWIPS = 1 inch.
fr.rc.top = fr.rcPage.top + 1440;
fr.rc.right = fr.rcPage.right - 1440;
fr.rc.bottom = fr.rcPage.bottom - 1440;
// Default the range of text to print as the entire document.
fr.chrg.cpMin = 0;
fr.chrg.cpMax = -1;
// Set up the print job (standard printing stuff here).
DOCINFO di;
ZeroMemory(&di, sizeof(di));
di.cbSize = sizeof(DOCINFO);
di.lpszDocName = "Type-in Document";
di.lpszOutput = NULL;
di.fwType = 0;
// Start the document.
StartDoc(pd.hDC, &di);
// Find out real size of document in characters.
lTextLength = SendMessage (hEdit, WM_GETTEXTLENGTH, 0, 0 );
do
{
// Start the page.
StartPage(pd.hDC);
// Print as much text as can fit on a page. The return value is
// the index of the first character on the next page. Using TRUE
// for the wParam parameter causes the text to be printed.
lTextPrinted = SendMessage(hEdit,EM_FORMATRANGE,TRUE,(LPARAM)&fr);
// Print last page.
EndPage(pd.hDC);
// If there is more text to print, adjust the range of characters
// to start printing at the first character of the next page.
if (lTextPrinted < lTextLength)
{
fr.chrg.cpMin = lTextPrinted;
fr.chrg.cpMax = -1;
}
}
while (lTextPrinted < lTextLength);
// Tell the control to release cached information.
SendMessage(hEdit, EM_FORMATRANGE, 0, (LPARAM)NULL);
EndDoc (pd.hDC);
DeleteDC(pd.hDC);
return TRUE;
} |