home *** CD-ROM | disk | FTP | other *** search
/ Supercompiler 1997 / SUPERCOMPILER97.iso / MS_VC.50 / VC / MFC / SRC / BARDLG.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-30  |  3.8 KB  |  157 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1997 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 related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10.  
  11. #include "stdafx.h"
  12. #include "occimpl.h"
  13.  
  14. #ifdef AFX_CORE3_SEG
  15. #pragma code_seg(AFX_CORE3_SEG)
  16. #endif
  17.  
  18. #ifdef _DEBUG
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22.  
  23. #define new DEBUG_NEW
  24.  
  25. CDialogBar::CDialogBar()
  26. {
  27. #ifndef _AFX_NO_OCC_SUPPORT
  28.     m_lpszTemplateName = NULL;
  29.     m_pOccDialogInfo = NULL;
  30. #endif
  31. }
  32.  
  33. CDialogBar::~CDialogBar()
  34. {
  35.     DestroyWindow();    // avoid PostNcDestroy problems
  36. }
  37.  
  38. BOOL CDialogBar::Create(CWnd* pParentWnd, LPCTSTR lpszTemplateName,
  39.     UINT nStyle, UINT nID)
  40. {
  41.     ASSERT(pParentWnd != NULL);
  42.     ASSERT(lpszTemplateName != NULL);
  43.  
  44. #ifdef _DEBUG
  45.     // dialog template must exist and be invisible with WS_CHILD set
  46.     if (!_AfxCheckDialogTemplate(lpszTemplateName, TRUE))
  47.     {
  48.         ASSERT(FALSE);          // invalid dialog template name
  49.         PostNcDestroy();        // cleanup if Create fails too soon
  50.         return FALSE;
  51.     }
  52. #endif //_DEBUG
  53.  
  54.     // allow chance to modify styles
  55.     m_dwStyle = nStyle;
  56.     CREATESTRUCT cs;
  57.     memset(&cs, 0, sizeof(cs));
  58.     cs.lpszClass = _afxWndControlBar;
  59.     cs.style = (DWORD)nStyle | WS_CHILD;
  60.     cs.hMenu = (HMENU)nID;
  61.     cs.hInstance = AfxGetInstanceHandle();
  62.     cs.hwndParent = pParentWnd->GetSafeHwnd();
  63.     if (!PreCreateWindow(cs))
  64.         return FALSE;
  65.  
  66.     // create a modeless dialog
  67.  
  68. #ifndef _AFX_NO_OCC_SUPPORT
  69.     m_lpszTemplateName = lpszTemplateName;
  70. #endif
  71.  
  72.     // initialize common controls
  73.     VERIFY(AfxDeferRegisterClass(AFX_WNDCOMMCTLS_REG));
  74.  
  75.     BOOL bSuccess = CreateDlg(lpszTemplateName, pParentWnd);
  76.  
  77. #ifndef _AFX_NO_OCC_SUPPORT
  78.     m_lpszTemplateName = NULL;
  79. #endif
  80.  
  81.     if (!bSuccess)
  82.         return FALSE;
  83.  
  84.     // dialog template MUST specify that the dialog
  85.     //  is an invisible child window
  86.     SetDlgCtrlID(nID);
  87.     CRect rect;
  88.     GetWindowRect(&rect);
  89.     m_sizeDefault = rect.Size();    // set fixed size
  90.  
  91.     // force WS_CLIPSIBLINGS
  92.     ModifyStyle(0, WS_CLIPSIBLINGS);
  93.  
  94.     if (!ExecuteDlgInit(lpszTemplateName))
  95.         return FALSE;
  96.  
  97.     // force the size to zero - resizing bar will occur later
  98.     SetWindowPos(NULL, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_SHOWWINDOW);
  99.  
  100.     return TRUE;
  101. }
  102.  
  103. CSize CDialogBar::CalcFixedLayout(BOOL bStretch, BOOL bHorz)
  104. {
  105.     if (bStretch) // if not docked stretch to fit
  106.         return CSize(bHorz ? 32767 : m_sizeDefault.cx,
  107.             bHorz ? m_sizeDefault.cy : 32767);
  108.     else
  109.         return m_sizeDefault;
  110. }
  111.  
  112. void CDialogBar::OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler)
  113. {
  114.     UpdateDialogControls(pTarget, bDisableIfNoHndler);
  115. }
  116.  
  117. #ifndef _AFX_NO_OCC_SUPPORT
  118.  
  119. BEGIN_MESSAGE_MAP(CDialogBar, CControlBar)
  120.     ON_MESSAGE(WM_INITDIALOG, HandleInitDialog)
  121. END_MESSAGE_MAP()
  122.  
  123. LRESULT CDialogBar::HandleInitDialog(WPARAM, LPARAM)
  124. {
  125.     Default();  // allow default to initialize first (common dialogs/etc)
  126.  
  127.     // create OLE controls
  128.     COccManager* pOccManager = afxOccManager;
  129.     if ((pOccManager != NULL) && (m_pOccDialogInfo != NULL))
  130.     {
  131.         if (!pOccManager->CreateDlgControls(this, m_lpszTemplateName,
  132.             m_pOccDialogInfo))
  133.         {
  134.             TRACE0("Warning: CreateDlgControls failed during dialog bar init.\n");
  135.             return FALSE;
  136.         }
  137.     }
  138.  
  139.     return TRUE;
  140. }
  141.  
  142. BOOL CDialogBar::SetOccDialogInfo(_AFX_OCC_DIALOG_INFO* pOccDialogInfo)
  143. {
  144.     m_pOccDialogInfo = pOccDialogInfo;
  145.     return TRUE;
  146. }
  147.  
  148. #endif //!_AFX_NO_OCC_SUPPORT
  149.  
  150. #ifdef AFX_INIT_SEG
  151. #pragma code_seg(AFX_INIT_SEG)
  152. #endif
  153.  
  154. IMPLEMENT_DYNAMIC(CDialogBar, CControlBar)
  155.  
  156. ///////////////////////////////////////////////////////////////////////////
  157.