home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 171.lha / SupLib / conwin.c < prev    next >
C/C++ Source or Header  |  1988-04-28  |  3KB  |  90 lines

  1.  
  2. /*
  3.  *  CONWIN.C
  4.  *
  5.  *  Win = GetConWindow()
  6.  *
  7.  *  Returns console window associated with the current task or NULL if
  8.  *  no console task associated.
  9.  *
  10.  *  The intuition.library and graphics.library must be openned.
  11.  */
  12.  
  13. #include <exec/types.h>
  14. #include <exec/memory.h>
  15. #include <intuition/intuition.h>
  16. #include <libraries/dos.h>
  17. #include <libraries/dosextens.h>
  18.  
  19. #define BTOC(bptr)    ((long)(bptr) << 2)
  20. #define CTOB(cptr)    ((long)(cptr) >> 2)
  21.  
  22. typedef struct Task          TASK;
  23. typedef struct Process          PROC;
  24. typedef struct StandardPacket STDPKT;
  25. typedef struct MsgPort          MSGPORT;
  26. typedef struct Window          WIN;
  27. typedef struct InfoData       INFODATA;
  28.  
  29. extern TASK *FindTask();
  30. extern void *AllocMem();
  31.  
  32. /*
  33.  *  GETCONWINDOW()
  34.  *
  35.  *  Return the window used by the console of the current process.  We can
  36.  *  use our process's message port as the reply port since it is a
  37.  *  synchronous packet (we wait for the result to come back).  WARNING:
  38.  *  This routine does not check if the 'console' of the current process
  39.  *  is really a console device.
  40.  *
  41.  *  The DISK_INFO packet is sent to the console device.  Although this
  42.  *  packet is normally used to retrieve disk information from disk
  43.  *  devices, the console device recognizes the packet and places a pointer
  44.  *  to the window in id_VolumeNode of the infodata structure.  A pointer
  45.  *  to the console unit is also placed in id_InUse of the infodata structure.
  46.  */
  47.  
  48. WIN *
  49. GetConWindow()
  50. {
  51.     PROC    *proc;
  52.     STDPKT    *packet;
  53.     INFODATA    *infodata;
  54.     long    result;
  55.     WIN     *win;
  56.  
  57.     proc   = (PROC *)FindTask(NULL);
  58.     if (!proc->pr_ConsoleTask)
  59.     return(NULL);
  60.     /*
  61.      *    NOTE: Since DOS requires the packet and infodata structures to
  62.      *    be longword aligned, we cannot declare them globally or on the
  63.      *    stack (word aligned).  AllocMem() always returns longword
  64.      *    aligned pointers.
  65.      */
  66.  
  67.     packet   = (STDPKT   *)AllocMem(sizeof(STDPKT)  , MEMF_CLEAR|MEMF_PUBLIC);
  68.     infodata = (INFODATA *)AllocMem(sizeof(INFODATA), MEMF_CLEAR|MEMF_PUBLIC);
  69.  
  70.     packet->sp_Msg.mn_Node.ln_Name = (char *)&(packet->sp_Pkt);
  71.     packet->sp_Pkt.dp_Link = &packet->sp_Msg;
  72.     packet->sp_Pkt.dp_Port = &proc->pr_MsgPort;
  73.     packet->sp_Pkt.dp_Type = ACTION_DISK_INFO;
  74.     packet->sp_Pkt.dp_Arg1 = CTOB(infodata);
  75.     PutMsg(proc->pr_ConsoleTask, packet);
  76.     WaitPort(&proc->pr_MsgPort);
  77.     GetMsg(&proc->pr_MsgPort);
  78.  
  79.     result = packet->sp_Pkt.dp_Res1;
  80.     win = (WIN *)infodata->id_VolumeNode;
  81.     /* note: id_InUse holds a pointer to the console unit also */
  82.     FreeMem(packet  , sizeof(STDPKT));
  83.     FreeMem(infodata, sizeof(INFODATA));
  84.     if (!result)
  85.     return(NULL);
  86.     return(win);
  87. }
  88.  
  89.  
  90.