Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:sdksamples:pluginsettings [2015/09/14] (current)
Line 1: Line 1:
 +====== Saving Persistent Plug-in Settings ======
 +====== C++ ======
 +> **Summary:​** //Discusses how to save plug-in settings to the Registry.//
 +
 +=====Question=====
 +My plug-in maintains a number of settings that I would like to retain between sessions. Is there an easy way for me to do this? How can I have these setting migrate from one Rhino service release to another?
 +
 +=====Answer=====
 +You can load and save persistent plug-in setting from and to the Registry using the **CRhinoPlugIn::​LoadProfile** and **CRhinoPlugIn::​SaveProfile** virtual functions. For information on these virtual function, see **rhinoSdkPlugIn.h**.
 +
 +=====Example=====
 +
 +Lets say we have a sample plug-in class declaration that looks something like the following:
 +
 +
 +<code c++>
 +class CTestPlugIn : public CRhinoUtilityPlugIn
 +{
 +public:
 +  CTestPlugIn();​
 +  ~CTestPlugIn();​
 +
 +  // Required overrides
 +  const wchar_t* PlugInName() const;
 +  const wchar_t* PlugInVersion() const;
 +  GUID PlugInID() const;
 +  BOOL OnLoadPlugIn();​
 +  void OnUnloadPlugIn();​
 +
 + ​private:​
 +  ON_wString m_plugin_version;​
 +
 +  // Persistent data
 +  bool m_value0;
 +  int m_value1;
 +  double m_value2;
 +  ON_wString m_value3;
 +};
 +
 +</​code>​
 +Simply, overload the **CRhinoPlugIn::​LoadProfile** and **CRhinoPlugIn::​SaveProfile** virtual functions by adding the the following public declarations to our plug-in class:
 +
 +
 +<code c++>
 +void LoadProfile( LPCTSTR lpszSection,​ CRhinoProfileContext&​ pc );
 +void SaveProfile( LPCTSTR lpszSection,​ CRhinoProfileContext&​ pc );
 +
 +</​code>​
 +Then, provide the definition:
 +
 +
 +<code c++>
 +void CTestPlugIn::​LoadProfile( LPCTSTR lpszSection,​ CRhinoProfileContext&​ pc )
 +{
 +  pc.LoadProfileBool( lpszSection,​ L"​value0",​ &​m_value0 );
 +  pc.LoadProfileInt( lpszSection,​ L"​value1",​ &​m_value1 );
 +  pc.LoadProfileDouble( lpszSection,​ L"​value2",​ &​m_value2 );
 +  pc.LoadProfileString( lpszSection,​ L"​value3",​ m_value3 );
 +}
 +
 +void CTestPlugIn::​SaveProfile( LPCTSTR lpszSection,​ CRhinoProfileContext&​ pc )
 +{
 +  pc.SaveProfileBool( lpszSection,​ L"​value0",​ m_value0 );
 +  pc.SaveProfileInt( lpszSection,​ L"​value1",​ m_value1 );
 +  pc.SaveProfileDouble( lpszSection,​ L"​value2",​ m_value2 );
 +  pc.SaveProfileString( lpszSection,​ L"​value3",​ m_value3 );
 +}
 +
 +</​code>​
 +That's it! Your data is now saved at the following location in the Registry:
 +
 +
 +<code c++>
 +HKEY_CURRENT_USER\Software\McNeel\Rhinoceros\4.0\<​scheme>​\Plug-ins\<​plugin_id>​\Settings
 +
 +</​code>​
 +
 +
 +{{tag>​Developer cplusplus}}
  
developer/sdksamples/pluginsettings.txt ยท Last modified: 2015/09/14 (external edit)