Using VC ++ to develop the printed program obtained

zhaozj2021-02-11  166

The printing method you have learned to explore everyone's welcome, readers have developed their own opinion

The resulting print procedures are not very difficult, as long as the Windows font size and

Solving the work of the onDraw function and the work that should be made in the onprint function can make a more satisfactory program.

The following is the step of the program generated:

(1) Use AppWizard to create a PRT-view. note:

1. CLASS NAME in Classes Select Class Name in Classes

The ViewDoc class is changed to CSONGDOC class, Prtvdoc. H and PRTVDOC. CPP is changed to S, respectively

ONGDOC. H and songdoc. CPP; depending on the VIEW of PRTVVW. H and PRTVVW. CPP respectively

Change to Songvw. H and songvw. CPP (so the purpose is to make the program's readability

Ok, because the content we have to print is a lyrics; in addition, sangvw. CPP base

The class is changed to a CScrollView class with a scroll bar. 2. Select PRIN in Option Selection

Ting and pre -view options.

(2) Use classwizard to join the WM-CREATE message control letter for CSONGVW classes

number.

(3) Open SongDoc. H file, join

PUBLIC:

CStringArray M-SongArray;

(4) Open SongDoc. CPP file, add to the on -NewDocument function

The following sequence:

1 BOOL CSONGDOC :: OnNewDocument ()

2 {

3 if (! Cdocument :: onnewdocument ())

4 returnaf;

5 m-songArray. Setsize (13);

6 m-songArray [0] = "Tell Me How long, Can We go in th

IS WAY

7 m-songArray [1] = "Just to be strong";

8 m-songArray [2] = "We Talk THROUGH THE NIGHT";

9 m-songArray [3] = "But Never Reach the Other Side";

10 m-songArray [4] = "We Fill Our Lives";

11 m-songArray [5] = "When all this we need, We Hold W

Ithin outs ";

12 m-songArray [6] = "WHEN WILL We Find, Our Way Out of The Dark";

13 m-songArray [7] = "chorus:"

14 m-songArray [8] = "We know That";

15 m-songArray [9] = "Love is the power, love is the k

EY ";

16 m-songArray [10] = "Love is The Reason, Reason to B

Elieve ";

17 m-songArray [11] = "Love is the answer, WHEN WERE W

e see ";

18 m-songArray [12] = "Love is the power, love is the

Power, ";

19 Return True;

20 void csongdoc :: Serialize (CARCHIVE & A)

M-SongArray. Serialize (ar):}

(5) Open Songvw. CPP, because we use scroll windows, you must set up

Send the size of the window, the size of the page, etc. Delete the content of the ONLNITIALUPDATE function

. Add to the oncreate function

1 int Csongview :: oncreate (lpcreatestruct lpcreate str

UCT)

2 {if (cscrollview :: oncreate (lpcreatestructure) == -

1)

3 retURN -1;

4 CSIZE TOTALSIZE = CSIZE (11520, 15120);

5 csize pagesize = csize (Totalsize.cx/2, TOTALSIZE.CY

/2);

6 CSIZE LINESIZE = CSIZE (Totalsize.cx/100, TOTALSIZE.

CY / 100);

7 Setscrollsizes (MM-Twips, Totalsize, PageSize, Linsiz

e);

8 return 0;

Add the following blocks in the onDraw function:

1 void csongview :: OnDraw (CDC * PDC) 2 {INT I, J, NHEIGHT

3 char Temp [33];

4 cfont font;

5 TextMetric TM;

6 csongdoc * pdoc = getDocument ();

7 PDC-> Moveto (CPOINT (0, 0));

8 PDC-> LineTo (CPOINT (11505, 0));

9 PDC-> Lineto (CPOINT (11505, -15105);

10 pdc-> lineto (cpoint (0, -15105));

11 PDC-> Lineto (CPOINT (0, 0));

12 // Draw External Frame of Article

13 for (i = 0; i <= 8; i = i 1) {

14 WSPRINTF (TEMP, "% 02d", i);

15 PDC-> Textout (i * 1440, 0, temp);

16 for (i = 0; i <= 10; i )

17 {WSPRINTF (TEMP, "% 02d", i);

18 PDC-> TextOut (0, -i * 1440, temp):}

19 font. CreateFont (-200, 0, 0, 0, 400, False, False,

0, ANSI-CHARSET, OUT-Default-Precis, Clip-Default-Preci

S, Default-Quality, Default-Pitch | FF-Roman, "TIMES NEW

Roman ");

20 cfont * PoldFont = (cfont *) PDC-> SelectObject (& f

Ont);

21 PDC-> GetTextMetrics (& TM); 22 NHEIGHT = Tm. Temheight TM. TMEXTERNALLEADING;

23 j = pdoc-> m-songArray. Getsize ();

24 for (i = 0; i

25 PDC-> Textout (720, -i * NHEIGHT-720, PDOC-> M-SO

NGARRAY [1]);

26}

27 PDC-> SelectObject (PoldFont);

Add the following blocks in the onprepareprinting function:

Bool csongview :: onprepareprinting (CPrintlnfo * PLNF

o)

// Default Preperation

PLNFO-> SetMaxPage (1);

Return doprepareprinting (plnfo);

}

(6) Build This program, run it, you can see this lyrics that only account for one page.

转载请注明原文地址:https://www.9cbs.com/read-4803.html

New Post(0)