home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / AUTOCK2.PAK / ACLIKDOC.CPP next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  4.4 KB  |  193 lines

  1. // AClikDoc.cpp : implementation of the CAutoClickDoc class
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1995 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #include "stdafx.h"
  14. #include "AutoClik.h"
  15.  
  16. #include "AClikDoc.h"
  17. #include "Dialogs.h"
  18.  
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24.  
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CAutoClickDoc
  27.  
  28. IMPLEMENT_DYNCREATE(CAutoClickDoc, CDocument)
  29.  
  30. BEGIN_MESSAGE_MAP(CAutoClickDoc, CDocument)
  31.     //{{AFX_MSG_MAP(CAutoClickDoc)
  32.     ON_COMMAND(ID_EDIT_CHANGETEXT, OnEditChangetext)
  33.     //}}AFX_MSG_MAP
  34. END_MESSAGE_MAP()
  35.  
  36. BEGIN_DISPATCH_MAP(CAutoClickDoc, CDocument)
  37.     //{{AFX_DISPATCH_MAP(CAutoClickDoc)
  38.     DISP_PROPERTY(CAutoClickDoc, "text", m_str, VT_BSTR)
  39.     DISP_PROPERTY_EX(CAutoClickDoc, "x", GetX, SetX, VT_I2)
  40.     DISP_PROPERTY_EX(CAutoClickDoc, "y", GetY, SetY, VT_I2)
  41.     DISP_PROPERTY_EX(CAutoClickDoc, "Position", GetPosition, SetPosition, VT_DISPATCH)
  42.     DISP_FUNCTION(CAutoClickDoc, "RefreshWindow", Refresh, VT_EMPTY, VTS_NONE)
  43.     DISP_FUNCTION(CAutoClickDoc, "SetAllProps", SetAllProps, VT_EMPTY, VTS_I2 VTS_I2 VTS_BSTR)
  44.     DISP_FUNCTION(CAutoClickDoc, "ShowWindow", ShowWindow, VT_EMPTY, VTS_NONE)
  45.     //}}AFX_DISPATCH_MAP
  46. END_DISPATCH_MAP()
  47.  
  48. // Note: we add support for IID_IAClick to support typesafe binding
  49. //  from VBA.  This IID must match the GUID that is attached to the 
  50. //  dispinterface in the .ODL file.
  51.  
  52. // {47D53E05-CC33-11CE-8F35-00DD01109044}
  53. static const IID IID_IAClick =
  54. { 0x47d53e05, 0xcc33, 0x11ce, { 0x8f, 0x35, 0x0, 0xdd, 0x1, 0x10, 0x90, 0x44 } };
  55.  
  56. BEGIN_INTERFACE_MAP(CAutoClickDoc, CDocument)
  57.     INTERFACE_PART(CAutoClickDoc, IID_IAClick, Dispatch)
  58. END_INTERFACE_MAP()
  59.  
  60. /////////////////////////////////////////////////////////////////////////////
  61. // CAutoClickDoc construction/destruction
  62.  
  63. CAutoClickDoc::CAutoClickDoc()
  64. {
  65.     EnableAutomation();
  66.     m_pt = CPoint(10, 10);
  67.     m_str = _T("Automation!");
  68.  
  69.     AfxOleLockApp();
  70. }
  71.  
  72. CAutoClickDoc::~CAutoClickDoc()
  73. {
  74.     AfxOleUnlockApp();
  75. }
  76.  
  77. BOOL CAutoClickDoc::OnNewDocument()
  78. {
  79.     if (!CDocument::OnNewDocument())
  80.         return FALSE;
  81.  
  82.     // TODO: add reinitialization code here
  83.     // (SDI documents will reuse this document)
  84.  
  85.     return TRUE;
  86. }
  87.  
  88. void CAutoClickDoc::Refresh()
  89. {
  90.     UpdateAllViews(NULL);
  91.     SetModifiedFlag();
  92. }
  93.  
  94. /////////////////////////////////////////////////////////////////////////////
  95. // CAutoClickDoc serialization
  96.  
  97. void CAutoClickDoc::Serialize(CArchive& ar)
  98. {
  99.     if (ar.IsStoring())
  100.     {
  101.         ar << m_pt << m_str;
  102.     }
  103.     else
  104.     {
  105.         ar >> m_pt >> m_str;
  106.     }
  107. }
  108.  
  109. /////////////////////////////////////////////////////////////////////////////
  110. // CAutoClickDoc diagnostics
  111.  
  112. #ifdef _DEBUG
  113. void CAutoClickDoc::AssertValid() const
  114. {
  115.     CDocument::AssertValid();
  116. }
  117.  
  118. void CAutoClickDoc::Dump(CDumpContext& dc) const
  119. {
  120.     CDocument::Dump(dc);
  121. }
  122. #endif //_DEBUG
  123.  
  124. /////////////////////////////////////////////////////////////////////////////
  125. // CAutoClickDoc commands
  126.  
  127. void CAutoClickDoc::OnEditChangetext() 
  128. {
  129.     CChangeText dlg;
  130.     dlg.m_str = m_str;
  131.     if (dlg.DoModal())
  132.     {
  133.         m_str = dlg.m_str;
  134.         Refresh();
  135.     }
  136. }
  137.  
  138. short CAutoClickDoc::GetX()
  139. {
  140.     return (short)m_pt.x;
  141. }
  142.  
  143. void CAutoClickDoc::SetX(short nNewValue)
  144. {
  145.     m_pt.x = nNewValue;
  146.     Refresh();
  147. }
  148.  
  149. short CAutoClickDoc::GetY()
  150. {
  151.     return (short)m_pt.y;
  152. }
  153.  
  154. void CAutoClickDoc::SetY(short nNewValue)
  155. {
  156.     m_pt.y = nNewValue;
  157.     Refresh();
  158. }
  159.  
  160. void CAutoClickDoc::SetAllProps(short x, short y, LPCTSTR text)
  161. {
  162.     m_pt.x = x;
  163.     m_pt.y = y;
  164.     m_str = text;
  165.     Refresh();
  166. }
  167.  
  168. void CAutoClickDoc::ShowWindow()
  169. {
  170.     POSITION pos = GetFirstViewPosition();
  171.     CView* pView = GetNextView(pos);
  172.     if (pView != NULL)
  173.     {
  174.         CFrameWnd* pFrameWnd = pView->GetParentFrame();
  175.         pFrameWnd->ActivateFrame(SW_SHOW);
  176.         pFrameWnd = pFrameWnd->GetParentFrame();
  177.         if (pFrameWnd != NULL)
  178.             pFrameWnd->ActivateFrame(SW_SHOW);
  179.     }
  180. }
  181.  
  182. LPDISPATCH CAutoClickDoc::GetPosition() 
  183. {
  184.     // TODO: Add your property handler here
  185.  
  186.     return NULL;
  187. }
  188.  
  189. void CAutoClickDoc::SetPosition(LPDISPATCH newValue) 
  190. {
  191.     // TODO: Add your property handler here
  192. }
  193.