SimulateMouseView.cpp
上传用户:qzzxgm
上传日期:2009-12-14
资源大小:1882k
文件大小:4k
源码类别:

书籍源码

开发平台:

Visual C++

  1. // SimulateMouseView.cpp : implementation of the CSimulateMouseView class
  2. //
  3. #include "stdafx.h"
  4. #include "SimulateMouse.h"
  5. #include "SimulateMouseDoc.h"
  6. #include "SimulateMouseView.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CSimulateMouseView
  14. IMPLEMENT_DYNCREATE(CSimulateMouseView, CFormView)
  15. BEGIN_MESSAGE_MAP(CSimulateMouseView, CFormView)
  16. //{{AFX_MSG_MAP(CSimulateMouseView)
  17. ON_BN_CLICKED(IDC_LDBCLICK, OnLdbclick)
  18. ON_BN_CLICKED(IDC_LCLICK, OnLclick)
  19. //}}AFX_MSG_MAP
  20. // Standard printing commands
  21. ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
  22. ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
  23. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
  24. END_MESSAGE_MAP()
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CSimulateMouseView construction/destruction
  27. CSimulateMouseView::CSimulateMouseView()
  28. : CFormView(CSimulateMouseView::IDD)
  29. {
  30. //{{AFX_DATA_INIT(CSimulateMouseView)
  31. // NOTE: the ClassWizard will add member initialization here
  32. //}}AFX_DATA_INIT
  33. // TODO: add construction code here
  34. }
  35. CSimulateMouseView::~CSimulateMouseView()
  36. {
  37. }
  38. void CSimulateMouseView::DoDataExchange(CDataExchange* pDX)
  39. {
  40. CFormView::DoDataExchange(pDX);
  41. //{{AFX_DATA_MAP(CSimulateMouseView)
  42. // NOTE: the ClassWizard will add DDX and DDV calls here
  43. //}}AFX_DATA_MAP
  44. }
  45. BOOL CSimulateMouseView::PreCreateWindow(CREATESTRUCT& cs)
  46. {
  47. // TODO: Modify the Window class or styles here by modifying
  48. //  the CREATESTRUCT cs
  49. return CFormView::PreCreateWindow(cs);
  50. }
  51. void CSimulateMouseView::OnInitialUpdate()
  52. {
  53. CFormView::OnInitialUpdate();
  54. GetParentFrame()->RecalcLayout();
  55. ResizeParentToFit();
  56. }
  57. /////////////////////////////////////////////////////////////////////////////
  58. // CSimulateMouseView printing
  59. BOOL CSimulateMouseView::OnPreparePrinting(CPrintInfo* pInfo)
  60. {
  61. // default preparation
  62. return DoPreparePrinting(pInfo);
  63. }
  64. void CSimulateMouseView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  65. {
  66. // TODO: add extra initialization before printing
  67. }
  68. void CSimulateMouseView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  69. {
  70. // TODO: add cleanup after printing
  71. }
  72. void CSimulateMouseView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
  73. {
  74. // TODO: add customized printing code here
  75. }
  76. /////////////////////////////////////////////////////////////////////////////
  77. // CSimulateMouseView diagnostics
  78. #ifdef _DEBUG
  79. void CSimulateMouseView::AssertValid() const
  80. {
  81. CFormView::AssertValid();
  82. }
  83. void CSimulateMouseView::Dump(CDumpContext& dc) const
  84. {
  85. CFormView::Dump(dc);
  86. }
  87. CSimulateMouseDoc* CSimulateMouseView::GetDocument() // non-debug version is inline
  88. {
  89. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSimulateMouseDoc)));
  90. return (CSimulateMouseDoc*)m_pDocument;
  91. }
  92. #endif //_DEBUG
  93. /////////////////////////////////////////////////////////////////////////////
  94. // CSimulateMouseView message handlers
  95. void CSimulateMouseView::OnLdbclick() 
  96. {
  97. //将鼠标的位置放在窗口的标题条上
  98. POINT lpPoint;
  99. CRect rc;
  100. CWnd* pParent = AfxGetApp()->GetMainWnd();
  101. pParent->GetWindowRect(&rc);
  102. lpPoint.x = rc.left+50;
  103. lpPoint.y = rc.top+10;
  104. SetCursorPos(lpPoint.x, lpPoint.y);
  105. //双击该标题条
  106. mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
  107. mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
  108. mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
  109. mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
  110. }
  111. void CSimulateMouseView::OnLclick() 
  112. {
  113. //将鼠标的位置放在窗口的关闭按钮上
  114. POINT lpPoint;
  115. CRect rc;
  116. CWnd* pParent = AfxGetApp()->GetMainWnd();
  117. pParent->GetWindowRect(&rc);
  118. lpPoint.x = rc.right-5;
  119. lpPoint.y = rc.top +5;
  120. SetCursorPos(lpPoint.x, lpPoint.y);
  121. //单击
  122. mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
  123. mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
  124. }