This article is from the Amiga FAQ, by Ignaz Kellerer with numerous contributions by others.
The following function returns the window pointer of a CON window. It can be executed safely under all versions of the Amiga's OS.
struct Window *getConWindowPtr(BPTR fh) { struct Window *w; struct FileHandle *cfh; struct StandardPacket *sp; struct InfoData *id; struct MsgPort *mp;
w = NULL;
if ((cfh = BADDR(fh))->fh_Type != NULL) { if (sp = AllocMem(sizeof (struct StandardPacket), MEMF_PUBLIC | MEMF_CLEAR)) { if (id = AllocMem(sizeof (struct InfoData), MEMF_PUBLIC | MEMF_CLEAR)) { if (mp = CreatePort(NULL, 0)) { sp->sp_Msg.mn_Node.ln_Name = (char *) &sp->sp_Pkt; sp->sp_Pkt.dp_Link = &sp->sp_Msg; sp->sp_Pkt.dp_Port = mp; sp->sp_Pkt.dp_Type = ACTION_DISK_INFO; sp->sp_Pkt.dp_Arg1 = MKBADDR(id);
PutMsg(cfh->fh_Type, &sp->sp_Msg); (void) WaitPort(mp); (void) GetMsg(mp);
if (sp->sp_Pkt.dp_Res1) w = (struct Window *) id->id_VolumeNode;
DeletePort(mp); } FreeMem(id, sizeof (struct InfoData)); } FreeMem(sp, sizeof (struct StandardPacket)); } }
return w; }
Notes: * Accessing a console's window directly may interfere with operations performed by the CON handler. Be careful!
* To obtain the window pointer of a CLI's console, pass the FileHandle returned by Open("*", MODE_OLDFILE) to the above function.
* The result of the above function may well be NULL, e.g. in case of an AUX handler or if an AUTO CON handler is unable to open its window.
* Sending an ACTION_DISK_INFO packet to an AUTO CON handler (2.0+) causes its window to lose its special AUTO properties (i.e. it can no longer be closed at any time by clicking on its Close gadget), as the window pointer returned in id_VolumeNode must remain valid from now on.
* All in all: Don't use this function. :-)
For more information, please refer to pages 273, 276, 435, 463, 485, and 629 in "The Amiga Guru Book" (see Manuals).
Ralph Babel, rbabel@babylon.pfm-mainz.de
 
Continue to: