On 24/04/2007, Brian Stevens wrote: > In the process of converting to CE (and probably shortly thereafter > to Nibs with CE), I"ll be phasing out the Appearance Window > statement and using CreateNewWindow (or via the Nib later). One > challenge of this approach is how to obtain the WindowRef for an > existing window. FB (when using Appearance Window) conveniently > stuffs it in the RefCon so it is available to for FB statements > like: WINDOW (-_myWindow), WINDOW (_wndRef) and, of course, > directly via the Get Window statement. Many toolbox calls require a > WindowRef (fn IsWindowVisible is one example) that isn't readily > available when the window was created with CreateNewWindow. > > So here is my question: Do I need to save the WindowRef (maybe > even stuffing it in the Refcon or using the window property) when > the window is created (again assume CreateNewWindow) or is there > some nifty TB call that returns the windowRef of specific (i.e. It > is possible to walk the existing window list with > GetFrontWindowOfClass and GetNextWindowOfClass but every window > needs to be inspected to decide if it is the target window) window? Stuffing a WindowRef into the RefCon or a WindowProperty doesn't buy you anything; in order to retrieve the value you must already know it. Fortunately, it is not normally necessary to cache a WindowRef anywhere. Window-related CarbonEvents (_kEventClassWindow) allow you to get the relevant window with: dim as WindowRef @ w call GetEventParameter( theEvent, _kEventParamDirectObject, _typeWindowRef, #0, sizeof( WindowRef ), #0, @w ) From a mouse event handler you can get the window with: call GetEventParameter( theEvent, _kEventParamWindowRef, _typeWindowRef, #0, sizeof( WindowRef ), #0, @w ) If you have a ControlRef (or HIViewRef), you can get its owning window with w = GetControlOwner( c ). Robert P.