[futurebasic] Re: [FB] A Real FB Problem

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : February 2005 : Group Archive : Group : All Groups

From: Alain Pastor <apastor@...>
Date: Mon, 21 Feb 2005 02:08:11 +0100
Joe Lewis Wilkins a écrit :
> Thanks for the clue, BJ. I don't currently have an AppleEvent Handler in 
> the progam - don't know why since I usually do; so I've got to go steal 
> one from another of my programs. I'll post back if this works.
> 

If it doesn't work, there might be another solution with a threaded 
function that could watch for a change in the window' status. The 
CWindowRecord structure contains an unused boolean field that could 
easily store the state of the window at a given time. The prog could 
then check periodically that stored value against the window's content 
region, which is empty when the window is collapsed and when the thread 
determines that the window has just been expanded, it would post a 
_wndRefresh event for that specific window, then your program would deal 
with that event in its usual dialog event handler. Of course, you would 
call the same threaded function for each collapsible window your program 
needs to open. All this doesn't seem to be required when the prog is 
running on Classic. That trick cannot work in Carbon because the window 
structure is opaque, however if it is needed, you could still store the 
window' status as a window property to achieve the same goal, I guess. 
Here is an example that seems to work, but has not been tested under Mac 
OS 9 :

#If CarbonLib == _false
Begin Enum
_gestaltMacOSCompatibilityBoxAttr      = _"bbox"
_gestaltMacOSCompatibilityBoxPresent   = 0
_gestaltMacOSCompatibilityBoxHasSerial = 1
_gestaltMacOSCompatibilityBoxless      = 2
End Enum

Local Mode
Local Fn IsRunningOnClassic
'~'1
Dim @ reply  As Long
Dim   answer As Boolean
Long If Fn Gestalt(_gestaltMacOSCompatibilityBoxAttr, reply) == _noErr
answer = ((reply And (1 << _gestaltMacOSCompatibilityBoxPresent))!= 0)
End If
End Fn = answer



Clear Local Mode
Local Fn HandleWindowShading( wNum As Long ) // incoming FB window number
'~'1

Dim @ w  As .CWindowRecord
Dim rslt As Boolean
Do
Get Window wNum, w// getting window pointer
Long If w
rslt = Fn EmptyRgn( w.contRgn )// is content region empty?
Long If w.spareFlag != rslt// has the window status changed?
w.spareFlag = rslt// store new status
Long If rslt = 0// content region not empty
// Beep
#If Def _appearanceRuntime
Fn SendFBDialogEvt( _wndRefresh, wNum ) // post event in Appearance Rntm
#Else
Fn FBSendDialogEvt( _wndRefresh, wNum ) // post event in Standard Rntm
#Endif
End If
End if
Xelse
Exit Do// couldn't get window pointer, exit thread
End If
Until ThreadStatus != _noErr
End Fn

#Endif

_mainWnd = 100

Local Fn doRefresh( wNum As Long )
'~'1
If wNum = _mainWnd Then Print Rnd(1000)
End Fn


Local Fn doDialog
'~'1
Dim As Long act, ref
act = Dialog(0)
ref = Dialog(act)
Select act
Case _wndRefresh
Fn doRefresh( ref )
End Select
End Fn


Window _mainWnd, "Test"

#If CarbonLib == _false
Long If Fn IsRunningOnClassic == _false
ThreadBegin Fn HandleWindowShading, _mainWnd
End If
#Endif

On Dialog Fn doDialog

Do
HandleEvents
Until _nil



Alain