ToolbarPlugin.cpp
Upload User: kairuinn
Upload Date: 2009-02-07
Package Size: 2922k
Code Size: 5k
Category:

Graph program

Development Platform:

Visual C++

  1. #include "stdafx.h"
  2. #include "ToolbarPlugin.h"
  3. CToolbarPlugin::CToolbarPlugin(HINSTANCE hInst, PLUGIN_INFO plInfo):
  4. CPluginBase(hInst,plInfo)
  5. {
  6. m_start_ID = 0;
  7. m_end_ID = 0;
  8. m_was_load = false;
  9. m_reset_names_func = NULL;
  10. m_get_button_state_func=NULL;
  11. m_get_status_bar_message = NULL;
  12. m_get_tooltip_message=NULL;
  13. m_get_new_commander = NULL;
  14. m_get_edit_commander = NULL;
  15. m_free_commander = NULL;
  16. }
  17. CToolbarPlugin::~CToolbarPlugin()
  18. {
  19. for (size_t i=0, sz=m_object_bitmaps.size();i<sz;i++)
  20. delete m_object_bitmaps[i];
  21. }
  22.  bool CToolbarPlugin::LoadSupportedIDs()
  23.  {
  24.  typedef void(*LPDLLFUNC_FILL_SUPPORTED_IDS)(std::vector<const char*>&);
  25.  LPDLLFUNC_FILL_SUPPORTED_IDS  lpfnDllFuncFillObjectsIDs = NULL;
  26.  lpfnDllFuncFillObjectsIDs = (LPDLLFUNC_FILL_SUPPORTED_IDS)::GetProcAddress(m_hInst,"GetSupportedObjectIDs");
  27.  if (lpfnDllFuncFillObjectsIDs)
  28.  lpfnDllFuncFillObjectsIDs(m_supported_objectsIDs);
  29.  else
  30.  return false;
  31.  return true;
  32. }
  33.  bool  CToolbarPlugin::LoadObjectsBitmaps()
  34.  {
  35.  typedef HBITMAP(*LPDLLFUNC_GET_OBJECT_BITMAP)(const char*, LPWORD);
  36.  LPDLLFUNC_GET_OBJECT_BITMAP  lpfnDllFuncGetObjectBitmap = NULL;
  37.  m_object_bitmaps.assign(m_supported_objectsIDs.size(), NULL);
  38.  lpfnDllFuncGetObjectBitmap = (LPDLLFUNC_GET_OBJECT_BITMAP)::GetProcAddress(m_hInst,"GetObjectBitmap");
  39.  if (lpfnDllFuncGetObjectBitmap)
  40.  {
  41.  size_t sz=m_supported_objectsIDs.size();
  42.  for (size_t i=0;i<sz;i++)
  43.  {
  44.  CBitmap32* tmpBmp = new CBitmap32;
  45.  WORD lc;
  46.  HBITMAP tmpHbmp = lpfnDllFuncGetObjectBitmap(m_supported_objectsIDs[i],&lc);
  47.  if (tmpHbmp)
  48.  {
  49. tmpBmp->Attach(tmpHbmp,&lc);
  50. m_object_bitmaps[i] = tmpBmp;
  51.  }
  52.  else
  53.  {
  54.  ASSERT(0);
  55.  delete tmpBmp;
  56.  }
  57.  }
  58.  }
  59.  else
  60.  return false;
  61.  return true;
  62.  }
  63. bool  CToolbarPlugin::LoadToolbar(CWnd* pParent)
  64. {
  65. typedef void(*LPDLLFUNC_LOADTOOLBAR)(unsigned int, CToolBar* , CWnd* );
  66. typedef HBITMAP(*LPDLLFUNC_GETTOOLBARBITMAP)(LPWORD);
  67. typedef void(*LPDLLFUNC_GETIDS)(unsigned int&, unsigned int&);
  68. LPDLLFUNC_LOADTOOLBAR lpfnDllFuncLoadToolbar = NULL;
  69. LPDLLFUNC_GETTOOLBARBITMAP lpfnDllGetToolbarBitmap = NULL;
  70. LPDLLFUNC_GETIDS  lpfnDllFuncGetIDS = NULL;
  71. lpfnDllFuncLoadToolbar = (LPDLLFUNC_LOADTOOLBAR)::GetProcAddress(m_hInst,"GetToolbar");
  72. if (!lpfnDllFuncLoadToolbar)
  73. {
  74. AfxMessageBox("Function not found in DLL");
  75. return false;
  76. }
  77. lpfnDllGetToolbarBitmap = (LPDLLFUNC_GETTOOLBARBITMAP)::GetProcAddress(m_hInst,"GetToolbarBitmap");
  78. if (!lpfnDllGetToolbarBitmap)
  79. {
  80. AfxMessageBox("Function not found in DLL");
  81. return false;
  82. }
  83. lpfnDllFuncLoadToolbar(pluginToolbarIDStart, &m_toolbar,pParent);
  84. WORD wColor;
  85. HBITMAP  hBmp = lpfnDllGetToolbarBitmap(&wColor);
  86. m_toolbar.LoadHiColor(hBmp,&wColor);
  87. lpfnDllFuncGetIDS = (LPDLLFUNC_GETIDS)::GetProcAddress(m_hInst,"GetFirstAndLastIDs");
  88. lpfnDllFuncGetIDS(m_start_ID,m_end_ID);
  89. pluginToolbarIDStart = m_end_ID+1;
  90. m_reset_names_func = (LPDLLFUNC_RESET_NAMES)::GetProcAddress(m_hInst,"ResetNames");
  91. m_get_button_state_func = (LPDLLFUNC_GET_BUTTON_STATE)::GetProcAddress(m_hInst,"GetButtonState");
  92. m_get_status_bar_message = (LPDLLFUNC_STATUSBAR_STRING)::GetProcAddress(m_hInst,"GetStatusBarMessage");
  93. m_get_tooltip_message=(LPDLLFUNC_TOOLTIP_STRING)::GetProcAddress(m_hInst,"GetTooltipMessage");
  94. m_get_new_commander = (LPDLLFUNC_GET_NEW_COMMANDER)::GetProcAddress(m_hInst,"GetNewCommander");
  95. m_get_edit_commander = (LPDLLFUNC_GET_EDIT_COMMANDER)::GetProcAddress(m_hInst,"GetEditCommander");
  96. m_free_commander = (LPDLLFUNC_FREE_COMMANDER)::GetProcAddress(m_hInst,"FreeCommander");
  97. m_was_load = true;
  98. return true;
  99. }
  100. void  CToolbarPlugin::ResetNames()
  101. {
  102. if (m_reset_names_func)
  103. m_reset_names_func();
  104. }
  105. void CToolbarPlugin::GetToolbarButtonState(unsigned int nID, bool& ch, bool& enbl)
  106. {
  107. if (m_get_button_state_func)
  108. m_get_button_state_func(nID,ch,enbl);
  109. }
  110. CString  CToolbarPlugin::GetStatusBarMessage(unsigned int nID)
  111. {
  112. if (m_get_status_bar_message)
  113. return CString(m_get_status_bar_message(nID));
  114. return CString("");
  115. }
  116. CString  CToolbarPlugin::GetTooltipMessage(unsigned int nID)
  117. {
  118. if (m_get_tooltip_message)
  119. return CString(m_get_tooltip_message(nID));
  120. return CString("");
  121. }
  122. ICommander* CToolbarPlugin::GetNewCommander(unsigned int nID, 
  123. IApplicationInterface* appInt)
  124. {
  125. if (m_get_new_commander)
  126. return m_get_new_commander(nID,appInt);
  127. return NULL;
  128. }
  129. ICommander*  CToolbarPlugin::GetEditCommander(sgCObject* editableObj, 
  130.   IApplicationInterface* appInt)
  131. {
  132. if (m_get_edit_commander)
  133. return m_get_edit_commander(editableObj,appInt);
  134. return NULL;
  135. }
  136. void        CToolbarPlugin::FreeCommander(ICommander* cmndr)
  137. {
  138. if (m_free_commander)
  139. if (!m_free_commander(cmndr))
  140. ASSERT(0);
  141. }