If you want to write the xml file of different encoding using MSXL, you need to add a precessing instruction node to you xml document. Here is the code in c++ for encoding UTF-16.
// pXMLDOMDoc is the IXMLDOMDocument pointer
IXMLDOMNode* pNode = NULL;
IXMLDOMProcessingInstruction* pInstruct = NULL;
USES_CONVERSION;
BSTR value = T2BSTR(_T("version='1.0' encoding='UTF-16'"));
BSTR xml = T2BSTR(_T("xml"));
// Create the processing instruction node
HRESULT hr = pXMLDOMDoc->createProcessingInstruction( xml, value, &pInstruct);
if(SUCCEEDED(hr) && pInstruct)
{
// Append the processing instruction node to the XML document
pXMLDOMDoc->appendChild(pInstruct, &pNode);
HCOM_Release(pInstruct);
HCOM_Release(pNode);
}
SysFreeString(value);
SysFreeString(xml);
// Set the root node as reference element of the XML document
if(SUCCEEDED(hr) && pInstruct)
{
IXMLDOMElement* pRootNode = NULL;
pXMLDOMDoc->get_documentElement(&pRootNode);
if(pRootNode != NULL)
pXMLDOMDoc->putref_documentElement(pRootNode);
}
// Now save the xml
pXMLDOMDoc->save(VARIANT_FromBSTR(bstrFileName));
Wednesday, October 31, 2007
Saturday, October 27, 2007
UTF-8, UTF-16, UTF-32 & BOM
The following sites contain very useful information:
http://unicode.org/faq/utf_bom.html#28
http://msdn2.microsoft.com/en-us/library/ms776429.aspx
http://unicode.org/faq/utf_bom.html#28
http://msdn2.microsoft.com/en-us/library/ms776429.aspx
Wednesday, October 24, 2007
Changing the caption of a floating toolbar
Before we go through the code we just need to know the window layout of a floating toolbar.
Here it is:
CToolbar
CDockBar
CMiniDockFrameWnd
Suppose, we have a toolbar pointer pToolBar. Here is the code to change its caption.
pToolBar->SetWindowText(szToolBarName);
CMiniDockFrameWnd *pParentFrame;
pParentFrame = DYNAMIC_DOWNCAST(CMiniDockFrameWnd,
pToolBar->GetParentFrame));
if(pParentFrame != NULL)
{
pParentFrame->m_wndDockBar.SetWindowText(szToolBarName);
pParentFrame->SetWindowText(szToolBarName);
}
Here it is:
CToolbar
CDockBar
CMiniDockFrameWnd
Suppose, we have a toolbar pointer pToolBar. Here is the code to change its caption.
pToolBar->SetWindowText(szToolBarName);
CMiniDockFrameWnd *pParentFrame;
pParentFrame = DYNAMIC_DOWNCAST(CMiniDockFrameWnd,
pToolBar->GetParentFrame));
if(pParentFrame != NULL)
{
pParentFrame->m_wndDockBar.SetWindowText(szToolBarName);
pParentFrame->SetWindowText(szToolBarName);
}
Change or modify the value of a member of class by another class
I think using an interface to change or modify the value of a member of class by another class, may be better solution. Here are an example of such design.
class IModifier {
virtual void Modify( int &x ) = 0;
};
class A {
private:
int x;
public:
void ModifyX( IModifier* pModifier)
{
pModifier->Modify(x);
}
}
class B : public IModifier {
public:
void Modify( int &x )
{
x = 10;
}
}
class IModifier {
virtual void Modify( int &x ) = 0;
};
class A {
private:
int x;
public:
void ModifyX( IModifier* pModifier)
{
pModifier->Modify(x);
}
}
class B : public IModifier {
public:
void Modify( int &x )
{
x = 10;
}
}
Subscribe to:
Posts (Atom)