home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c480 / 19.ddi / MFC / SRC / VIEWFORM.CP_ / VIEWFORM.CP
Encoding:
Text File  |  1993-02-08  |  5.2 KB  |  200 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library. 
  2. // Copyright (C) 1992 Microsoft Corporation 
  3. // All rights reserved. 
  4. //  
  5. // This source code is only intended as a supplement to the 
  6. // Microsoft Foundation Classes Reference and Microsoft 
  7. // QuickHelp and/or WinHelp documentation provided with the library. 
  8. // See these sources for detailed information regarding the 
  9. // Microsoft Foundation Classes product. 
  10.  
  11.  
  12. #include "stdafx.h"
  13.  
  14. #ifdef AFX_CORE2_SEG
  15. #pragma code_seg(AFX_CORE2_SEG)
  16. #endif
  17.  
  18. #ifdef _DEBUG
  19. #undef THIS_FILE
  20. static char BASED_CODE THIS_FILE[] = __FILE__;
  21. #define new DEBUG_NEW
  22. #endif
  23.  
  24. /////////////////////////////////////////////////////////////////////////////
  25.  
  26. IMPLEMENT_DYNAMIC(CFormView, CScrollView)
  27.  
  28. BEGIN_MESSAGE_MAP(CFormView, CScrollView)
  29.     //{{AFX_MSG_MAP(CFormView)
  30.     ON_WM_CREATE()
  31.     //}}AFX_MSG_MAP
  32. END_MESSAGE_MAP()
  33.  
  34. CFormView::CFormView(LPCSTR lpszTemplateName)
  35. {
  36.     m_lpszTemplateName = lpszTemplateName;
  37.     m_pCreateContext = NULL;
  38. }
  39.  
  40. CFormView::CFormView(UINT nIDTemplate)
  41. {
  42.     ASSERT_VALID_IDR(nIDTemplate);
  43.     m_lpszTemplateName = MAKEINTRESOURCE(nIDTemplate);
  44.     m_pCreateContext = NULL;
  45. }
  46.  
  47. // virtual override of CWnd::Create
  48. BOOL CFormView::Create(LPCSTR /*lpszClassName ignored*/,
  49.     LPCSTR /*lpszWindowName ignored*/, DWORD dwRequestedStyle,
  50.     const RECT& rect, CWnd* pParentWnd, UINT nID,
  51.     CCreateContext* pContext)
  52. {
  53.     ASSERT(pParentWnd != NULL);
  54.     ASSERT(m_lpszTemplateName != NULL);
  55.  
  56.     m_pCreateContext = pContext;    // save state for later OnCreate
  57.  
  58. #ifdef _DEBUG
  59.     // dialog template must exist and be invisible with WS_CHILD set
  60.     if (!_AfxCheckDialogTemplate(m_lpszTemplateName, TRUE))
  61.     {
  62.         ASSERT(FALSE);          // invalid dialog template name
  63.         PostNcDestroy();        // cleanup if Create fails too soon
  64.         return FALSE;
  65.     }
  66. #endif //_DEBUG
  67.  
  68. #ifndef _AFXDLL
  69.     HINSTANCE hInst = AfxGetResourceHandle();
  70. #else
  71.     HINSTANCE hInst = AfxFindResourceHandle(m_lpszTemplateName, RT_DIALOG);
  72. #endif
  73.  
  74.     _AfxHookWindowCreate(this);
  75.     HWND hWnd = ::CreateDialog(hInst, m_lpszTemplateName,
  76.             pParentWnd->GetSafeHwnd(), NULL);
  77.     if (!_AfxUnhookWindowCreate())
  78.         PostNcDestroy();        // cleanup if Create fails too soon
  79.  
  80.     if (hWnd == NULL)
  81.         return FALSE;
  82.  
  83.     ASSERT(hWnd == m_hWnd);
  84.     m_pCreateContext = NULL;
  85.  
  86.     // we use the style from the template - but make sure that
  87.     //  the WS_BORDER bit is correct
  88.     DWORD dwStyle = GetStyle();
  89.     if ((dwStyle & WS_BORDER) != (dwRequestedStyle & WS_BORDER))
  90.     {
  91.         // toggle WS_BORDER on invisible window
  92.         ::SetWindowLong(m_hWnd, GWL_STYLE, dwStyle ^ WS_BORDER);
  93.     }
  94.  
  95.     _AfxSetDlgCtrlID(m_hWnd, nID);
  96.  
  97.     CRect rectTemplate;
  98.     GetWindowRect(rectTemplate);
  99.     SetScrollSizes(MM_TEXT, rectTemplate.Size());
  100.  
  101.     // initialize VBX controls etc
  102.     if (!ExecuteDlgInit(m_lpszTemplateName))
  103.         return FALSE;
  104.  
  105.     // force the size requested
  106.     SetWindowPos(NULL, rect.left, rect.top,
  107.         rect.right - rect.left, rect.bottom - rect.top,
  108.         SWP_NOZORDER|SWP_NOACTIVATE);
  109.  
  110.     // make visible if requested
  111.     if (dwRequestedStyle & WS_VISIBLE)
  112.         ShowWindow(SW_NORMAL);
  113.  
  114.     return TRUE;
  115. }
  116.  
  117. void CFormView::OnInitialUpdate()
  118. {
  119.     ASSERT_VALID(this);
  120.  
  121.     if (!UpdateData(FALSE))
  122.         TRACE0("UpdateData failed during formview initial update\n");
  123.     CScrollView::OnInitialUpdate();
  124. }
  125.  
  126. int CFormView::OnCreate(LPCREATESTRUCT lpcs)
  127. {
  128.     // since we can't get the create context parameter passed in
  129.     //  through CreateDialog, we use a temporary member variable
  130.     lpcs->lpCreateParams = (LPSTR)m_pCreateContext;
  131.     return CScrollView::OnCreate(lpcs);
  132. }
  133.  
  134. BOOL CFormView::PreTranslateMessage(MSG* pMsg)
  135. {
  136.     ASSERT(pMsg != NULL);
  137.     ASSERT_VALID(this);
  138.     ASSERT(m_hWnd != NULL);
  139.  
  140.     // don't translate dialog messages when in Shift+F1 help mode
  141.     if (AfxGetApp()->m_bHelpMode)
  142.         return FALSE;
  143.  
  144.     // since 'IsDialogMessage' will eat frame window accelerators,
  145.     //   we call the frame window's PreTranslateMessage first
  146.     CWnd* pFrame;
  147.     if ((pFrame = GetParentFrame()) != NULL)
  148.     {
  149.         if (pFrame->PreTranslateMessage(pMsg))
  150.             return TRUE;        // eaten by frame accelerator
  151.         // check for parent of the frame in case of MDI
  152.         if ((pFrame = pFrame->GetParentFrame()) != NULL &&
  153.           pFrame->PreTranslateMessage(pMsg))
  154.             return TRUE;        // eaten by frame accelerator
  155.     }
  156.  
  157.     // filter both messages to dialog and from children
  158.     return ::IsDialogMessage(m_hWnd, pMsg);
  159. }
  160.  
  161.  
  162. void CFormView::OnDraw(CDC* pDC)
  163. {
  164.     ASSERT_VALID(this);
  165.  
  166.     // do nothing - dialog controls will paint themselves,
  167.     //   and Windows dialog controls do not support printing
  168.     if (pDC->IsPrinting())
  169.         TRACE0("Warning: CFormView does not support printing\n");
  170. }
  171.  
  172. WNDPROC* CFormView::GetSuperWndProcAddr()
  173. {
  174.     static WNDPROC NEAR pfnSuper;
  175.     return &pfnSuper;
  176. }
  177.  
  178. //////////////////////////////////////////////////////////////////////////
  179. // CFormView diagnostics
  180.  
  181. #ifdef _DEBUG
  182. void CFormView::Dump(CDumpContext& dc) const
  183. {
  184.     ASSERT_VALID(this);
  185.     CView::Dump(dc);
  186.     AFX_DUMP0(dc, "\nm_lpszTemplateName = ");
  187.     if (HIWORD(m_lpszTemplateName) == 0)
  188.         dc << (int)LOWORD(m_lpszTemplateName);
  189.     else
  190.         dc << m_lpszTemplateName;
  191. }
  192.  
  193. void CFormView::AssertValid() const
  194. {
  195.     CView::AssertValid();
  196. }
  197. #endif
  198.  
  199. //////////////////////////////////////////////////////////////////////////
  200.