#Saving window location
5 messages in this thread
Wayne & Tryg,
Thanks for your input. I will definitely use a Prefs file. It would be
unusual to have a program that is redistributed among different users that
comes up with, say the window way off to the right. Better to let that info be
in a prefs file. I agree with the idea of saving the position at close or
quit.
I'm a newbie on the Mac. I'm always having difficulties, as you can imagine.
I've been trying to figure out from the THINK Reference how to make use of the
Notification Mgr. when running in the background. My code brings up the
message when I step through in the Debugger, but otherwise it comes up nada.
Here's an approximate of the code:
/******************** SendNote ************************/
void SendNote( void )
{
NMRec myNote;
OSErr err;
Str255 tempStr;
memcpy( tempStr, gNotifyStr, strlen(gNotifyStr) );
myNote.qType = nmType;
myNote.nmMark = 1;
myNote.nmIcon = GetResource( 'SICN', kBaseResID );
myNote.nmSound = (Handle) -1L;
myNote.nmStr = (StringPtr)&tempStr; //Use alert box
myNote.nmResp = nil;
myNote.nmRefCon = 0;
err = NMInstall( (NMRecPtr) &myNote);
RemoveQueue( &myNote );
}
/************************** RemoveQueue **************************/
void RemoveQueue( NMRecPtr notifyPtr )
{
OSErr err;
err = NMRemove( notifyPtr );
}
Can you please tell me why this *^&@# thing won't work! I've changed the code
so many ways and nothing works. I tried putting the response procedure address
in, I started without a seperate function and just put the remove after the
install. I tried setting nmResp to -1 and accomplished nothing. I can't
figure out what the THINK Reference is saying to do. Nothing seems to work for
me. It even mentioned setting nmResp to NULIL. What the heck is NULIL?
Help,
Eric (-:
Eric:
>>>
memcpy( tempStr, gNotifyStr, strlen(gNotifyStr) );
<<<
First of all, note that the Notification Mgr wants pascal strings, and the
above really looks like a C string. If it is, you need to CtoPStr() it.
>>>
err = NMInstall( (NMRecPtr) &myNote);
RemoveQueue( &myNote );
…
Can you please tell me why this *^&@# thing won't work!
<<<
All that NMInstall() does is put the message in a queue. But nothing will ever
actually look at that queue until the next time someone calls WaitNextEvent()
[or its relatives]. If the message has not yet made it to the screen,
NMRemove() will prevent it from ever getting there; if the message is currently
on the screen, NMRemove() will take it off without the user having to respond;
if the user has already responded, NMRemove() just does cleanup.
After you call NMInstall(), you then need to go do something else, such as sit
in a WaitNextEvent() loop. You don't want to call NMRemove() until:
1) the user has responded, or
2) the condition you are alerting about has ceased to exist, or
3) you decide to time out because the computer is apparently unattended.
Note however that both your NMRec and your message string are local variables
in the routine where you call NMInstall(). If that routine returns before you
call NMRemove(), the NMRec will cease to exist, and the Notification Mgr will
crash.
Also, if you set nmResp to -1, you should never call NMRemove(), because the
Notification Mgr will remove it for you. However, this comes with the
disadvantage of not knowing _when_ the user responded or the NMRemove()
happened. Well, pretty much, anyway; you could call WaitNextEvent()
immediately, and that would probably force things.
>>>
It even mentioned setting nmResp to NULIL. What the heck is NULIL?
<<<
A typo for NULL.
Thanks Steve,
I know what I sound like and what my code looks like, but that's what happens
when you play around with same thing for several hours and get nowhere!
I knew something must be missing. My string is a Pstring. I copied it into
temp because I read something about "not having access to your globals (A5)…"
I didn't know what that was telling me, so I thought maybe I should define it
within the function. Anyway, I'll try again. I was shooting arrows in the air
since nothing I did was accomplishing my desires. Thanks for the bit of info I
didn't see in the docs.
NULIL… I thought it was a typo, but there's always another term I don't
recognize, so I wasn't sure. There seems to be many typos along the way in the
THINK Ref, still wouldn't want to be without it.
Thanks again,
Eric (-:
Eric:
>>>
My string is a Pstring. I copied it into temp because I read something about
"not having access to your globals (A5)…" I didn't know what that was telling
me, so I thought maybe I should define it within the function.
<<<
The message string is explicitly pointed to by the NMRec, so A5 isn't a
problem. But if your response routine needs to access global variables, you
have to have some way to put your correct value into A5 (or A4 for code
resources). Usually this is done with the refCon; you might put the A5 or A4
value in it directly, or you might put a pointer or handle to a structure that
among other things contains your A5/A4 value.
Steve
Steve,
I got it all working. Once I understood that the NMRec was lost once I exited
the function, it was all clear. I made the NMRec a global so I could pass it
through my event loop. Actually, I restructured everything and I'm much
happier with what I've got. Things are going well.
Thanks,
Eric (-: