Opps, sorry, forgot about that
It's taken from a XML file. (Using TinyXMl). This codes gets the title, and sets it:
Code:
// XML
TiXmlDocument *xmlDoc = new TiXmlDocument(szFileName);
if (!xmlDoc->LoadFile())
{
MessageBox(hClient, "XML file load failed.", "Oh Oh...",MB_ICONEXCLAMATION | MB_OK);
return 0;
}
// Get root
TiXmlElement* xCircuit = xmlDoc->FirstChildElement("circuit");
if (!xCircuit)
{
MessageBox(hClient, "XML root circuit element couldn't be found", "Oh Oh...",MB_ICONEXCLAMATION | MB_OK);
xmlDoc->Clear();
delete xmlDoc;
return 0;
}
//--- Get doc data --------------------------------------------------//
TiXmlElement* xDoc = XMLGetElement(xCircuit, "doc");
// try for the title?
// IT FOOCKING WELL WORKS!
TiXmlElement* xTitle = XMLGetElement(xDoc, "title");
CircuitData.title = XMLStringVal(xTitle);
Using this two XML wrapper functions:
Code:
//------------------------------------------------------------------------------------//
// XMLGetElement()
//------------------------------------------------------------------------------------//
TiXmlElement* XMLGetElement(TiXmlElement* xParent, const char* ElementName)
{
TiXmlElement* xElement = xParent->FirstChildElement(ElementName);
if (!xElement)
{
MessageBox(hClient, strcat("XML data couldn't be found for: ", ElementName), "Oh Oh...",MB_ICONEXCLAMATION | MB_OK);
return 0;
}
return xElement;
}
//------------------------------------------------------------------------------------//
//------------------------------------------------------------------------------------//
// XMLStringVal()
//------------------------------------------------------------------------------------//
const char * XMLStringVal(TiXmlElement* xElement)
{
const char *ElementValue = (xElement->FirstChild())->Value();
if (!ElementValue)
{
MessageBox(hClient, "Error extracting XML string value", "Oh Oh...",MB_ICONEXCLAMATION | MB_OK);
return 0;
}
return ElementValue;
}
//------------------------------------------------------------------------------------//
After the title is set in CircuitData.title, the CircuitData struct gets passed to a function to create the doc:
Code:
hOpen = MakeNewDoc(hClient, CircuitData);
And heres that function:
Code:
HWND MakeNewDoc(HWND hClient, Circuit CircuitData)
{
MDICREATESTRUCT mcs;
HWND hChild;
// temp
COLORREF BackgroundColor = DOC_DEF_BGCOLOR;
mcs.szTitle = CircuitData.title;
mcs.szClass = CHILD_CLASS_NAME;
mcs.hOwner = GetModuleHandle(NULL);
mcs.x = CW_USEDEFAULT;
mcs.cx = CircuitData.size.width + (DOC_BORDER*2);
mcs.y = CW_USEDEFAULT;
mcs.cy = CircuitData.size.height + (DOC_BORDER*2) + 25; // +25 for title bar etc..
mcs.style = MDIS_ALLCHILDSTYLES;
mcs.lParam = NumCircuits;
hChild = (HWND)SendMessage(hClient, WM_MDICREATE, 0, (LONG)&mcs);
if(!hChild)
{
MessageBox(hClient, "MDI Child creation failed.", "Oh Oh...",MB_ICONEXCLAMATION | MB_OK);
}
// Add to circuit count
CircuitData.handle = hChild;
circuits[NumCircuits] = CircuitData;
NumCircuits++;
return hChild;
}
Now setting the Window title using the CircuitData.title works there, but in the WM_PAINT, when I call the PaintBoard function above, the title is messed up.
EDIT: And heres the function I call to get the circuit data in WM_PAINT:
Code:
Circuit* GetCircuitData(HWND hTest)
{
for (int i = 0; i < NumCircuits; ++i)
{
if (circuits[i].handle == hTest)
{
return &circuits[i];
}
}
const char *msg = "GetCircuitData() failed";
MessageBoxA(0, msg, msg, MB_OK);
return 0;
}
//------
Cheers