Quote:
Originally Posted by hadescik
I want to access the CIFflorian0 object from the outside and apply SetText to the CIFStatic fields inside, but I could not access it from the outside.
How can I access the CIFflorian0 instance from outside?
|
You can get a pointer to the window (and other windows) with m_IRM of CGInterface.
Code:
CIFflorian0 *pWnd = g_pCGInterface->m_IRM.GetResObj<CIFflorian0>(1338, 1);
However, I would recommend to make a function for retrieving the pointer instead of using m_IRM directly.
Code:
CIFflorian0 *pWnd = g_pCGInterface->GetFlorian0Window();
Code:
CIFflorian0 *CGInterface::GetFlorian0Window() {
return m_IRM.GetResObj<CIFflorian0>(1338, 1);
}
Now you have a pointer to the window and you can access all the members of the window with it.
You can get a pointer to the controls with m_IRM of the Window.
Code:
CIFflorian0 *pWnd = g_pCGInterface->GetFlorian0Window();
CIFStatic *pLabel = pWnd->m_IRM.GetResObj<CIFStatic>(1234, 1);
pLabel->SetText(L"Hello World");
However, I would recommend hiding this functionality inside another function so the code stays readable.
Code:
CIFflorian0 *pWnd = g_pCGInterface->GetFlorian0Window();
pWnd->SetLabelText(L"Hello World");
Code:
void CIFflorian0::SetLabelText(const wchar_t *text) {
m_IRM.GetResObj<CIFStatic>(1234, 1)->SetText(text);
}
If you're using the controls on the window frequently, you can save time by storing the pointer to the control in the class instead of calling GetResObj every time. An example can be found here:
[Only registered and activated users can see links. Click Here To Register...]