MFC :: OpenGL] ProjectMFCReport 와꾸짜기 (옮김)

심플디 2014.04.25 13:11 조회 수 : 1734

이 프로젝트는 다른 모든 기능을 뒤로 제끼고 단 하나의 기능에 주목한다.
그것은 바로 프린터 출력이다. 공학도라면 보고서가 얼마나 중요한 서류인지 알것이다.

ProjectOpenGL의 모달리스 다이얼로그에서 데이터를 전송하고, 
ProjectMFCReport의 view 클래스는 그 데이터를 받아서 리포트 양식에 맞게 자료를 정리해 두도록 할 것이다.

데이터를 전송하는 것은 ProjectOpenGL의 모달리스 프로젝트에서 설명했으므로
이곳에는 데이터를 받고, 적기적소에 출력하는 모습을 보여줄 것이다.

프샷 찍어야 하는데 너무 길어서 그냥 텍스트를 붙이겠다.
(독자 입장에서는 이것이 더 고마울지도...)

 

// CProjectMFCReportView 메시지처리기

void CProjectMFCReportView::OnDraw(CDC* pDC)

{

        CProjectMFCReportDoc* pDoc = GetDocument();

        ASSERT_VALID(pDoc);

        if (!pDoc)

               return;

 

        int y_Position=0;

 

        if(pDC->IsPrinting())

        {

               pDC->SetMapMode(MM_ISOTROPIC);

               pDC->SetWindowExt(100, 100);

               pDC->SetViewportExt(800, 800);

        }

              

        // Area

               CRect reArea(0, 0, 594, 841);

               SetBkMode(pDC->m_hDC, TRANSPARENT);

              

        // Font List

               CFont ftReport, ftMyNumber, tfTitle, tfInfo, *OldFont;

               ftReport.CreateFont(60, 0, 0, 0,FW_HEAVY,FALSE, FALSE, FALSE,

                                   ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,

                                   DEFAULT_QUALITY,VARIABLE_PITCH | FF_SWISS, _T("Times New Roman"));

               ftMyNumber.CreateFont(13, 0, 0, 0,FW_HEAVY,FALSE, FALSE, FALSE,ANSI_CHARSET,OUT_DEFAULT_PRECIS,

                                   CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,VARIABLE_PITCH | FF_SWISS, _T("Lucida Grande"));

              tfTitle.CreateFont(15, 0, 0, 0,FW_HEAVY,FALSE, FALSE, FALSE,ANSI_CHARSET,OUT_DEFAULT_PRECIS,

                                   CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,VARIABLE_PITCH | FF_SWISS,

                                   _T("Lucida Grande"));

              tfInfo.CreateFont(13, 0, 0, 0,FW_NORMAL,FALSE, FALSE, FALSE,ANSI_CHARSET,OUT_DEFAULT_PRECIS,

                                   CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,VARIABLE_PITCH | FF_SWISS,

                                   _T("Lucida Grande"));

       

        // Rectangle

               int off = 20;

               // pDC->Rectangle(reArea.left, reArea.top, reArea.right, reArea.bottom);

               pDC->Rectangle(reArea.left+off, reArea.top+off, reArea.right-off, reArea.bottom-off);

 

        // REPORT

               y_Position = 25;

 

               TCHAR tcReport[10];

               wsprintf(tcReport, _T("REPORT"));

              

               OldFont = pDC->SelectObject(&ftReport);

               SetTextAlign(pDC->m_hDC, TA_CENTER);

               pDC->TextOutW(reArea.right/2, reArea.top+y_Position, tcReport, lstrlen(tcReport));

               pDC->SelectObject(OldFont);

               SetTextAlign(pDC->m_hDC, TA_LEFT);

 

        // Line 1 : y = 90

               y_Position = 90;

               pDC->MoveTo(reArea.left+55,           reArea.top+y_Position  );

               pDC->LineTo(reArea.right-55,  reArea.top+y_Position);

       

        // Div  :  y = 100 ~ 120

               y_Position = 100;

                       TCHAR tcMyNumber[20], tcDate[20], tcMyText[60], tcMyName[50];

                       CTime Today = CTime::GetCurrentTime();

                       OldFont = pDC->SelectObject(&ftMyNumber);

                       SetTextAlign(pDC->m_hDC, TA_CENTER);

                       SetTextColor(pDC->m_hDC, RGB(100, 100, 100));

                       wsprintf(tcMyNumber, _T("2005 02219"));

                       wsprintf(tcDate, _T("%d.%d.%d, %d:%d"), Today.GetDay(), Today.GetMonth(), Today.GetYear(), Today.GetHour(), Today.GetMinute());

                       wsprintf(tcMyText, _T("%s // %s"), tcMyNumber, tcDate);

                       pDC->TextOutW(reArea.right/2, reArea.top+y_Position, tcMyText, lstrlen(tcMyText));

               y_Position+=20;

                       wsprintf(tcMyName, _T("D.S Shin"));

                       pDC->TextOutW(reArea.right/2, reArea.top+y_Position, tcMyName, lstrlen(tcMyName));

                       pDC->SelectObject(OldFont);

                       SetTextAlign(pDC->m_hDC, TA_LEFT);

              

        // Line 2

               y_Position+=20;

                       pDC->MoveTo(reArea.left+55,                  reArea.top+y_Position);

                       pDC->LineTo(reArea.right-55,          reArea.top+y_Position);

              

        // FILE title

               y_Position+=20;

                       TCHAR tcFileTitle[20];

                       OldFont = pDC->SelectObject(&tfTitle);

                       SetTextColor(pDC->m_hDC, RGB(0, 0, 0));

                       wsprintf(tcFileTitle, _T("FILE") );

                       pDC->TextOutW(reArea.left + 55, 160, tcFileTitle, lstrlen(tcFileTitle));

                       pDC->SelectObject(OldFont);

              

        // FILE info

               y_Position+=25;

                       TCHAR tcPath[500], tcName[200], tcExtention[200];

                       OldFont = pDC->SelectObject(&tfInfo);

                       SetTextColor(pDC->m_hDC, RGB(0, 0, 0));

                       wsprintf(tcPath, _T("Path : ") );

                       wsprintf(tcName, _T("Name : "));

                       wsprintf(tcExtention, _T("Extention : "));

                       pDC->TextOutW(reArea.left + 80, y_Position, tcPath, lstrlen(tcPath));

               y_Position+=25;

                       pDC->TextOutW(reArea.left + 80, y_Position, tcName, lstrlen(tcName));

               y_Position+=25;

                       pDC->TextOutW(reArea.left + 80, y_Position, tcExtention, lstrlen(tcExtention));

                       pDC->SelectObject(OldFont);

              

        // DATA title : y = 300

               y_Position+=40;

               TCHAR tcDataTitle[20];

               OldFont = pDC->SelectObject(&tfTitle);

               SetTextColor(pDC->m_hDC, RGB(0, 0, 0));

               wsprintf(tcDataTitle, _T("DATA") );

               pDC->TextOutW(reArea.left + 55, y_Position, tcDataTitle, lstrlen(tcDataTitle));

               pDC->SelectObject(OldFont);

       

        // DATA info : y = 330

               y_Position+=25;

                       TCHAR tcPoint[50], tcUV[50],

                              tcMax[50], tcMin[50],

                              tcSize[50],    tcMesh[50], tcFlag[50],

                               tcModified[100];

                       OldFont = pDC->SelectObject(&tfInfo);

                       SetTextColor(pDC->m_hDC, RGB(0, 0, 0));

                       wsprintf(tcPoint, _T("Point : ") );

                       wsprintf(tcUV, _T("U, V : "));

                       wsprintf(tcMax, _T("Max : "));

                       wsprintf(tcMin, _T("Min : "));

                       wsprintf(tcSize, _T("Size : "));

                       wsprintf(tcMesh, _T("Mesh : "));

                       wsprintf(tcFlag, _T("Flag : "));

                       wsprintf(tcModified, _T("Modified Mesh : "));

                       pDC->TextOutW(reArea.left + 80, y_Position, tcPoint, lstrlen(tcPoint));

               y_Position+=25;

                       pDC->TextOutW(reArea.left + 80, y_Position, tcUV, lstrlen(tcUV));

               y_Position+=25;

                       pDC->TextOutW(reArea.left + 80, y_Position, tcMax, lstrlen(tcMax));

               y_Position+=25;

                       pDC->TextOutW(reArea.left + 80, y_Position, tcMin, lstrlen(tcMin));

               y_Position+=25;

                       pDC->TextOutW(reArea.left + 80, y_Position, tcSize, lstrlen(tcSize));

               y_Position+=25;

                       pDC->TextOutW(reArea.left + 80, y_Position, tcMesh, lstrlen(tcMesh));

               y_Position+=25;

                       pDC->TextOutW(reArea.left + 80, y_Position, tcFlag, lstrlen(tcFlag));

               y_Position+=25;

                       pDC->TextOutW(reArea.left + 80, y_Position, tcModified, lstrlen(tcModified));

               pDC->SelectObject(OldFont);

              

        // REVISION title : y = 560

               y_Position+=40;

                       TCHAR tcRevisionTitle[20];

                       OldFont = pDC->SelectObject(&tfTitle);

                       SetTextColor(pDC->m_hDC, RGB(0, 0, 0));

                       wsprintf(tcRevisionTitle, _T("REVISION") );

                       pDC->TextOutW(reArea.left + 55, y_Position, tcRevisionTitle, lstrlen(tcRevisionTitle));

                       pDC->SelectObject(OldFont);

       

        // REVISION info : y = 590

               y_Position+=25;

                       TCHAR tcTranslate[200], tcRotate[200];

                       OldFont = pDC->SelectObject(&tfInfo);

                       SetTextColor(pDC->m_hDC, RGB(0, 0, 0));

                       wsprintf(tcTranslate, _T("Translate : ") );

                       wsprintf(tcRotate, _T("Rotate : "));

                       pDC->TextOutW(reArea.left + 80, y_Position, tcTranslate, lstrlen(tcTranslate));

               y_Position+=25;

                       pDC->TextOutW(reArea.left + 80, y_Position, tcRotate, lstrlen(tcRotate));

                       pDC->SelectObject(OldFont);

       

        // Set-Value title : y = 630

               y_Position+=40;

                       TCHAR tcSetValue[20];

                       TCHAR tcColor[20];

                       OldFont = pDC->SelectObject(&tfTitle);

                       SetTextColor(pDC->m_hDC, RGB(0, 0, 0));

                       wsprintf(tcSetValue, _T("Set-Value") );

                       wsprintf(tcColor, _T("Color"));

                       pDC->TextOutW(reArea.left + 55, y_Position, tcSetValue, lstrlen(tcSetValue));

                       pDC->TextOutW(reArea.right/2 + 25,    y_Position, tcColor, lstrlen(tcColor));

                       pDC->SelectObject(OldFont);

 

        // Set-Value info : y = 660

               y_Position+=25;

                       TCHAR   tcMeshType[50], tcMeshVector[50], tcClipping[50], tcPerspective[50], tcLightPosition[50],

                                      tcPointColor[50], tcMeshColor[50], tcFaceColor[50], tcLightColor[50], tcBackgroundColor[50];

                       OldFont = pDC->SelectObject(&tfInfo);

                       SetTextColor(pDC->m_hDC, RGB(0, 0, 0));

                      

                       wsprintf(tcMeshType, _T("Mesh type : ") );

                       wsprintf(tcMeshVector, _T("Mesh vector : "));

                       wsprintf(tcClipping, _T("Clipping : "));

                       wsprintf(tcPerspective, _T("Perspective : "));

                       wsprintf(tcLightPosition, _T("Light position : "));

                       wsprintf(tcPointColor, _T("Point color : "));

                       wsprintf(tcMeshColor, _T("Mesh color : "));

                       wsprintf(tcFaceColor, _T("Face color : "));

                       wsprintf(tcLightColor, _T("Light color : "));

                       wsprintf(tcBackgroundColor, _T("Background color : "));

 

                       pDC->TextOutW(reArea.left + 80, y_Position, tcMeshType, lstrlen(tcMeshType));

                       pDC->TextOutW(reArea.right/2 + 50, y_Position, tcPointColor, lstrlen(tcPointColor));

               y_Position+=25;

                       pDC->TextOutW(reArea.left + 80, y_Position, tcMeshVector, lstrlen(tcMeshVector));

                       pDC->TextOutW(reArea.right/2 + 50, y_Position, tcMeshColor, lstrlen(tcMeshColor));

               y_Position+=25;

                       pDC->TextOutW(reArea.left + 80, y_Position, tcClipping, lstrlen(tcClipping));

                       pDC->TextOutW(reArea.right/2 + 50, y_Position, tcFaceColor, lstrlen(tcFaceColor));

               y_Position+=25;

                       pDC->TextOutW(reArea.left + 80, y_Position, tcPerspective, lstrlen(tcPerspective));

                       pDC->TextOutW(reArea.right/2 + 50, y_Position, tcLightColor, lstrlen(tcLightColor));

               y_Position+=25;

                       pDC->TextOutW(reArea.left + 80, y_Position, tcLightPosition, lstrlen(tcLightPosition));

                       pDC->TextOutW(reArea.right/2 + 50, y_Position, tcBackgroundColor, lstrlen(tcBackgroundColor));

                       pDC->SelectObject(OldFont);

              

        // Line 3

               pDC->MoveTo(reArea.left+55,           reArea.bottom-80);

               pDC->LineTo(reArea.right-55,  reArea.bottom-80);

              

        // Div...

               OldFont = pDC->SelectObject(&ftMyNumber);

               TCHAR tcMecha[128];

               SetTextAlign(pDC->m_hDC, TA_CENTER);

               SetTextColor(pDC->m_hDC, RGB(100, 100, 100));

               wsprintf(tcMecha, _T("Div. Of Mechanical and auto motive Engineering Kong-ju National University"));

               pDC->TextOutW(reArea.right/2, reArea.bottom-70, tcMecha, lstrlen(tcMecha));

               SetTextAlign(pDC->m_hDC, TA_LEFT);

               pDC->SelectObject(OldFont);

}





코드를 보면 알겠지만, y축 거리를 내려오면서 단계적으로 텍스트를 출력하고 있음을 알 수 있다.

이 중에서, 아래와 같은 코드가 가장 중요한 위치를 차지한다.





if(pDC->IsPrinting())

{

pDC->SetMapMode(MM_ISOTROPIC);

pDC->SetWindowExt(100, 100);

pDC->SetViewportExt(800, 800);

}



<그림 1 :: Report 양식>

 

<그림 1>은 필자가 초기에 구상했던 '출력용' 리포트 양식(hwp 작성)이다.

물론 구성 변수들이 지금과는 많이 다르지만, 아무튼 이런 양식을 따르기로 마음 먹은 것은 변하지 않았다.


그런데 만약 if(pDC->IsPrinting()) { (생략) } 의 코드를 넣지 않는다면, 인쇄 미리보기에서 <그림 2>와 같은 모습을 볼 수 있다.


 <그림 2 :: 뭥미>


 <그림 3 :: if문 적용한 인쇄 미리보기>


하지만 if문을 적용했다면 <그림 3>과 같이 바뀐 모습을 볼 수 있다.

매핑(mapping)기술이 들어간 것인데 자세한 것은 MFC 서적을 참고할 수 있기를 바란다.

개인적으로 필자는 Visual C++2008 MFC 윈도우 프로그래밍, 최호성, 프리렉  서적을 구입하여 참고했다.

(쿠폰 긁어놓고 동영상 강의를 제대로 보지 않아서 아깝다...)


이 정도 기초 틀을 다져놓았다면 아래와 같은 데이터 타입을 만들어주자.



<그림 4 :: 리포트 데이터>


ProjectOpenGL 에 포함했던 데이터 타입과 똑같아야 한다.

일단 이 프로젝트도 여기까지다.

번호 제목 글쓴이 날짜 조회 수
공지 본 게시글의 첨부파일 권한 심플디 2014.08.22 2401
47 [MFC :: OpenGL] 컴공 수업 발표 자료 (옮김) [2] 심플디 2014.04.25 2899
46 [MFC :: OpenGL] Project 시즌 2 후기 (옮김) 심플디 2014.04.25 1585
45 [MFC :: OpenGL] File output (옮김) 심플디 2014.04.25 1519
44 [MFC :: OpenGL] Tool bar(툴바) 편집방법 (옮김) 심플디 2014.04.25 1840
43 [MFC :: OpenGL] IntroPage (옮김) file 심플디 2014.04.25 1518
42 [MFC :: OpenGL] IPC 적용 (옮김) file 심플디 2014.04.25 1574
» MFC :: OpenGL] ProjectMFCReport 와꾸짜기 (옮김) 심플디 2014.04.25 1734
40 [MFC :: OpenGL] Data Dialog 와꾸짜기 (옮김) 심플디 2014.04.25 1728
39 [MFC :: OpenGL] 시즌 2 개요 (옮김) file 심플디 2014.04.25 1515
38 [MFC :: OpenGL] Project 시즌 2 시작 (옮김) [1] 심플디 2014.04.25 1522
37 [MFC :: OpenGL] Project 시즌 1 후기 (옮김) file 심플디 2014.04.25 1584
36 [MFC :: OpenGL] Mesh :: Part 2 (옮김) [1] file 심플디 2014.04.25 1551
35 [MFC :: OpenGL] Mesh :: Part 1 (옮김) file 심플디 2014.04.25 1600
34 [MFC :: OpenGL] DXF :: Part 5 (옮김) file 심플디 2014.04.25 1592
33 [MFC :: OpenGL] DXF :: Part 4 (옮김) file 심플디 2014.04.25 1490
32 [MFC :: OpenGL] DXF :: Part 3 (옮김) file 심플디 2014.04.25 1466
31 [MFC :: OpenGL] DXF :: Part 2 (옮김) file 심플디 2014.04.25 1523
30 [MFC :: OpenGL] DXF :: Part 1 (옮김) file 심플디 2014.04.25 1566
29 [MFC :: OpenGL] Proposal 및 앞으로의 계획 (옮김) 심플디 2014.04.25 1557