home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / mfc / src / bardlg.cpp < prev    next >
C/C++ Source or Header  |  1998-06-16  |  4KB  |  160 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 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 & CBRS_ALL);
  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.     AfxDeferRegisterClass(AFX_WNDCOMMCTLSNEW_REG);
  75.  
  76.     BOOL bSuccess = CreateDlg(lpszTemplateName, pParentWnd);
  77.  
  78. #ifndef _AFX_NO_OCC_SUPPORT
  79.     m_lpszTemplateName = NULL;
  80. #endif
  81.  
  82.     if (!bSuccess)
  83.         return FALSE;
  84.  
  85.     // dialog template MUST specify that the dialog
  86.     //  is an invisible child window
  87.     SetDlgCtrlID(nID);
  88.     CRect rect;
  89.     GetWindowRect(&rect);
  90.     m_sizeDefault = rect.Size();    // set fixed size
  91.  
  92.     // force WS_CLIPSIBLINGS
  93.     ModifyStyle(0, WS_CLIPSIBLINGS);
  94.  
  95.     if (!ExecuteDlgInit(lpszTemplateName))
  96.         return FALSE;
  97.  
  98.     // force the size to zero - resizing bar will occur later
  99.     SetWindowPos(NULL, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE|SWP_SHOWWINDOW);
  100.  
  101.     return TRUE;
  102. }
  103.  
  104. CSize CDialogBar::CalcFixedLayout(BOOL bStretch, BOOL bHorz)
  105. {
  106.     if (bStretch) // if not docked stretch to fit
  107.         return CSize(bHorz ? 32767 : m_sizeDefault.cx,
  108.             bHorz ? m_sizeDefault.cy : 32767);
  109.     else
  110.         return m_sizeDefault;
  111. }
  112.  
  113. void CDialogBar::OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler)
  114. {
  115.     UpdateDialogControls(pTarget, bDisableIfNoHndler);
  116. }
  117.  
  118. #ifndef _AFX_NO_OCC_SUPPORT
  119.  
  120. //{{AFX_MSG_MAP(CDialogBar)
  121. BEGIN_MESSAGE_MAP(CDialogBar, CControlBar)
  122.     ON_MESSAGE(WM_INITDIALOG, HandleInitDialog)
  123. END_MESSAGE_MAP()
  124. //}}AFX_MSG_MAP
  125.  
  126. LRESULT CDialogBar::HandleInitDialog(WPARAM, LPARAM)
  127. {
  128.     Default();  // allow default to initialize first (common dialogs/etc)
  129.  
  130.     // create OLE controls
  131.     COccManager* pOccManager = afxOccManager;
  132.     if ((pOccManager != NULL) && (m_pOccDialogInfo != NULL))
  133.     {
  134.         if (!pOccManager->CreateDlgControls(this, m_lpszTemplateName,
  135.             m_pOccDialogInfo))
  136.         {
  137.             TRACE0("Warning: CreateDlgControls failed during dialog bar init.\n");
  138.             return FALSE;
  139.         }
  140.     }
  141.  
  142.     return TRUE;
  143. }
  144.  
  145. BOOL CDialogBar::SetOccDialogInfo(_AFX_OCC_DIALOG_INFO* pOccDialogInfo)
  146. {
  147.     m_pOccDialogInfo = pOccDialogInfo;
  148.     return TRUE;
  149. }
  150.  
  151. #endif //!_AFX_NO_OCC_SUPPORT
  152.  
  153. #ifdef AFX_INIT_SEG
  154. #pragma code_seg(AFX_INIT_SEG)
  155. #endif
  156.  
  157. IMPLEMENT_DYNAMIC(CDialogBar, CControlBar)
  158.  
  159. ///////////////////////////////////////////////////////////////////////////
  160.