home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
HyperLib 1997 Winter - Disc 1
/
HYPERLIB-1997-Winter-CD1.ISO.7z
/
HYPERLIB-1997-Winter-CD1.ISO
/
オンラインウェア
/
PRG
/
AESample.sit
/
AESample
/
sources
/
sample.alrt.c
< prev
next >
Wrap
Text File
|
1996-06-22
|
5KB
|
174 lines
/*
*--------------------------------------------------------------
* sample.alrt.c
*--------------------------------------------------------------
*/
#include <Notification.h>
#include <Icons.h>
#include "sample.h"
#include "sample.alrt.h"
/*
*--------------------------------------------------------------
* static global for the notification
*--------------------------------------------------------------
*/
static NMRec gMyRequest;
/*
*--------------------------------------------------------------
* static function prototype
*--------------------------------------------------------------
*/
static OSErr NotifyMyError(const short dialogID);
/*
*--------------------------------------------------------------
* CheckMyErrors
*--------------------------------------------------------------
* check a notification and show alert
*--------------------------------------------------------------
*/
short CheckMyErrors(void)
{
short answer = ok;
short alertID;
if (gNowBackGround == false) {
alertID = (short)gMyRequest.nmRefCon;
if (alertID != 0) {
/* remove the notification */
NMRemove(&gMyRequest);
gMyRequest.nmRefCon = 0;
/* now show the postponed alert */
answer = MyAlert(alertID);
}
}
return (answer);
}
/*
*--------------------------------------------------------------
* MyAlert
*--------------------------------------------------------------
* In foreground, this routine shows a modal dialog immediately.
* In background, post notification instead.
*--------------------------------------------------------------
*/
short MyAlert(const short theDlgID)
{
short itemHit = cancel;
if (gNowBackGround) {
/* postpone the alert */
NotifyMyError(theDlgID);
} else {
/* show the alert dialog */
DialogRef aDialog;
aDialog = GetNewDialog(theDlgID, kInHeap, kFrontMost);
if (aDialog != nil) {
WindowRef aWindow;
GrafPtr savePort;
GetPort(&savePort);
aWindow = GetDialogWindow(aDialog);
SetPortWindowPort(aWindow);
SetDialogDefaultItem(aDialog, kStdOkItemIndex);
/* make the dialog appear */
ShowWindow(aWindow);
SelectWindow(aWindow);
SysBeep(1); /* play a beep once */
InitCursor();
do {
ModalDialog(nil, &itemHit);
} while (itemHit != ok && itemHit != cancel);
SetPort(savePort);
DisposeDialog(aDialog);
}
}
return (itemHit);
}
/*
*--------------------------------------------------------------
* NotifyMyError
*--------------------------------------------------------------
* install a data to notification queue
* this is used in case the drag and drop occurred when this
* program stays background
*--------------------------------------------------------------
*/
static OSErr NotifyMyError(const short theAlertID)
{
Handle aSuite;
OSErr result = noErr;
if (gNowBackGround) {
if (gMyRequest.nmRefCon != 0) {
NMRemove(&gMyRequest);
}
if (GetIconSuite(&aSuite, kMyIconID, svAllSmallData) != noErr) {
aSuite = nil;
}
/* setup notification data record */
gMyRequest.qType = nmType;
gMyRequest.nmMark = 1;
gMyRequest.nmIcon = aSuite; /* show my icon in menu bar */
gMyRequest.nmSound = (Handle)-1; /* SysBeep */
gMyRequest.nmStr = nil; /* no dialog */
gMyRequest.nmResp = nil; /* no response procs */
gMyRequest.nmRefCon = theAlertID; /* set the alert ID */
result = NMInstall(&gMyRequest);
}
return (result);
}
/*
*--------------------------------------------------------------
* DoFileAlert
*--------------------------------------------------------------
* show file handlig alert here
*--------------------------------------------------------------
*/
void DoFileAlert(StringPtr theFileName, OSErr theCode)
{
Str15 codeStr;
NumToString((long)theCode, codeStr);
ParamText(theFileName, codeStr, nil, nil);
MyAlert(alrtFileID);
}
/*
*--------------------------------------------------------------
* DoAliasAlert
*--------------------------------------------------------------
* show file handlig alert here
*--------------------------------------------------------------
*/
void DoAliasAlert(StringPtr theFileName, OSErr theCode)
{
Str15 codeStr;
NumToString((long)theCode, codeStr);
ParamText(theFileName, codeStr, nil, nil);
MyAlert(alrtAliasID);
}
/*
*--------------------------------------------------------------
* FatalErrorAlert
*--------------------------------------------------------------
* show some fatal error
*--------------------------------------------------------------
*/
void FatalErrorAlert(void)
{
StopAlert(alrtFatalID, nil);
}