Advertisement
Guest User

Print position and size of console window (Amiga)

a guest
Jun 17th, 2019
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.26 KB | None | 0 0
  1. #include <exec/types.h>
  2. #include <libraries/dos.h>
  3. #include <libraries/dosextens.h>
  4. #include <intuition/intuition.h>
  5. #include <proto/exec.h>
  6. #include <stdio.h>
  7.  
  8. #define APTR_TO_BPTR(x) ((ULONG)x >> 2)
  9.  
  10. int main()
  11. {
  12.     struct Process *process = (struct Process *)FindTask(NULL);
  13.     struct MsgPort *con_mp = (struct MsgPort *)process->pr_ConsoleTask;
  14.     struct MsgPort *reply_port = CreatePort(NULL, 0);
  15.     struct InfoData *id = AllocMem(sizeof(struct InfoData), 0);
  16.  
  17.     struct StandardPacket sp;
  18.     sp.sp_Msg.mn_Node.ln_Type = NT_MESSAGE;
  19.     sp.sp_Msg.mn_Node.ln_Pri = 0;
  20.     sp.sp_Msg.mn_Node.ln_Name = (char *)&sp.sp_Pkt;
  21.     sp.sp_Msg.mn_Length = sizeof(struct StandardPacket);
  22.     sp.sp_Msg.mn_ReplyPort = reply_port;
  23.     sp.sp_Pkt.dp_Link = &sp.sp_Msg;
  24.     sp.sp_Pkt.dp_Port = reply_port;
  25.     sp.sp_Pkt.dp_Type = ACTION_DISK_INFO;
  26.     sp.sp_Pkt.dp_Arg1 = APTR_TO_BPTR(id);
  27.     sp.sp_Pkt.dp_Arg2 = 0;
  28.     sp.sp_Pkt.dp_Arg3 = 0;
  29.     PutMsg(con_mp, &sp.sp_Msg);
  30.  
  31.     Wait(1L << reply_port->mp_SigBit);
  32.     GetMsg(reply_port);
  33.  
  34.     struct Window *win = (struct Window *)id->id_VolumeNode;
  35.  
  36.     printf("Window position: (%3d, %3d)\n", win->LeftEdge, win->TopEdge);
  37.     printf("Window size:     (%3d, %3d)\n", win->Width, win->Height);
  38.  
  39.     FreeMem(id, sizeof(struct InfoData));
  40.     DeletePort(reply_port);
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement