If you are getting started with the Non-COM property system in AutoCAD, please refer to this DevTV by my colleague, Adam Nagy. In this post, we will look at the changes required for displaying a localized property name using the Non-COM property system.
1) The first step is to ensure that strings are fetched from the string table. To associate the ID of the string with the property, instantiate the "AcRxLocalizedNameAttribute" class and add it to the attributes collection of the property. This can be done in the property constructor.
MyDoubleProperty::MyDoubleProperty() :
AcRxProperty(_T("My Double Property"),
AcRxValueType::Desc<double>::value())
{
// ...
AcRxLocalizedNameAttribute *pAttrib
= new AcRxLocalizedNameAttribute(IDS_MYDOUBLE_PROPERTY);
attributes().add(pAttrib);
}
2) Implement a class derived from "AcRxResourceLoader" and override the "subLoadString" method. Ensure that your implementation in this method returns the localized string corresponding to the ID passed in as a parameter.
// Our resource loader class
class MyResourceLoader : public AcRxResourceLoader
{
// Return the string fetched from the string table
virtual Acad::ErrorStatus subLoadString
(
unsigned int id,
unsigned int sourceHint,
AcString& result
)
{
if (sourceHint)
return AcRxResourceLoader::loadString
(
AcRxObject::desc(),
id,
sourceHint,
result
);
const int size = 1024;
ACHAR buf[size];
int ret = ::LoadString(_hdllInstance, id, buf, size);
if (ret==0)
return Acad::eKeyNotFound;
ASSERT(ret!=size-1);
result = buf;
return Acad::eOk;
}
};
3) Create a global instance of the resource loader class that we created in Step 2.
// Create a global instance of our resource loader
MyResourceLoader _mrl;
4) Add the global instance of the resouce loader class that we created in Step 3 as a protocol extension object to the AcRxClass of the property. A suitable place to do this is the "On_kInitAppMsg" method of your application.
virtual AcRx::AppRetCode On_kInitAppMsg (void *pkt)
{
AcRx::AppRetCode retCode
= AcRxArxApp::On_kInitAppMsg (pkt);
// Add the global instance of our resouce loader
// as a protocol extension object to the AcRxClass
// of the property.
MyDoubleProperty::desc()->addX
(
AcRxResourceLoader::desc(),
&_mrl
);
return (retCode) ;
}
We now have everything in place to display the localized name for our property.
Here is a sample project with these changes. This project does not implement resource dlls and so if you need help with it, you may refer to this documentation :