私はこの[不完全な]関数を持っています:
void EditorWindow::OnLMClick(SObjectType sOT, short xPos, short yPos)
{
SObject* pSObject;
int nElements;
switch(sOT)
{
case SOT_Tile: nElements=TILETYPE_COUNT; pSObject = pSOTile[0]; break;
case SOT_Surface: nElements=SURFACEBMP_COUNT; break;
case SOT_Object: nElements=OBJECTBMP_COUNT; break;
case SOT_Edit: nElements=EDITBMP_COUNT; break;
default: MessageBox(NULL,"Switch does not include this SObjectType","Error in EditorWindow::OnLMClick()",NULL); return;
}
// From there on, pSObject may be pointing to any array of its child classes
for (int n = 0; n<nElements; n++)
{
if (xPos > pSObject->coor.X &&
xPos < pSObject->coor.X + pSObject->size.Width &&
yPos > pSObject->coor.Y &&
yPos < pSObject->coor.Y + pSObject->size.Height)
{
selectedItemRect.left = pSObject->coor.X;
selectedItemRect.top = pSObject->coor.Y + pSObject->size.Width;
selectedItemRect.right = pSObject->coor.X;
selectedItemRect.bottom = pSObject->coor.Y + pSObject->size.Height;
}
*(pSObject++);
}
Display();
}
pSObject が配列 pSOTile の次の要素を指すようにしようとしています。どうやってやるの?関数を更新すると、pSObject は最終的に SOTile 以外の子を指す可能性があることに注意してください。