
FB II Compiler
PG PRO
Debugging
Memory
System
Mathematics
Resources
Disk I/O
Windows
Controls
Menus
Mouse
Keyboard
Text
Fonts
Drawing
Sound
Clipboard
Printing
Communication
ASM
|
SYSTEM
Use the Notification Manager
I use FN GetAttention, which is listed below. You need to create a SICN resource and put it in your app's resource fork; the FN is currently hard-coded to use SICN #128, but you can change that as you wish.
BTW, a SICN is black & white. If you can figure out how to flash a small _color_ icon, let me know. I've seen it done, but I've never seen it documented & I've never been able to accomplish it.
'----------------------------------------------------------------
LOCAL FN GetFrontProcess(PSNptr&)
'Call as follows:
' OSErr = FN GetFrontProcess(@PSN)
'where PSN is an 8-byte record.
DIM OSErr
` CLR.W -(SP)
` MOVE.L ^PSNptr&,-(SP)
` DC.W $70FF
` DC.W $2F00
` MOVE.W #$0039,-(SP)
` DC.W $A88F
` MOVE.W (SP)+,^OSErr
END FN = OSErr
'----------------------------------------------------------------
LOCAL FN SameProcess(@PSN1ptr&, @PSN2ptr&, resultPtr&)
'Call as follows:
' OSErr = FN SameProcess(PSN1, PSN2, @result)
'where PSN1, PSN2 are 8-byte records.
'(As Toolbox may poke only 1 byte into result, clear both bytes now:)
DIM OSErr
POKE WORD resultPtr&, 0
` CLR.W -(SP)
` MOVE.L ^PSN1ptr&,-(SP)
` MOVE.L ^PSN2ptr&,-(SP)
` MOVE.L ^resultPtr&,-(SP)
` MOVE.W #$003D,-(SP)
` DC.W $A88F
` MOVE.W (SP)+,^OSErr
END FN = OSErr
'----------------------------------------------------------------
CLEAR LOCAL
DIM myProcess.8, frontProcess.8, nmRecord.36
LOCAL FN GetAttention(theSound&)
'If the process is currently in the foreground, this routine does nothing
'(and returns _false). Otherwise, it posts a notification (puts adiamond
'in the application menu, flashes the app. menu icon, an optionally plays
'a sound. If theSound& = 0, no sound is played. If theSound& = -1, the
'system beep is played. Otherwise, theSound& should be a handle to an
'"snd " sound, which will then be played.) In this case, GetAttention
'won't return until the user brings the application to the front, at
'which time it returns _zTrue.
DIM OSErr, wasInBack, same, iconHandle&
myProcess.6% = _kCurrentProcess
OSErr = FN GetFrontProcess(@frontProcess)
OSErr = FN SameProcess(myProcess, frontProcess, @same)
LONG IF same = 0
wasInBack = _zTrue
'Get an icon.
iconHandle& = FN GETRESOURCE(_"SICN", 128)
nmRecord.nmIcon& = iconHandle&
nmRecord.qType% = _nmType
nmRecord.nmMark% = 1 '(put diamond in app MENU)
nmRecord.nmSound& = theSound&
OSErr = FN NMINSTALL(@nmRecord)
DO
HANDLEEVENTS
OSErr = FN GetFrontProcess(@frontProcess)
OSErr = FN SameProcess(myProcess, frontProcess, @same)
UNTIL same <> 0
OSErr = FN NMREMOVE(@nmRecord)
XELSE
wasInBack = _false
END IF
END FN = wasInBack
'-----------------------------------------------------------------
You might try this. I can't remember the routine name offhand but I expect you have access to Think Reference. I use the routine below to draw a close box in a window by drawing a color icon. You first need to create an ICN# resource, but it's okay to only create one of the six or so icons that the resource gives you opportunity to create (as long as you create the one that you are going to use, of course). The Toolbox routine automatically selects the correct size of the icon based on the rectangle that you supply it.
` SUBQ.L #2,sp ; space for osErr%
` MOVE.L ^closeRect&,-(sp) ; boundary rectangle for icon
` MOVE.W #0,-(sp)
` MOVE.W #0,-(sp)
` MOVE.W #200,-(sp) ; res ID of icon
` DC.W $303C,$0500,$ABC9
` MOVE.W (sp)+,D0 ; return error code
If you need code to get a Finder icon I can give you something for that too.
Thanks. Your code works fine, and I have no problem plotting a small color icon per se; but I can't figure out how to get the Notification Manager routines to plot one. Any suggestions?
Heres the trick - load the hole Icon Family, and pass it in the Notification Block instead on a SICN. I found the documentation for this while researching AEInteractWithUser. Be careful if you convert the "ICONS.p" header file, the Pascal converter thinks that an "SInt" is a long!. I have corrected the following version (I hope):
' Function:GetIconSuite
'
'=================
LOCAL MODE
LOCAL FN GetIconSuite(@theIconSuite&,theResID%,selector&)
'---------------------------------------
` CLR.W -(SP)
` MOVE.L ^theIconSuite&,-(SP) ;Var: Handle
` MOVE.W ^theResID%,-(SP) ;SInt16
` MOVE.L ^selector&,-(SP) ;IconSelectorValue
` DC.W $303C,$0501,$ABC9
` MOVE.W (SP)+,D0
` EXT.L D0
END FN = REGISTER(D0) 'OSErr
'
Changes to Rick's code:
'Get an icon (or Family, if possible)
_kAllAvailableData = &FFFFFFFF
osErr% = FN GetIconSuite(iconHandle&,128,_kAllAvailableData)
LONG IF osErr% <> _noErr
iconHandle& = FN GETRESOURCE(_"SICN", 128) ' Revert to old way
END IF
nmRecord.nmIcon& = iconHandle&
nmRecord.qType% = _nmType
nmRecord.nmMark% = 1 '(put diamond in app
MENU)
nmRecord.nmSound& = theSound&
OSErr = FN NMINSTALL(@nmRecord)
|