bardlg.cpp 3.9 KB

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