ATLEDIT.H
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:4k
源码类别:

Windows编程

开发平台:

Visual C++

  1. // AtlEdit.h : Declaration of the CAtlEdit
  2. //
  3. // This is a part of the Active Template Library.
  4. // Copyright (C) 1996-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Active Template Library Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Active Template Library product.
  12. #include "resource.h"       // main symbols
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CAtlEdit
  15. class CAtlEdit :
  16. public CComObjectRoot,
  17. public CComCoClass<CAtlEdit, &CLSID_CAtlEdit>,
  18. public CComControl<CAtlEdit>,
  19. public IDispatchImpl<IAtlEdit, &IID_IAtlEdit, &LIBID_SUBEDITLib>,
  20. public IProvideClassInfo2Impl<&CLSID_CAtlEdit, NULL, &LIBID_SUBEDITLib>,
  21. public IPersistStreamInitImpl<CAtlEdit>,
  22. public IPersistStorageImpl<CAtlEdit>,
  23. public IQuickActivateImpl<CAtlEdit>,
  24. public IOleControlImpl<CAtlEdit>,
  25. public IOleObjectImpl<CAtlEdit>,
  26. public IOleInPlaceActiveObjectImpl<CAtlEdit>,
  27. public IViewObjectExImpl<CAtlEdit>,
  28. public IOleInPlaceObjectWindowlessImpl<CAtlEdit>,
  29. public IDataObjectImpl<CAtlEdit>,
  30. public ISpecifyPropertyPagesImpl<CAtlEdit>
  31. {
  32. public:
  33. CContainedWindow m_EditCtrl;
  34. CAtlEdit() : m_EditCtrl(_T("EDIT"), this, 1)
  35. {
  36. m_bWindowOnly = TRUE;
  37. }
  38. DECLARE_REGISTRY_RESOURCEID(IDR_AtlEdit)
  39. BEGIN_COM_MAP(CAtlEdit)
  40. COM_INTERFACE_ENTRY(IAtlEdit)
  41. COM_INTERFACE_ENTRY(IDispatch)
  42. COM_INTERFACE_ENTRY_IMPL(IViewObjectEx)
  43. COM_INTERFACE_ENTRY_IMPL_IID(IID_IViewObject2, IViewObjectEx)
  44. COM_INTERFACE_ENTRY_IMPL_IID(IID_IViewObject, IViewObjectEx)
  45. COM_INTERFACE_ENTRY_IMPL(IOleInPlaceObjectWindowless)
  46. COM_INTERFACE_ENTRY_IMPL_IID(IID_IOleInPlaceObject, IOleInPlaceObjectWindowless)
  47. COM_INTERFACE_ENTRY_IMPL_IID(IID_IOleWindow, IOleInPlaceObjectWindowless)
  48. COM_INTERFACE_ENTRY_IMPL(IOleInPlaceActiveObject)
  49. COM_INTERFACE_ENTRY_IMPL(IOleControl)
  50. COM_INTERFACE_ENTRY_IMPL(IOleObject)
  51. COM_INTERFACE_ENTRY_IMPL(IQuickActivate)
  52. COM_INTERFACE_ENTRY_IMPL(IPersistStorage)
  53. COM_INTERFACE_ENTRY_IMPL(IPersistStreamInit)
  54. COM_INTERFACE_ENTRY_IMPL(ISpecifyPropertyPages)
  55. COM_INTERFACE_ENTRY_IMPL(IDataObject)
  56. COM_INTERFACE_ENTRY(IProvideClassInfo)
  57. COM_INTERFACE_ENTRY(IProvideClassInfo2)
  58. END_COM_MAP()
  59. BEGIN_PROPERTY_MAP(CAtlEdit)
  60. // PROP_ENTRY(OLESTR("Description"), dispid, clsid)
  61. PROP_PAGE(CLSID_CColorPropPage)
  62. END_PROPERTY_MAP()
  63. BEGIN_MSG_MAP(CAtlEdit)
  64. MESSAGE_HANDLER(WM_PAINT, OnPaint)
  65. MESSAGE_HANDLER(WM_CREATE, OnCreate)
  66. MESSAGE_HANDLER(WM_CTLCOLOREDIT, OnCtlColorEdit)
  67. ALT_MSG_MAP(1)
  68. MESSAGE_HANDLER(WM_CHAR, OnChar)
  69. END_MSG_MAP()
  70. // IAtlEdit
  71. public:
  72. HRESULT OnDraw(ATL_DRAWINFO&)
  73. {
  74. return S_OK;
  75. }
  76. LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  77. {
  78. RECT rc;
  79. GetWindowRect(&rc);
  80. rc.right -= rc.left;
  81. rc.bottom -= rc.top;
  82. rc.top = rc.left = 0;
  83. m_EditCtrl.Create(m_hWnd, rc, _T("hello"), WS_CHILD | WS_VISIBLE | ES_MULTILINE | ES_AUTOVSCROLL);
  84. return 0;
  85. }
  86. STDMETHOD(SetObjectRects)(LPCRECT prcPos,LPCRECT prcClip)
  87. {
  88. IOleInPlaceObjectWindowlessImpl<CAtlEdit>::SetObjectRects(prcPos, prcClip);
  89. int cx, cy;
  90. cx = prcPos->right - prcPos->left;
  91. cy = prcPos->bottom - prcPos->top;
  92. ::SetWindowPos(m_EditCtrl.m_hWnd, NULL, 0,
  93.  0, cx, cy, SWP_NOZORDER | SWP_NOACTIVATE);
  94. return S_OK;
  95. }
  96. LRESULT OnChar(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  97. {
  98. if (isalnum(wParam) || wParam == VK_SPACE || wParam == VK_RETURN || wParam == VK_TAB)
  99. m_EditCtrl.DefWindowProc(WM_CHAR, wParam, lParam);
  100. return 0;
  101. }
  102. LRESULT OnCtlColorEdit(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  103. {
  104. ::SetTextColor((HDC)wParam, RGB(255,255,0));
  105. ::SetBkColor((HDC)wParam,RGB(0,0,0));
  106. return (LRESULT)::GetStockObject(BLACK_BRUSH);
  107. }
  108. };