🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.amiga.tech
Article #4464

Re: Finding Windows

#4464
From: Dave Haynie
Date: Fri, 20 Jul 1990 15:38
106 lines
3773 bytes
In article <1990Jul19.184648.11351@helios.physics.utoronto.ca> elrick@physics.utoronto.ca (Bruce Elrick) writes:
>
>  Question:

>If I open a window using the dos Open() command, how can I find the
>window structure (for, say, Windowtofront()) from the filehandle?

Here's about the best I've done.  I don't how you can get a window directly
from a filehandle, since a file isn't necessarily associated with any 
window.  However, you can get a window pointer if you know the console
associated with that window.  Here's an excerpt from SetCPU V2.7 that does
this:


// =======================================================================

// From SetFont 2.7 - by Dave Haynie

#include <exec/types.h>
#include <exec/io.h>
#include <exec/ports.h>
#include <exec/memory.h>
#include <graphics/gfxbase.h>
#include <graphics/text.h>
#include <graphics/rastport.h>
#include <libraries/dos.h>
#include <libraries/dosextens.h>
#include <intuition/intuition.h>
#include <string.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>

// =========================================================================

// Miscellaneous stuff.

inline MsgPort *contask(MsgPort *port) {
   return (MsgPort *) ((port->mp_SigTask->ln_Type == NT_PROCESS)
          ? ((Process *)port->mp_SigTask)->pr_ConsoleTask 
          : NULL);
}

// =========================================================================
 
// These classes manage the places that fonts are hidden.

// This is the basic place node

class PlaceNode : public Node {
   private:
      static Window *pwin;
      static Screen *pscr;

   public:
      PlaceNode();      
      PlaceNode *next() { return (PlaceNode *)Node::next(); }

      void testwindow() { if (!pwin) fail("Window not found\n"); }
      void testscreen() { if (!pscr) fail("Screen not found\n"); }

      Window *window()  { return pwin; }
      Screen *screen()  { return pscr; }

      virtual void set(SmartFont *f) {
         testwindow();
         SetFont(window()->graphic(),f->font());
         printf("\033c");  			// Re-init window's conunit
         (void)flushall();
      }
};

// Initialize the static stuff, once.

PlaceNode::PlaceNode() {
   if (pwin) return;

   StandardPacket *packet = new StandardPacket;
   InfoData *info = new InfoData;   
   MsgPort *port = new StdPort;

  // Find the window
   if (contask(port)) {
      packet->sendio(contask(port),port,ACTION_DISK_INFO,CADDR(info));
      (void)port->wait();
      pwin = (Window *)info->id_VolumeNode;
   } else 
      pwin = NULL;
   delete port;
   delete info;
   delete packet;

  // Find the screen
   pscr = (pwin) ? pwin->screen() : NULL;
}

Or, in english, if you send the ACTION_DISK_INFO packet to a console, the
console's window is returned as the id_VolumeNode field of the InfoData
structure.  You can't the console task from a FileHandle, but you can
get it from a FileLock.  Note that the Lock() function returns a BPTR to
a FileLock, so you'll have to convert this into a 680x0 pointer before
examining the fields.
-- 
Dave Haynie Commodore-Amiga (Amiga 3000) "The Crew That Never Rests"
   {uunet|pyramid|rutgers}!cbmvax!daveh      PLINK: hazy     BIX: hazy
	"I have been given the freedom to do as I see fit" -REM
Technical Details
Message-ID: <13331@cbmvax.commodore.com>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!cs.utexas.edu!tut.cis.ohio-state.edu!rutgers!cbmvax!daveh
References: <1990Jul19.184648.11351@helios.physics.utoronto.ca>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!cs.utexas.edu!tut.cis.ohio-state.edu!rutgers!cbmvax!daveh
From: daveh@cbmvax.commodore.com (Dave Haynie)
Newsgroups: comp.sys.amiga.tech
Subject: Re: Finding Windows
Message-ID: <13331@cbmvax.commodore.com>
Date: 20 Jul 90 15:38:41 GMT
References: <1990Jul19.184648.11351@helios.physics.utoronto.ca>
Reply-To: daveh@cbmvax (Dave Haynie)
Organization: Commodore, West Chester, PA
Lines: 106