1 // vtkMFCView.cpp : implementation file
2 //
3 
4 #include "stdafx.h"
5 #include "vtkMFCView.h"
6 #include "vtkMFCDocument.h"
7 #include "resource.h"
8 
9 #include "vtkWindowToImageFilter.h"
10 #include "vtkBMPWriter.h"
11 #include "vtkTIFFWriter.h"
12 #include "vtkPNMWriter.h"
13 
14 #ifdef _DEBUG
15 #define new DEBUG_NEW
16 #undef THIS_FILE
17 static char THIS_FILE[] = __FILE__;
18 #endif
19 
20 
21 /////////////////////////////////////////////////////////////////////////////
22 // vtkMFCView
23 
IMPLEMENT_DYNCREATE(vtkMFCView,CView)24 IMPLEMENT_DYNCREATE(vtkMFCView, CView)
25 
26 vtkMFCView::vtkMFCView()
27 {
28   this->PrintDPI = 100;
29 }
30 
~vtkMFCView()31 vtkMFCView::~vtkMFCView()
32 {
33 }
34 
35 
BEGIN_MESSAGE_MAP(vtkMFCView,CView)36 BEGIN_MESSAGE_MAP(vtkMFCView, CView)
37 	//{{AFX_MSG_MAP(vtkMFCView)
38 	ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
39 	//}}AFX_MSG_MAP
40 END_MESSAGE_MAP()
41 
42 /////////////////////////////////////////////////////////////////////////////
43 // vtkMFCView drawing
44 
45 void vtkMFCView::OnDraw(CDC* pDC)
46 {
47   CDocument* pDoc = GetDocument();
48   // TODO: add draw code here
49 }
50 
51 /////////////////////////////////////////////////////////////////////////////
52 // vtkMFCView diagnostics
53 
54 #ifdef _DEBUG
AssertValid() const55 void vtkMFCView::AssertValid() const
56 {
57 	CView::AssertValid();
58 }
59 
Dump(CDumpContext & dc) const60 void vtkMFCView::Dump(CDumpContext& dc) const
61 {
62 	CView::Dump(dc);
63 }
64 #endif //_DEBUG
65 
66 /////////////////////////////////////////////////////////////////////////////
67 // vtkMFCView message handlers
68 
PreCreateWindow(CREATESTRUCT & cs)69 BOOL vtkMFCView::PreCreateWindow(CREATESTRUCT& cs)
70 {
71   // TODO: Add your specialized code here and/or call the base class
72   //  the CREATESTRUCT cs
73   cs.style |= WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CS_OWNDC;
74   return CView::PreCreateWindow(cs);
75 }
76 
OnPreparePrinting(CPrintInfo * pInfo)77 BOOL vtkMFCView::OnPreparePrinting(CPrintInfo* pInfo)
78 {
79   // TODO: call DoPreparePrinting to invoke the Print dialog box
80   // default preparation
81   pInfo->SetMinPage(1);
82   pInfo->SetMaxPage(1);
83   return DoPreparePrinting(pInfo);
84 }
85 
OnEditCopy()86 void vtkMFCView::OnEditCopy()
87 {
88   // TODO: Add your command handler code here
89   LPBITMAPINFOHEADER  lpbi;       // pointer to BITMAPINFOHEADER
90   DWORD               dwLen;      // size of memory block
91   HANDLE              hDIB = NULL;  // handle to DIB, temp handle
92   vtkWindow *vtkWin = this->GetVTKWindow();
93   int *size = vtkWin->GetSize();
94   int dataWidth = ((size[0]*3+3)/4)*4;
95 
96   if (OpenClipboard())
97     {
98     BeginWaitCursor();
99     EmptyClipboard();
100 
101     dwLen = sizeof(BITMAPINFOHEADER) + dataWidth*size[1];
102     hDIB = ::GlobalAlloc(GHND, dwLen);
103     lpbi = (LPBITMAPINFOHEADER) ::GlobalLock(hDIB);
104 
105     lpbi->biSize = sizeof(BITMAPINFOHEADER);
106     lpbi->biWidth = size[0];
107     lpbi->biHeight = size[1];
108     lpbi->biPlanes = 1;
109     lpbi->biBitCount = 24;
110     lpbi->biCompression = BI_RGB;
111     lpbi->biClrUsed = 0;
112     lpbi->biClrImportant = 0;
113     lpbi->biSizeImage = dataWidth*size[1];
114 
115     this->SetupMemoryRendering(size[0],size[1],
116                                this->GetDC()->GetSafeHdc());
117     vtkWin->Render();
118 
119     memcpy((LPSTR)lpbi + lpbi->biSize,
120            this->GetMemoryData(),dataWidth*size[1]);
121 
122     SetClipboardData (CF_DIB, hDIB);
123     ::GlobalUnlock(hDIB);
124     CloseClipboard();
125     this->ResumeScreenRendering();
126     EndWaitCursor();
127     }
128 }
129 
130