home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 23 / IOPROG_23.ISO / SOFT / VFORM.ZIP / Samples / vfTest / vfTestView.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-10-10  |  6.3 KB  |  239 lines

  1. // -------------------------------------------------------------------------
  2. // Copyright @ 1997 TCK Software, Incorporated
  3. // All Rights Reserved
  4. // -------------------------------------------------------------------------
  5. // vfTestView.cpp : implementation of the CVfTestView class
  6. //
  7.  
  8. #include "stdafx.h"
  9. #include "vfTest.h"
  10.  
  11. #include "vfTestDoc.h"
  12. #include "vfTestView.h"
  13.  
  14. #ifdef _DEBUG
  15. #define new DEBUG_NEW
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19.  
  20. #define IDC_VFORM    100
  21. #define IDC_VFORM2    101
  22.  
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CVfTestView
  25.  
  26. IMPLEMENT_DYNCREATE(CVfTestView, CView)
  27.  
  28. BEGIN_MESSAGE_MAP(CVfTestView, CView)
  29.     //{{AFX_MSG_MAP(CVfTestView)
  30.     ON_WM_CREATE()
  31.     ON_WM_ERASEBKGND()
  32.     ON_WM_SIZE()
  33.     ON_WM_SETFOCUS()
  34.     ON_COMMAND(ID_FILE_PRINT_SCREEN, OnFilePrintScreen)
  35.     ON_COMMAND(ID_FILE_PRINT_ALL, OnFilePrintAll)
  36.     ON_COMMAND(ID_FILE_PRINT_SELECTED, OnFilePrintSelected)
  37.     //}}AFX_MSG_MAP
  38.     // Standard printing commands
  39.     ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
  40.     ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
  41.     ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  42. END_MESSAGE_MAP()
  43.  
  44. /////////////////////////////////////////////////////////////////////////////
  45. // CVfTestView construction/destruction
  46.  
  47. CVfTestView::CVfTestView()
  48. {
  49.     // TODO: add construction code here
  50.  
  51. }
  52.  
  53. CVfTestView::~CVfTestView()
  54. {
  55. }
  56.  
  57. /////////////////////////////////////////////////////////////////////////////
  58. // CVfTestView drawing
  59.  
  60. void CVfTestView::OnDraw(CDC* pDC)
  61. {
  62.     CVfTestDoc* pDoc = GetDocument();
  63.     ASSERT_VALID(pDoc);
  64. }
  65.  
  66. /////////////////////////////////////////////////////////////////////////////
  67. // CVfTestView printing
  68.  
  69. BOOL CVfTestView::OnPreparePrinting(CPrintInfo* pInfo)
  70. {
  71.     return m_vForm.DoPreparePrinting(this, pInfo);
  72.     // return DoPreparePrinting(pInfo);
  73. }
  74.  
  75. void CVfTestView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
  76. {
  77.     // Set the page info again, since the user may have changed the printer since
  78.     // we set it up in OnPreparePrinting
  79.     m_vForm.CalcPageInfo(pDC, pInfo);
  80. }
  81.  
  82. void CVfTestView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  83. {
  84.     // TODO: add cleanup after printing
  85. }
  86.  
  87. /////////////////////////////////////////////////////////////////////////////
  88. // CVfTestView diagnostics
  89.  
  90. #ifdef _DEBUG
  91. void CVfTestView::AssertValid() const
  92. {
  93.     CView::AssertValid();
  94. }
  95.  
  96. void CVfTestView::Dump(CDumpContext& dc) const
  97. {
  98.     CView::Dump(dc);
  99. }
  100.  
  101. CVfTestDoc* CVfTestView::GetDocument() // non-debug version is inline
  102. {
  103.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CVfTestDoc)));
  104.     return (CVfTestDoc*)m_pDocument;
  105. }
  106. #endif //_DEBUG
  107.  
  108. void CVfTestView::ResetPalette()
  109. {
  110.     m_palMsgHandler.DoRealizePalette(TRUE);
  111. }
  112.  
  113. /////////////////////////////////////////////////////////////////////////////
  114. // CVfTestView message handlers
  115.  
  116. int CVfTestView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  117. {
  118.     int rc;
  119.     CRect rect(10, 10, 400, 400);
  120.  
  121.     if (CView::OnCreate(lpCreateStruct) == -1)
  122.         return -1;
  123.  
  124.     m_vForm.SetPalMH(&m_palMsgHandler);
  125.     rc = m_vForm.Create(_T("VForm"), rect, this, IDC_VFORM);
  126.     if(!rc)
  127.         MessageBox(_T("Could not create VForm"), _T("Error")); 
  128.  
  129. /*  ---- Example of creating 2 VForms in same window ---
  130.     m_vForm.Register();
  131.     rc = m_vForm.CreateEx(WS_EX_CLIENTEDGE,
  132.             m_vForm.ClassName(), _T("VForm"),
  133.             WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | WS_TABSTOP | WS_VSCROLL,
  134.             10, 10, 400, 400,
  135.             this->GetSafeHwnd(),(HMENU)IDC_VFORM);
  136.  
  137.  
  138.     rc = m_vForm2.CreateEx(WS_EX_CLIENTEDGE,
  139.             m_vForm.ClassName(), _T("VForm2"),
  140.             WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | WS_TABSTOP | WS_VSCROLL,
  141.             415, 10, 400, 340,
  142.             this->GetSafeHwnd(),(HMENU)IDC_VFORM2);
  143.     if(!rc)
  144.         MessageBox(_T("Could not create form 2"), _T("Error")); 
  145. */
  146.     return 0;
  147. }
  148.  
  149.  
  150. // -------------------------------------------------------------------------
  151. // OnEraseBkgnd - overridden to draw gray background where VForm does not fit
  152. //  on the bottom -> VForm will always be a row heigh multiple + header and
  153. //  footer height.  If the window height is not on one of these multiples, a
  154. //  small area will be displayed below the footer.  
  155. //  This just makes that area gray.
  156. // -------------------------------------------------------------------------
  157. BOOL CVfTestView::OnEraseBkgnd(CDC* pDC) 
  158. {
  159. /*    // --- Only use if using snap resize 
  160.     // --- this will cause flicker when sizing
  161.     CBrush backBrush(GetSysColor(COLOR_3DFACE));
  162.     CBrush* pOldBrush = pDC->SelectObject(&backBrush);
  163.  
  164.     CRect rect;
  165.     pDC->GetClipBox(&rect);     // Erase the area needed
  166.     pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(), PATCOPY);
  167.     pDC->SelectObject(pOldBrush);
  168. */
  169.     return TRUE;    
  170. //    return CView::OnEraseBkgnd(pDC);
  171. }
  172.  
  173. void CVfTestView::OnSize(UINT nType, int cx, int cy) 
  174. {
  175.     CView::OnSize(nType, cx, cy);
  176.     
  177.     m_vForm.ResizeToParent();
  178. }
  179.  
  180. void CVfTestView::OnSetFocus(CWnd* pOldWnd) 
  181. {
  182.     // CView::OnSetFocus(pOldWnd);
  183.     m_vForm.SetFocus();
  184. }
  185.  
  186. void CVfTestView::OnInitialUpdate() 
  187. {
  188.     CView::OnInitialUpdate();
  189.     VBitmap* pBmp = m_vForm.GetBmp();
  190.     if (pBmp) 
  191.     {
  192.         if (!m_palMsgHandler.IsHooked())
  193.             m_palMsgHandler.Install(this, pBmp->GetPalette());
  194.  
  195.         // The following line is required because MFC does not send
  196.         // WM_INITIALUPDATE through normal channels. Only realize in
  197.         // foreground if I have the focus (could be updating all views
  198.         // from OnFontChange)
  199.         m_palMsgHandler.DoRealizePalette(m_hWnd==::GetFocus());
  200.     }    
  201. }
  202.  
  203. BOOL CVfTestView::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) 
  204. {
  205.     // TODO: Add your specialized code here and/or call the base class
  206.     
  207.     return CView::OnNotify(wParam, lParam, pResult);
  208. }
  209.  
  210. void CVfTestView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo) 
  211. {
  212.     CView::OnPrepareDC(pDC, pInfo);
  213.     m_vForm.DoPrepareDC(pDC, pInfo);
  214. }
  215.  
  216. void CVfTestView::OnPrint(CDC* pDC, CPrintInfo* pInfo) 
  217. {
  218.     m_vForm.DoPrint(pDC, pInfo);    
  219.     // CView::OnPrint(pDC, pInfo);
  220. }
  221.  
  222. void CVfTestView::OnFilePrintScreen() 
  223. {
  224.     m_vForm.PrintStyle(VFPRINT_SCREEN);
  225.     CView::OnFilePrintPreview();
  226. }
  227.  
  228. void CVfTestView::OnFilePrintAll() 
  229. {
  230.     m_vForm.PrintStyle(VFPRINT_ALL);
  231.     CView::OnFilePrintPreview();
  232. }
  233.  
  234. void CVfTestView::OnFilePrintSelected() 
  235. {
  236.     m_vForm.PrintStyle(VFPRINT_SELECTED);
  237.     CView::OnFilePrintPreview();    
  238. }
  239.