Article View: comp.sys.amiga.tech
Article #4460Re: Finding Windows
From: Deven T. Corzine
Date: Fri, 20 Jul 1990 16:14
Date: Fri, 20 Jul 1990 16:14
89 lines
4153 bytes
4153 bytes
In article <1990Jul19.184648.11351@helios.physics.utoronto.ca>
elrick@physics.utoronto.ca (Bruce Elrick) writes:
Bruce> If I open a window using the dos Open() command, how can I find the
Bruce> window structure (for, say, Windowtofront()) from the filehandle?
On 20 Jul 90 07:18:22 GMT, peterk@cbmger.UUCP (Peter Kittel GERMANY) said:
Peter> I only know a dirty way that won't be totally waterproof: If
Peter> the window is on Workbench then find Intuitionbase, scan the
Peter> pointer chain of screens for the Workbench screen and take the
Peter> pointer chain for windows inside this screen to search for your
Peter> one. To identify your window you could search for your UNIQUE
Peter> window title string. And this is already the caveat: You must
Peter> be ABSOLUTELY sure that no other window on this screen has the
Peter> same title string. As I said, a rather dirty way.
You're right, that is a rather dirty way. There is, however, a better
way. You can send an ACTION_DISK_INFO packet to the CON: handler and
it will return the address of the window in the Info structure.
Here's a routine which will return a Window pointer to the current
"console" window the one referred to by "*":
--------
/* findwindow.c - utility routine to find window of a CLI. */
#include <exec/types.h>
#include <exec/memory.h>
#include <proto/exec.h>
#include <proto/dos.h>
struct Window __regargs *FindWindow()
{
register struct DosLibrary *DOSBase;
register struct Window *win;
register struct Process *proc;
register struct CommandLineInterface *cli;
register struct InfoData *id;
register struct StandardPacket *pkt;
register struct FileHandle *fh;
register BPTR file;
register long ret1,ret2;
if (DOSBase=(struct DosLibrary *) OpenLibrary(DOSNAME,0)) {
if (id=(struct InfoData *)
AllocMem(sizeof(struct InfoData),MEMF_PUBLIC|MEMF_CLEAR)) {
if (pkt=(struct StandardPacket *)
AllocMem(sizeof(struct StandardPacket),MEMF_PUBLIC|MEMF_CLEAR)) {
proc=(struct Process *) FindTask(NULL);
if (cli=(struct CommandLineInterface *) (proc->pr_CLI<<2)) {
ret1=cli->cli_ReturnCode;
ret2=cli->cli_Result2;
if (file=Open("*",MODE_NEWFILE)) {
if (IsInteractive(file)) {
pkt->sp_Msg.mn_Node.ln_Name=(char *) &(pkt->sp_Pkt);
pkt->sp_Pkt.dp_Link=&(pkt->sp_Msg);
pkt->sp_Pkt.dp_Port=&(proc->pr_MsgPort);
pkt->sp_Pkt.dp_Type=ACTION_DISK_INFO;
pkt->sp_Pkt.dp_Arg1=((ULONG) id)>>2;
fh=(struct FileHandle *) (file<<2);
PutMsg(fh->fh_Type,(struct Message *) pkt);
WaitPort(&(proc->pr_MsgPort));
GetMsg(&(proc->pr_MsgPort));
win=(struct Window *) id->id_VolumeNode;
}
Close(file);
}
cli->cli_Result2=ret2;
cli->cli_ReturnCode=ret1;
}
FreeMem(pkt,sizeof(struct StandardPacket));
}
FreeMem(id,sizeof(struct InfoData));
}
CloseLibrary((struct Library *) DOSBase);
}
return(win);
}
--------
Enjoy.
Deven
--
Deven T. Corzine Internet: deven@rpi.edu, shadow@pawl.rpi.edu
Snail: 2214 12th St. Apt. 2, Troy, NY 12180 Phone: (518) 271-0750
Bitnet: deven@rpitsmts, userfxb6@rpitsmts UUCP: uunet!rpi!deven
Simple things should be simple and complex things should be possible.
Technical Details
Message-ID:
<DEVEN.90Jul20121451@netserv2.rpi.edu>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!snorkelwacker!usc!zaphod.mps.ohio-state.edu!rpi!netserv2!devenReferences:
<1990Jul19.184648.11351@helios.physics.utoronto.ca> <296@cbmger.UUCP>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!snorkelwacker!usc!zaphod.mps.ohio-state.edu!rpi!netserv2!deven From: deven@rpi.edu (Deven T. Corzine) Newsgroups: comp.sys.amiga.tech Subject: Re: Finding Windows Message-ID: <DEVEN.90Jul20121451@netserv2.rpi.edu> Date: 20 Jul 90 16:14:05 GMT References: <1990Jul19.184648.11351@helios.physics.utoronto.ca> <296@cbmger.UUCP> Organization: Rensselaer Polytechnic Institute, Troy, NY Lines: 89 In-Reply-To: peterk@cbmger.UUCP's message of 20 Jul 90 07:18:22 GMT