[comp.sys.mac.programmer] window

hui@landau.uchicago.edu (Hui Dong) (05/09/91)

    I am new to mac programming, this maybe a trivial question but I need
help. How to get the WindowRecord from a WindowPtr? Someone suggest
(WindowPeek)mywindow but it doesn't seem to work, and how to find the current
front window(active one)? Thank you very much.

dweisman@umiami.ir.miami.edu (Ordinary Man) (05/10/91)

In article <1991May9.074917.19604@midway.uchicago.edu>, hui@landau.uchicago.edu (Hui Dong) writes:
> 
>     I am new to mac programming, this maybe a trivial question but I need
> help. How to get the WindowRecord from a WindowPtr? Someone suggest
> (WindowPeek)mywindow but it doesn't seem to work, and how to find the current
> front window(active one)? Thank you very much.

Yeah, that *IS* the correct way to get at the WindowRecord of a window. I think 
the correct way to typecast is:

	var windRec:WindowRecord;

begin
	...
	windRec:=WindowPeek(yourWindowPtr);
	...
end;

You could also pass a pointer to the window's record when it gets created using 
(Get)NewWindow and setting the wStorage parameter to your window record.
The Window Manager function FrontWindow will return the currently active window
(i.e. if myWindow=FrontWindow then ...).

Dan

/-------------------------------------------------------------------------\
|   Dan Weisman -  University of Miami - Florida   |  ||   ||   ||   ||   |
|--------------------------------------------------|  ||   ||   ||\ /||   |
|   INTERNET  -----> dweisman@umiami.IR.Miami.edu  |  ||   ||   || | ||   |
|     BITNET  -----> dweisman@umiami               |  |||||||   || | ||   |
|-------------------------------------------------------------------------|
|       "The more I get to see, the less I understand..."    - Triumph    |
\_________________________________________________________________________/

ech@cbnewsk.att.com (ned.horvath) (05/10/91)

From article <1991May9.130911.9763@umiami.ir.miami.edu>, by dweisman@umiami.ir.miami.edu (Ordinary Man):
> Yeah, that *IS* the correct way to get at the WindowRecord of a window. I think 
> the correct way to typecast is:
> 
> 	var windRec:WindowRecord;
> 
> begin
> 	...
> 	windRec:=WindowPeek(yourWindowPtr);
> 	...
> end;
> 
> You could also pass a pointer to the window's record when it gets created using 
> (Get)NewWindow and setting the wStorage parameter to your window record.
> The Window Manager function FrontWindow will return the currently active window
> (i.e. if myWindow=FrontWindow then ...).

Not quite: a WindowPeek is a pointer to a WindowRecord, so you'd need
something like
	windRec := WindowPeek(yourWindowPtr)^;
Similarly, FrontWindow returns a WindowPtr (which you can convert to a
WindowPeek), not a WindowRecord.  Beware: FrontWindow returns the frontmost
VISIBLE window: it may return nil.
-- 

=Ned Horvath=
ehorvath@attmail.com

wdh@well.sf.ca.us (Bill Hofmann) (05/13/91)

In article <1991May9.074917.19604@midway.uchicago.edu> hui@control.uchicago.edu writes:
>
>    I am new to mac programming, this maybe a trivial question but I need
>help. How to get the WindowRecord from a WindowPtr? Someone suggest
>(WindowPeek)mywindow but it doesn't seem to work, and how to find the current
>front window(active one)? Thank you very much.

Isn't C operator precedence fun?  The problem here, most likely, is that
the cast has a lower precedence than the dereference, so to, for instance,
look at the windowKind field, you need to say:

	((WindowPeek)mywindow)->windowKind

Note that that's about the only WindowRecord field you should every get
at in that fashion, unless you're doing stuff with zooming windows.  Use
GetWRefCon and SetWRefCon for the refCon field, GetWTitle and SetWTitle for
the window title, etc.

FrontWindow() returns the WindowPtr of the frontmost (active) window.  Note
that if you're running single finder, this may not be your winodw, it may
be a DA window.

-Bill Hofmann