XPropertiesWndPpg.cpp
上传用户:yangzi5763
上传日期:2007-01-02
资源大小:239k
文件大小:8k
源码类别:

ActiveX/DCOM/ATL

开发平台:

Visual C++

  1. /************************************
  2.   REVISION LOG ENTRY
  3.   Revision By: Mihai Filimon
  4.   Revised on 10/13/98 5:26:24 PM
  5.   Comments: XPropertiesWndPpg.cpp : Implementation of the CXPropertiesWndPropPage property page class.
  6.  ************************************/
  7. #include "stdafx.h"
  8. #include "XPropertiesWnd.h"
  9. #include "XPropertiesWndPpg.h"
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15. IMPLEMENT_DYNCREATE(CXPropertiesWndPropPage, COlePropertyPage)
  16. /////////////////////////////////////////////////////////////////////////////
  17. // Message map
  18. BEGIN_MESSAGE_MAP(CXPropertiesWndPropPage, COlePropertyPage)
  19. //{{AFX_MSG_MAP(CXPropertiesWndPropPage)
  20. ON_WM_VSCROLL()
  21. //}}AFX_MSG_MAP
  22. END_MESSAGE_MAP()
  23. /////////////////////////////////////////////////////////////////////////////
  24. // Initialize class factory and guid
  25. IMPLEMENT_OLECREATE_EX(CXPropertiesWndPropPage, "XPROPERTIESWND.XPropertiesWndPropPage.1",
  26. 0x7b914a5c, 0x6271, 0x11d2, 0x86, 0xb8, 0, 0x40, 0x5, 0x5c, 0x8, 0xd9)
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CXPropertiesWndPropPage::CXPropertiesWndPropPageFactory::UpdateRegistry -
  29. // Adds or removes system registry entries for CXPropertiesWndPropPage
  30. BOOL CXPropertiesWndPropPage::CXPropertiesWndPropPageFactory::UpdateRegistry(BOOL bRegister)
  31. {
  32. if (bRegister)
  33. return AfxOleRegisterPropertyPageClass(AfxGetInstanceHandle(),
  34. m_clsid, IDS_XPROPERTIESWND_PREVIEW_PPG);
  35. else
  36. return AfxOleUnregisterClass(m_clsid, NULL);
  37. }
  38. /////////////////////////////////////////////////////////////////////////////
  39. // CXPropertiesWndPropPage::CXPropertiesWndPropPage - Constructor
  40. CXPropertiesWndPropPage::CXPropertiesWndPropPage() :
  41. COlePropertyPage(IDD, IDS_XPROPERTIESWND_PPG_PREVIEW_CAPTION)
  42. {
  43. //{{AFX_DATA_INIT(CXPropertiesWndPropPage)
  44. //}}AFX_DATA_INIT
  45. m_nRenamePage = -1;
  46. m_xFloorWndPages.SetOleDialog(this);
  47. }
  48. /////////////////////////////////////////////////////////////////////////////
  49. // CXPropertiesWndPropPage::DoDataExchange - Moves data between page and properties
  50. void CXPropertiesWndPropPage::DoDataExchange(CDataExchange* pDX)
  51. {
  52. //{{AFX_DATA_MAP(CXPropertiesWndPropPage)
  53. DDX_Control(pDX, IDC_SLIDER_ADDDEL, m_sldAddDel);
  54. DDX_Control(pDX, IDC_XFLOORWNDCTRL_PAGES, m_xFloorWndPages);
  55. //}}AFX_DATA_MAP
  56. DDP_PostProcessing(pDX);
  57. m_xFloorWndPages.DataExchange(pDX);
  58. m_sldAddDel.SetRange(0,6);
  59. m_sldAddDel.SetPos(m_xFloorWndPages.GetPagesCount());
  60. }
  61. /////////////////////////////////////////////////////////////////////////////
  62. // CXPropertiesWndPropPage message handlers
  63. CXPropertiesWndPropPage* CXPropertiesWndPropPage::m_pThis = NULL;
  64. BOOL CXPropertiesWndPropPage::OnInitDialog() 
  65. {
  66. COlePropertyPage::OnInitDialog();
  67. m_edtRename.Create(ES_WANTRETURN | ES_MULTILINE | ES_CENTER | WS_CHILD , CRect(0,0,0,0), &m_xFloorWndPages, 1000);
  68. m_edtRename.SetFont(GetFont());
  69. /* ASSERT (m_pThis == NULL);
  70. m_pThis = this;
  71. m_hHook = SetWindowsHookEx(WH_CALLWNDPROC, CallWndProcHookParent, AfxGetInstanceHandle(), GetWindowThreadProcessId(GetParent()->m_hWnd, NULL));
  72. Refresh();
  73. */
  74. return TRUE;  // return TRUE unless you set the focus to a control
  75.               // EXCEPTION: OCX Property Pages should return FALSE
  76. }
  77. // Function name : CXPropertiesWndPropPage::Refresh
  78. // Description     : Refresh color, etc...
  79. // Return type : void 
  80. void CXPropertiesWndPropPage::Refresh()
  81. {
  82. ULONG pnObjects = NULL;
  83. LPDISPATCH* lpDispatch = GetObjectArray(  &pnObjects );
  84. if (pnObjects)
  85. {
  86. COleDispatchDriver oleDispatch;
  87. oleDispatch.AttachDispatch(lpDispatch[0]);
  88. OLE_COLOR oleColor;
  89. oleDispatch.GetProperty(DISPID_BACKCOLOR, VT_I4, &oleColor);
  90. m_xFloorWndPages.SetBackColor(oleColor);
  91. oleDispatch.DetachDispatch();
  92. }
  93. }
  94. // Function name : CXPropertiesWndPropPage::CallWndProcHook
  95. // Description     : Hook procedure. Wait to m_pThis->GetParent() receives WM_WINDOWPOSCHANGED and WM_DESTROY messages
  96. // Return type : LRESULT 
  97. // Argument         : int nCode
  98. // Argument         : WPARAM wParam
  99. // Argument         : LPARAM lParam
  100. LRESULT CXPropertiesWndPropPage::CallWndProcHookParent(int nCode, WPARAM wParam, LPARAM lParam)
  101. {
  102. LRESULT lResult = CallNextHookEx(m_pThis->m_hHook, nCode, wParam, lParam);
  103. if (nCode >= 0)
  104. if (m_pThis->GetParent())
  105. {
  106. CWPSTRUCT* pMessage = (CWPSTRUCT*)lParam;
  107. if (pMessage->hwnd == m_pThis->GetParent()->m_hWnd)
  108. switch (pMessage->message)
  109. {
  110. case WM_WINDOWPOSCHANGED:
  111. {
  112. LPWINDOWPOS lpWindowPos = (LPWINDOWPOS)pMessage->lParam;
  113. if (lpWindowPos->flags | SWP_SHOWWINDOW)
  114. m_pThis->Refresh();
  115. break;
  116. }
  117. case WM_DESTROY:
  118. {
  119. UnhookWindowsHookEx(m_pThis->m_hHook);
  120. m_pThis = NULL;
  121. break;
  122. }
  123. }
  124. }
  125. return lResult;
  126. }
  127. // Function name : CXPropertiesWndPropPage::AddPage
  128. // Description     : 
  129. // Return type : void 
  130. void CXPropertiesWndPropPage::AddPage()
  131. {
  132. m_xFloorWndPages.AddPage(_T("Noname"));
  133. }
  134. // Function name : CXPropertiesWndPropPage::DeletePage
  135. // Description     : 
  136. // Return type : void 
  137. void CXPropertiesWndPropPage::DeletePage()
  138. {
  139. int nA = m_xFloorWndPages.GetActivePage();
  140. if (nA >= 0)
  141. m_xFloorWndPages.DeletePage(nA);
  142. }
  143. // Function name : CXPropertiesWndPropPage::RenamePage
  144. // Description     : 
  145. // Return type : void 
  146. // Argument         : int nIndex
  147. void CXPropertiesWndPropPage::RenamePage(int nIndex)
  148. {
  149. if (nIndex >= 0)
  150. {
  151. CString newName;
  152. m_edtRename.GetWindowText(newName);
  153. if (!newName.IsEmpty())
  154. if (newName != m_xFloorWndPages.GetPageName(nIndex))
  155. {
  156. m_xFloorWndPages.SetPageName(nIndex , newName);
  157. m_xFloorWndPages.Invalidate();
  158. m_nRenamePage = -1;
  159. SetModifiedFlag();
  160. }
  161. }
  162. }
  163. // Function name : CXPropertiesWndPropPage::OnVScroll
  164. // Description     : 
  165. // Return type : void 
  166. // Argument         : UINT nSBCode
  167. // Argument         : UINT nPos
  168. // Argument         : CScrollBar* pScrollBar
  169. void CXPropertiesWndPropPage::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
  170. {
  171. if ((LPARAM)pScrollBar == (LPARAM)&m_sldAddDel)
  172. {
  173. int cPages = m_sldAddDel.GetPos(), i = 0;
  174. for (i = 0; i < cPages; i++)
  175. if (!m_xFloorWndPages.IsPage(i))
  176. {
  177. CString page;
  178. page.Format(_T("Page %i"), i + 1);
  179. m_xFloorWndPages.AddPage(page);
  180. }
  181. while ( i < m_xFloorWndPages.GetPagesCount() )
  182. m_xFloorWndPages.DeletePage(i);
  183. m_xFloorWndPages.Init();
  184. SetModifiedFlag();
  185. }
  186. COlePropertyPage::OnVScroll(nSBCode, nPos, pScrollBar);
  187. }
  188. BEGIN_EVENTSINK_MAP(CXPropertiesWndPropPage, COlePropertyPage)
  189.     //{{AFX_EVENTSINK_MAP(CXPropertiesWndPropPage)
  190. ON_EVENT(CXPropertiesWndPropPage, IDC_XFLOORWNDCTRL_PAGES, 2 /* ClickOnActivePage */, OnClickOnActivePageXfloorwndctrlPages, VTS_I2)
  191. //}}AFX_EVENTSINK_MAP
  192. END_EVENTSINK_MAP()
  193. // Function name : CXPropertiesWndPropPage::OnClickOnActivePageXfloorwndctrlPages
  194. // Description     : Start to rename page
  195. // Return type : void 
  196. // Argument         : short nIndex
  197. void CXPropertiesWndPropPage::OnClickOnActivePageXfloorwndctrlPages(short nIndex) 
  198. {
  199. ASSERT (m_xFloorWndPages.IsPage(nIndex));
  200. long pTopLeft = m_xFloorWndPages.GetLeftTopPage(nIndex);
  201. long pBottomRight = m_xFloorWndPages.GetBottomRightPage(nIndex);
  202. m_nRenamePage = nIndex;
  203. CRect rect(CPoint(LOWORD(pTopLeft),HIWORD(pTopLeft)), CPoint(LOWORD(pBottomRight),HIWORD(pBottomRight)));
  204. rect.InflateRect(-2,-2);
  205. m_edtRename.Do(rect,m_xFloorWndPages.GetPageName(nIndex));
  206. }
  207. // Function name : CXPropertiesWndPropPagePreTranslateMessage
  208. // Description     : 
  209. // Return type : BOOL 
  210. // Argument         : MSG* pMsg
  211. BOOL CXPropertiesWndPropPage::PreTranslateMessage( MSG* pMsg )
  212. {
  213. if (pMsg->message == WM_KEYDOWN &&
  214. (pMsg->wParam == VK_ESCAPE || pMsg->wParam == VK_CANCEL))
  215. {
  216. return TRUE;
  217. }
  218. return COlePropertyPage::PreTranslateMessage(pMsg);
  219. }