home *** CD-ROM | disk | FTP | other *** search
/ Software 2000 / Software 2000 Volume 1 (Disc 1 of 2).iso / utilities / u620.dms / in.adf / Tips&Tricks / DOS-Intuition / GetWin.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-29  |  2.1 KB  |  97 lines

  1.  
  2. #include <exec/types.h>
  3. #include <exec/memory.h>
  4. #include <dos/dos.h>
  5. #include <dos/dosextens.h>
  6. #include <intuition/intuition.h>
  7. #include <clib/dos_protos.h>
  8. #include <clib/exec_protos.h>
  9. #include <clib/alib_protos.h>
  10.  
  11.  
  12. #define AllocPacket() (struct StandardPacket *)\
  13.                        AllocMem(sizeof(struct StandardPacket),\
  14.                    MEMF_CLEAR|MEMF_PUBLIC)
  15.  
  16.  
  17. LONG MyDoPkt(struct MsgPort *port,
  18.          LONG type,
  19.              LONG arg1,
  20.              LONG arg2,
  21.              LONG arg3,
  22.              LONG arg4,
  23.              LONG arg5)
  24. {
  25.  struct StandardPacket *packet;
  26.  struct MsgPort *reply;
  27.  LONG res;
  28.  
  29.  if(!port || !(reply = CreatePort(NULL,0)))
  30.     return NULL;
  31.  
  32.  if(!(packet = AllocPacket())) {
  33.     DeletePort(reply);
  34.     return NULL;
  35.  }
  36.  
  37.  packet->sp_Pkt.dp_Arg1 = arg1;
  38.  packet->sp_Pkt.dp_Arg2 = arg2;
  39.  packet->sp_Pkt.dp_Arg3 = arg3;
  40.  packet->sp_Pkt.dp_Arg4 = arg4;
  41.  packet->sp_Pkt.dp_Arg5 = arg5;
  42.  packet->sp_Pkt.dp_Type = type;
  43.  packet->sp_Pkt.dp_Link = &packet->sp_Msg;
  44.  packet->sp_Pkt.dp_Port = reply;
  45.  packet->sp_Msg.mn_Node.ln_Name = (char *)&(packet->sp_Pkt);
  46.  
  47.  PutMsg(port,(struct Message *)packet);
  48.  WaitPort(reply);
  49.  GetMsg(reply);
  50.  
  51.  res = packet->sp_Pkt.dp_Res1;
  52.  FreeMem(packet,sizeof(struct StandardPacket));
  53.  DeletePort(reply);
  54.  return res;
  55. }
  56.  
  57.  
  58. struct MsgPort *MyGetConsoleTask()
  59. {
  60.  struct Process *myproc = (struct Process *)
  61.                           FindTask(NULL);
  62.  
  63.  if(myproc->pr_Task.tc_Node.ln_Type == NT_PROCESS)
  64.     return myproc->pr_ConsoleTask;
  65.  else
  66.     return NULL;
  67. }
  68.  
  69.  
  70. #define AllocID() (struct InfoData *)\
  71.                   AllocMem(sizeof(struct InfoData),\
  72.                   MEMF_CLEAR|MEMF_PUBLIC)
  73.  
  74. struct Window *GetWin(BPTR fh)
  75. {
  76.  struct FileHandle *handle = BADDR(fh);
  77.  struct InfoData *info;
  78.  LONG result;
  79.  struct Window *win;
  80.  
  81.  if(handle->fh_Type < 0)
  82.     return NULL;
  83.  if(!(info = AllocID()))
  84.     return NULL;
  85.  
  86.  result = MyDoPkt(handle->fh_Type,
  87.                   ACTION_DISK_INFO,
  88.                   MKBADDR(info),
  89.                   0,0,0,0);
  90.  win = (struct Window *)info->id_VolumeNode;
  91.  FreeMem(info,sizeof(struct InfoData));
  92.  
  93.  return result ? win : NULL;
  94. }
  95.  
  96.  
  97.