File: vtkMFCView.cpp

package info (click to toggle)
vtk 5.8.0-17.5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 130,804 kB
  • ctags: 169,145
  • sloc: cpp: 1,129,307; ansic: 708,203; tcl: 48,526; python: 20,878; xml: 6,779; yacc: 4,208; perl: 3,121; java: 2,773; lex: 931; sh: 660; asm: 471; makefile: 301
file content (129 lines) | stat: -rw-r--r-- 3,067 bytes parent folder | download | duplicates (10)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// vtkMFCView.cpp : implementation file
//

#include "stdafx.h"
#include "vtkMFCView.h"
#include "vtkMFCDocument.h"
#include "resource.h"

#include "vtkWindowToImageFilter.h"
#include "vtkBMPWriter.h"
#include "vtkTIFFWriter.h"
#include "vtkPNMWriter.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


/////////////////////////////////////////////////////////////////////////////
// vtkMFCView

IMPLEMENT_DYNCREATE(vtkMFCView, CView)

vtkMFCView::vtkMFCView()
{
  this->PrintDPI = 100;
}

vtkMFCView::~vtkMFCView()
{
}


BEGIN_MESSAGE_MAP(vtkMFCView, CView)
	//{{AFX_MSG_MAP(vtkMFCView)
	ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// vtkMFCView drawing

void vtkMFCView::OnDraw(CDC* pDC)
{
  CDocument* pDoc = GetDocument();
  // TODO: add draw code here
}

/////////////////////////////////////////////////////////////////////////////
// vtkMFCView diagnostics

#ifdef _DEBUG
void vtkMFCView::AssertValid() const
{
	CView::AssertValid();
}

void vtkMFCView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// vtkMFCView message handlers

BOOL vtkMFCView::PreCreateWindow(CREATESTRUCT& cs) 
{
  // TODO: Add your specialized code here and/or call the base class
  //  the CREATESTRUCT cs
  cs.style |= WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CS_OWNDC;
  return CView::PreCreateWindow(cs);
}

BOOL vtkMFCView::OnPreparePrinting(CPrintInfo* pInfo) 
{
  // TODO: call DoPreparePrinting to invoke the Print dialog box
  // default preparation
  pInfo->SetMinPage(1);
  pInfo->SetMaxPage(1);
  return DoPreparePrinting(pInfo);
}

void vtkMFCView::OnEditCopy() 
{
  // TODO: Add your command handler code here
  LPBITMAPINFOHEADER  lpbi;       // pointer to BITMAPINFOHEADER
  DWORD               dwLen;      // size of memory block
  HANDLE              hDIB = NULL;  // handle to DIB, temp handle
  vtkWindow *vtkWin = this->GetVTKWindow();
  int *size = vtkWin->GetSize();
  int dataWidth = ((size[0]*3+3)/4)*4;

  if (OpenClipboard())
    {
    BeginWaitCursor();
    EmptyClipboard();
  
    dwLen = sizeof(BITMAPINFOHEADER) + dataWidth*size[1];
    hDIB = ::GlobalAlloc(GHND, dwLen);
    lpbi = (LPBITMAPINFOHEADER) ::GlobalLock(hDIB);
    
    lpbi->biSize = sizeof(BITMAPINFOHEADER);
    lpbi->biWidth = size[0];
    lpbi->biHeight = size[1];
    lpbi->biPlanes = 1;
    lpbi->biBitCount = 24;
    lpbi->biCompression = BI_RGB;
    lpbi->biClrUsed = 0;
    lpbi->biClrImportant = 0;
    lpbi->biSizeImage = dataWidth*size[1];
    
    this->SetupMemoryRendering(size[0],size[1],
                               this->GetDC()->GetSafeHdc());
    vtkWin->Render();

    memcpy((LPSTR)lpbi + lpbi->biSize,
           this->GetMemoryData(),dataWidth*size[1]);
    
    SetClipboardData (CF_DIB, hDIB);
    ::GlobalUnlock(hDIB);
    CloseClipboard();
    this->ResumeScreenRendering();
    EndWaitCursor();
    }		
}