Hello Bill

Talking to myself again but then no one else seemed to know the answer to my
question.

So if anyone else wants to know how to find out if a particular object os of
a secific type, in this case a BetterString object then see below.


On 02/09/2010, Bill Eaves wrote:
> Hello

> I cannot find anything in the docs so ask for guidance.

> Given an object pointer, (eg the Object *) for an object, how do I find
> out what type of object it is, I guess this is the class it belongs to.


After a bit of delving in headers etc I was able to come up with the
following solution.



======================================

HOOKFUNCTION VOID BetterStringFunc(REG(a0, struct Hook *hook), REG(a2,
Object *obj), REG(a1, ULONG *arg))
{

     BOOL betterstringshortcut=FALSE;
     Object *activewindow=NULL;
     Object *window;
     Object *actObj;
     struct IClass *clpointer;

     // Get Active window
     struct Node *node = ((struct List *)
xget(MUI_App,MUIA_Application_WindowList))->lh_Head;
     while ((window = NextObject ((Object**)&node)) && (activewindow==NULL))
     {
          if((BOOL)xget(window,MUIA_Window_Activate)) activewindow=window;
     }
    if(activewindow!=NULL)
    {
        // Get window active object here
        if(actObj = (Object *)xget(activewindow, MUIA_Window_ActiveObject))
        {
            //Check if Active Object is a betterstring object
            clpointer=OCLASS(actObj);
            if(clpointer->cl_ID) if
(!strcmp(clpointer->cl_ID,"BetterString.mcc")) betterstringshortcut=TRUE;
        }
    }
    switch (arg[0])
    {
        case MENU_CONTROL:
            if (betterstringshortcut) DoMethod(actObj,
MUIM_BetterString_DoAction, MUIV_BetterString_DoAction_Copy);
            else DoMethod(MUI_App,MUIM_CallHook,&ControlHook);
            break;
        case MENU_PLANET:
            if (betterstringshortcut) DoMethod(actObj,
MUIM_BetterString_DoAction, MUIV_BetterString_DoAction_Cut);
            else set(MUI_ChoosePlanetWindow, MUIA_Window_Open, TRUE);
            break;
        case MENU_FIELD:
            if (betterstringshortcut) DoMethod(actObj,
MUIM_BetterString_DoAction, MUIV_BetterString_DoAction_Paste);
            else set(MUI_FieldWindow, MUIA_Window_Open, TRUE);
            break;
        case MENU_DISPLAY:
            if (betterstringshortcut) DoMethod(actObj,
MUIM_BetterString_DoAction, MUIV_BetterString_DoAction_DecreaseNum);
            else set(MUI_DisplayWindow, MUIA_Window_Open, TRUE);
            break;
        case MENU_ICONIFY:
            if (betterstringshortcut) DoMethod(actObj,
MUIM_BetterString_DoAction, MUIV_BetterString_DoAction_IncreaseNum);
            else set(MUI_App,MUIA_Application_Iconified,TRUE);
            break;
        case MENU_QUIT:
            if (betterstringshortcut) DoMethod(actObj,
MUIM_BetterString_DoAction, MUIV_BetterString_DoAction_Revert);
            else DoMethod(MUI_App,MUIM_Application_ReturnID,
MUIV_Application_ReturnID_Quit);
            break;
    };


}
MakeStaticHook(BetterStringHook, BetterStringFunc); 


======================================

Regards,

Bill.



------------------------------------

Visit http://www.amiga.dk/tumult for MUI-related
information, especially about MUI custom classes.Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/MUI/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/MUI/join
    (Yahoo! ID required)

<*> To change settings via email:
    [email protected] 
    [email protected]

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/

Reply via email to