Plugin.cpp
上传用户:easylife05
上传日期:2007-02-14
资源大小:393k
文件大小:5k
源码类别:

PlugIns编程

开发平台:

Visual C++

  1. // Plugin.cpp : CPlugin 的实现
  2. #include "stdafx.h"
  3. #include <string.h>
  4. #include "Plugin.h"
  5. //#include <Winuser.h>
  6. //#include <windows.h>
  7. // CPlugin
  8. extern HINSTANCE global_hInstance; //全局程序实例句柄
  9. STDMETHODIMP CPlugin::GetFunctionCount(SHORT* pCount)
  10. {
  11. // TODO: 在此添加实现代码
  12. *pCount=FUNCTION_NUM;
  13. return S_OK;
  14. }
  15. STDMETHODIMP CPlugin::DoFunction(SHORT index)
  16. {
  17. //----------------------------------------
  18. myGraph* mGraph=NULL;
  19. switch(index)
  20. {
  21. case 0:
  22. //MessageBox(NULL,"I am Plugin2's first function","Hello",MB_OK);
  23. if (m_myDlg==NULL)
  24. {
  25. m_myDlg=new CMyDialog(m_hDC);
  26. m_myDlg->Create(NULL);
  27. }//delete m_myDlg;
  28. m_pServer->GetDataPoint(&mGraph);
  29. m_myDlg->m_Graph=mGraph;
  30. m_myDlg->m_dlgServer=m_pServer;
  31. //m_pGraph=mGraph;
  32. m_myDlg->ShowWindow(SW_SHOWNORMAL);
  33. m_myDlg->BringWindowToTop();
  34. break;
  35. case 1:
  36. //MessageBox(NULL,"简单的信息提示!","插件提示",MB_OK);
  37. CTestDialog mDlg;
  38. mDlg.m_hWND=m_hWND;
  39. mDlg.DoModal();
  40. break;
  41. //default:;
  42. }
  43. return S_OK;
  44. }
  45. STDMETHODIMP CPlugin::GetFunctionName(SHORT index, CHAR* name)
  46. {
  47. // TODO: 在此添加实现代码
  48. switch(index)
  49. {
  50. case 0:
  51. strcpy(name,"Scribble");
  52. break;
  53. case 1:
  54. strcpy(name,"功能调用");
  55. break;
  56. default:
  57. ;
  58. }
  59. return S_OK;
  60. }
  61. STDMETHODIMP CPlugin::GetPluginName(CHAR* name)
  62. {
  63. // TODO: 在此添加实现代码
  64. strcpy(name,"图形插件");
  65. return S_OK;
  66. }
  67. STDMETHODIMP CPlugin::SendMouseMessage(UINT Message, UINT flags, int x, int y)
  68. {
  69. // TODO: 在此添加实现代码
  70. if (m_myDlg!=NULL)
  71. {
  72. HWND hwndStatus =m_myDlg->GetDlgItem(IDC_EDIT1);
  73. TCHAR szCookieItem[100];
  74. switch(Message)
  75. {
  76. case WM_MOUSEMOVE:
  77. _stprintf(szCookieItem, _T("MouseMove( x position %d,y position%d) "), x,y);
  78. if (m_Paint){
  79. m_Target.x=x;m_Target.y=y;
  80. m_myDlg->DrawTo(m_Source,m_Target);
  81. m_Source.x=m_Target.x;m_Source.y=m_Target.y;
  82. }
  83. if ((m_myDlg->m_bPaint) && m_Paint)
  84. ///*if (m_Paint)
  85. {
  86. ::SetCursor(::LoadCursor(NULL,IDC_CROSS));
  87. }else
  88. {
  89. ::SetCursor(::LoadCursor(NULL,IDC_ARROW));
  90. }
  91. break;
  92. case WM_LBUTTONDOWN:
  93. _stprintf(szCookieItem, _T("MouseLeftbuttondown( x position %d,y position%d) "), x,y);
  94. m_Source.x=x;m_Source.y=y;
  95. m_Paint=true;
  96. if ((m_myDlg->m_bPaint) && m_Paint)
  97. ::SetCursor(::LoadCursor(NULL,IDC_CROSS));
  98. break;
  99. case WM_LBUTTONUP:
  100. _stprintf(szCookieItem, _T("MouseLeftbuttonup( x position %d,y position%d) "), x,y);
  101. m_Paint=false;
  102. //if (m_myDlg->m_bPaint)
  103. ::SetCursor(::LoadCursor(NULL,IDC_ARROW));
  104. break;
  105. case WM_LBUTTONDBLCLK:
  106. _stprintf(szCookieItem, _T("MouseDoublebuttonclick( x position %d,y position%d) "), x,y);
  107. m_Paint=false;
  108. //-------------画圆------------
  109. if (m_myDlg->m_bCircle)
  110. {
  111. ::SetCursor(::LoadCursor(NULL,IDC_UPARROW));
  112. HPEN hPen = ::CreatePen(PS_SOLID,m_myDlg->m_Width,RGB(m_myDlg->m_Red,m_myDlg->m_Green,m_myDlg->m_Blue) ) ;
  113. HPEN hOldPen = (HPEN) ::SelectObject(m_hDC, hPen) ;
  114. ::Ellipse(m_hDC,x-20*m_myDlg->m_Rate, y-20*m_myDlg->m_Rate,
  115. x+20*m_myDlg->m_Rate,y+20*m_myDlg->m_Rate);
  116. ::SelectObject(m_hDC,hOldPen);
  117. LOGBRUSH logBrush;
  118. logBrush.lbStyle = BS_NULL;
  119. logBrush.lbColor = RGB(0, 192, 192);
  120. logBrush.lbHatch = HS_CROSS;
  121. HBRUSH brush=::CreateBrushIndirect(&logBrush);
  122. ::SelectObject(m_hDC,brush);
  123. myGraph mGraph;
  124. mGraph.mRed=m_myDlg->m_Red;mGraph.mGreen=m_myDlg->m_Green;mGraph.mBlue=m_myDlg->m_Blue;
  125. mGraph.mRate=m_myDlg->m_Rate;mGraph.x=x;mGraph.y=y;mGraph.mWidth=m_myDlg->m_Width;
  126. mGraph.next=NULL;
  127. m_pServer->NewDataCircle(&mGraph);
  128. }
  129. ::SetCursor(::LoadCursor(NULL,IDC_ARROW));
  130. //-----------------------------
  131. break;
  132. default:
  133. _stprintf(szCookieItem, _T("OtherMouseMessages( x position %d,y position%d) "), x,y);
  134. break;
  135. }
  136. ::SetWindowText(hwndStatus, szCookieItem);
  137. }
  138. return S_OK;
  139. }
  140. STDMETHODIMP CPlugin::PassHDC(HDC hDC)
  141. {
  142. // TODO: 在此添加实现代码
  143. m_hDC=hDC;
  144. return S_OK;
  145. }
  146. STDMETHODIMP CPlugin::PassHWND(HWND mHWND)
  147. {
  148. // TODO: 在此添加实现代码
  149. m_hWND=mHWND;
  150. return S_OK;
  151. }
  152. STDMETHODIMP CPlugin::SetServer(IUnknown* iServer)
  153. {
  154. // TODO: 在此添加实现代码
  155. m_pServer=(IServer*)iServer;
  156. return S_OK;
  157. }
  158. STDMETHODIMP CPlugin::ReDraw(void)
  159. {
  160. //-------------------------------------------
  161. if (m_myDlg==NULL) return S_OK;
  162. if (!(m_myDlg->m_bDraw)) return S_OK;
  163. m_pServer->GetDataPoint(&m_pGraph);
  164. myGraph *mGraph;
  165. mGraph=m_pGraph;
  166. while (mGraph!=NULL)
  167. { //创建为空刷子,以使圆透明
  168. LOGBRUSH logBrush;
  169. logBrush.lbStyle = BS_NULL;
  170. logBrush.lbColor = RGB(0, 192, 192);
  171. logBrush.lbHatch = HS_CROSS;
  172. HBRUSH brush=::CreateBrushIndirect(&logBrush);
  173. //::SelectObject(m_hDC,brush);
  174. HBRUSH oldBrush=(HBRUSH)::SelectObject(m_hDC,brush);
  175. HPEN hPen = ::CreatePen(PS_SOLID,mGraph->mWidth,RGB(mGraph->mRed,mGraph->mGreen,mGraph->mBlue) ) ;
  176. HPEN hOldPen = (HPEN) ::SelectObject(m_hDC, hPen) ;
  177. ::Ellipse(m_hDC,mGraph->x-20*mGraph->mRate, mGraph->y-20*mGraph->mRate,
  178. mGraph->x+20*mGraph->mRate,mGraph->y+20*mGraph->mRate);
  179. ::SelectObject(m_hDC,hOldPen);
  180. ::SelectObject(m_hDC,oldBrush);
  181. mGraph=mGraph->next;
  182. }
  183. return S_OK;
  184. }
  185. STDMETHODIMP CPlugin::GetToolBarBitmap(HBITMAP* hBitmap)
  186. {
  187. // TODO: 在此添加实现代码
  188. *hBitmap=::LoadBitmap(global_hInstance,MAKEINTRESOURCE(IDB_PALETTE));
  189. return S_OK;
  190. }