home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frozen Fish 1: Amiga
/
FrozenFish-Apr94.iso
/
bbs
/
alib
/
d1xx
/
d169
/
dillonstuff.lha
/
src
/
suplib
/
conwin.c
< prev
next >
Wrap
C/C++ Source or Header
|
1988-11-22
|
3KB
|
90 lines
/*
* CONWIN.C
*
* Win = GetConWindow()
*
* Returns console window associated with the current task or NULL if
* no console task associated.
*
* The intuition.library and graphics.library must be openned.
*/
#include <exec/types.h>
#include <exec/memory.h>
#include <intuition/intuition.h>
#include <libraries/dos.h>
#include <libraries/dosextens.h>
#define BTOC(bptr) ((long)(bptr) << 2)
#define CTOB(cptr) ((long)(cptr) >> 2)
typedef struct Task TASK;
typedef struct Process PROC;
typedef struct StandardPacket STDPKT;
typedef struct MsgPort MSGPORT;
typedef struct Window WIN;
typedef struct InfoData INFODATA;
extern TASK *FindTask();
extern void *AllocMem();
/*
* GETCONWINDOW()
*
* Return the window used by the console of the current process. We can
* use our process's message port as the reply port since it is a
* synchronous packet (we wait for the result to come back). WARNING:
* This routine does not check if the 'console' of the current process
* is really a console device.
*
* The DISK_INFO packet is sent to the console device. Although this
* packet is normally used to retrieve disk information from disk
* devices, the console device recognizes the packet and places a pointer
* to the window in id_VolumeNode of the infodata structure. A pointer
* to the console unit is also placed in id_InUse of the infodata structure.
*/
WIN *
GetConWindow()
{
PROC *proc;
STDPKT *packet;
INFODATA *infodata;
long result;
WIN *win;
proc = (PROC *)FindTask(NULL);
if (!proc->pr_ConsoleTask)
return(NULL);
/*
* NOTE: Since DOS requires the packet and infodata structures to
* be longword aligned, we cannot declare them globally or on the
* stack (word aligned). AllocMem() always returns longword
* aligned pointers.
*/
packet = (STDPKT *)AllocMem(sizeof(STDPKT) , MEMF_CLEAR|MEMF_PUBLIC);
infodata = (INFODATA *)AllocMem(sizeof(INFODATA), MEMF_CLEAR|MEMF_PUBLIC);
packet->sp_Msg.mn_Node.ln_Name = (char *)&(packet->sp_Pkt);
packet->sp_Pkt.dp_Link = &packet->sp_Msg;
packet->sp_Pkt.dp_Port = &proc->pr_MsgPort;
packet->sp_Pkt.dp_Type = ACTION_DISK_INFO;
packet->sp_Pkt.dp_Arg1 = CTOB(infodata);
PutMsg(proc->pr_ConsoleTask, packet);
WaitPort(&proc->pr_MsgPort);
GetMsg(&proc->pr_MsgPort);
result = packet->sp_Pkt.dp_Res1;
win = (WIN *)infodata->id_VolumeNode;
/* note: id_InUse holds a pointer to the console unit also */
FreeMem(packet , sizeof(STDPKT));
FreeMem(infodata, sizeof(INFODATA));
if (!result)
return(NULL);
return(win);
}