home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_progs / prog_c / suplib.lzh / SUPLIB / SRC / CONWIN.C < prev    next >
C/C++ Source or Header  |  1991-08-16  |  2KB  |  77 lines

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