[futurebasic] Re: [FB] About Menu Item / Display NIB more than once

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : March 2008 : Group Archive : Group : All Groups

From: Robert Purves <listrp@...>
Date: Mon, 31 Mar 2008 18:39:50 +1300
Brian Heibert wrote:

> I am finding that when I display a window twice for example go to  
> the application menu in OS X and select About this App...  then  
> close the about window (nib) and select About this App..  again I am  
> getting this error message:
> Failed assertion:
> fn IsWRefConFBHandle(wRefCon)
> at line 951 at RNTM APPEARANCE.INCL
> What do I do to fix this?  I want the NIB window to be able to be  
> displayed as many times as the user clicks on the About menuitem.


[1] turn off the window's Standard handler checkbox in IB, and close  
the window via an old-style DoDialog handler for the _wndClose FB event


[2] immediately after the window is created in your code from the nib,  
call InstallWindowCloseHandler (see below) passing the window's  

long if 0
enterproc fn WindowCloseHandler( nextHandler as EventHandlerCallRef,  
theEvent as EventRef, userData as ptr ) = OSStatus
dim as WindowRef @ w
dim as OSStatus result : result = _eventNotHandledErr
dim as long wNum

call GetEventParameter( theEvent, _kEventParamDirectObject,  
_typeWindowRef, #0, sizeof( WindowRef ), #0, @w )
wNum = fn FBGetWndNumber( w )
select fn GetEventKind( theEvent )
case _kEventWindowClose
// (It's bad to let the standard Carbon handler close the
// window, because the FB-specific associated information
// doesn't get properly disposed of).
window close wNum
result = _noErr // we handled
end select
exitproc = result
end if

local fn InstallWindowCloseHandler( w as WindowRef )
dim as EventTypeSpec events(1)
begin globals
dim as proc sWindowEventUPP // 'static' var
end globals
#if def _FBtoC
sWindowEventUPP = @fn WindowCloseHandler
long if ( sWindowEventUPP == 0 )
sWindowEventUPP = fn NewEventHandlerUPP( [proc "WindowCloseHandler" +  
_FBprocToProcPtrOffset] )
end if
#endif // def _FBtoC
events.eventClass(0) = _kEventClassWindow
events.eventKind(0) = _kEventWindowClose
end fn = fn InstallEventHandler( fn GetWindowEventTarget( w ),  
sWindowEventUPP, 1, @events(0), #0, #0 )

Robert P.