ShowIntTool.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #include "stdafx.h"
  2. #include "ShowIntTool.h"
  3. #include "ToolDialog.h"
  4. #include "Resource.h"
  5. DLL_TOOL_DESC m_Description;
  6. ///////////////////////////////////////////////////////////////////
  7. // 返回工具新实例的指针
  8. extern "C" __declspec(dllexport) CDllTool<int, int, int>* GetToolPtr(CWnd * pWnd)
  9. {
  10. return (new CShowIntTool(pWnd));
  11. }
  12. ////////////////////////////////////////////////////////////////
  13. // 生成工具描述
  14. extern "C" __declspec(dllexport) const DLL_TOOL_DESC& Description()
  15. {
  16. // 生成dll描述
  17. m_Description.strCategory = _T("变量显示");
  18. m_Description.strName = _T("Show_Int");
  19. m_Description.strVersion = _T("1.0");
  20. m_Description.strInfo = _T("This Info");
  21. // 接口
  22. DLL_INF_DESC inf;
  23. inf.strName = _T("Int.InPut1");
  24. inf.nIndex = 1;
  25. inf.bWay = INF_IN;
  26. inf.strValueType = PARAM_INT;
  27. m_Description.Interfaces.push_back(inf);
  28. inf.strName = _T("Int.InPut2");
  29. inf.nIndex = 2;
  30. inf.bWay = INF_IN;
  31. inf.strValueType = PARAM_INT;
  32. m_Description.Interfaces.push_back(inf);
  33. inf.strName = _T("Int.OutPut");
  34. inf.nIndex = 3;
  35. inf.bWay = INF_OUT;
  36. inf.strValueType = PARAM_INT;
  37. m_Description.Interfaces.push_back(inf);
  38. return m_Description;
  39. }
  40. CShowIntTool::CShowIntTool(CWnd * pWnd)
  41. {
  42. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  43. // 重新生成描述
  44. Description();
  45. // 赋初值
  46. m_Value1 = PARAM_INT_DEFAULT_VALUE;
  47. m_Value2 = PARAM_INT_DEFAULT_VALUE;
  48. m_Value3 = PARAM_INT_DEFAULT_VALUE;
  49. pDlg = NULL;
  50. pDlg = new CToolDialog();
  51. pDlg->Create(IDD_SHOWINT_DIALOG, CWnd::FromHandle(pWnd->GetSafeHwnd()));
  52. pDlg->ShowWindow(SW_HIDE);
  53. if (pDlg != NULL)
  54. {
  55. m_Even.hEvenHandle = NULL;
  56. m_Even = pDlg->GetEvent();
  57. }
  58. }
  59. CShowIntTool::~CShowIntTool()
  60. {
  61. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  62. if (pDlg != NULL)
  63. {
  64. pDlg->DestroyWindow();
  65. delete pDlg;
  66. pDlg = NULL;
  67. }
  68. if (m_Even.hEvenHandle != NULL)
  69. {
  70. CloseHandle(m_Even.hEvenHandle);
  71. m_Even.hEvenHandle = NULL;
  72. }
  73. }
  74. ////////////////////////////////////////////////////////////////////
  75. // 主框架的信息传入dll
  76. void CShowIntTool::MainFrameInfo(FRAMEINFO* info)
  77. {
  78. if (pDlg != NULL)
  79. {
  80. pDlg->pFrameInfo = info;
  81. }
  82. }
  83. //系统Run和Stop时调用
  84. void CShowIntTool::Running(bool bRun)
  85. {
  86. if (pDlg != NULL)
  87. {
  88. pDlg->Running(bRun);
  89. }
  90. }
  91. // 序列化
  92. void CShowIntTool::Serialize(CArchive& ar)
  93. {
  94. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  95. if (pDlg != NULL)
  96. {
  97. pDlg->Serialize(ar);
  98. }
  99. }
  100. // 显示参数设置对话框
  101. void CShowIntTool::ShowDialog(CString strName)
  102. {
  103. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  104. if (pDlg != NULL)
  105. {
  106. pDlg->SetWindowTextW(strName);
  107. pDlg->BringWindowToTop();
  108. pDlg->ShowWindow(SW_SHOW);
  109. }
  110. }
  111. int CShowIntTool::Execute()
  112. {
  113. // ForTest输出执行的结果信息
  114. if (pDlg != NULL)
  115. {
  116. pDlg->m_Value = m_Value1;
  117. pDlg->m_Value2 = m_Value2;
  118. pDlg->Execute();
  119. }
  120. int nResult = pDlg->m_Value + pDlg->m_Value2;
  121. m_Value3 = nResult;
  122. CString strTip;
  123. strTip.Format(_T("Tool - %s\nInterface - %s\nExecute output:%d + %d = %d\n"),
  124. m_Description.strName, m_Description.Interfaces[2].strName,
  125. m_Value1, m_Value2, nResult);
  126. // AfxMessageBox(strTip, MB_ICONINFORMATION);
  127. return 0;
  128. }