[futurebasic] [FB3] [Release 7.0] Shutdown

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : September 2002 : Group Archive : Group : All Groups

From: Ken Shmidheiser <kshmidheiser@...>
Date: Fri, 20 Sep 2002 22:06:49 -0400
Brian Heibert asked:

>I need to be able to shutdown the computer when a button I have in my program
>is clicked, how do I do that?   This is in OSX.   I'd also like to be able to
>restart the computer as well.

Brian,

This should work in PPC Classic and Carbon OS X . Hope it helps.

Best,

Ken

p.s. Please watch for e-mail line breaks and lost constant
underscores stripped by the Associate server. E-mail list versions
should work okay.

_kAEFinderEvents = _"FNDR"
_kAERestart      = _"rest"
_kAEShutDown     = _"shut"

local fn BuildWindow
dim as rect r

setrect( r, 0, 0, 200, 140  )
appearance Window -1, "", @r, _kDocumentWindowClass,¬
_kWindowStandardFloatingAttributes

def SetWindowBackground(_kThemeActiveDialogBackgroundBrush,_zTrue)

setrect( r, 20, 20, 180, 40 )
button 1, _activeBtn, "Shutdown this Mac", @r, _push

offsetrect( r, 0, 40 )
button 2, _activeBtn, "Restart this Mac", @r, _push

offsetrect( r, 0, 40 )
button 3, _activeBtn, "Quit this demo", @r, _shadow

window 1

end fn

local fn DoShutDown

select system( _sysVers )
case < 1000 : sendAppleEvent _kAEFinderEvents,¬
_kAEShutDown, _nil, _nil, "Finder"
case else   : sendAppleEvent _kCoreEventClass,¬
_kAEShutDown, _nil, _nil, "loginwindow"
end select

end fn

local fn DoRestart

select system( _sysVers )
case < 1000 : sendAppleEvent _kAEFinderEvents,¬
_kAERestart, _nil, _nil, "Finder"
case else   : sendAppleEvent _kCoreEventClass,¬
_kAERestart, _nil, _nil, "loginwindow"
end select

end fn

local fn DoDialog
dim as long evnt, id

evnt = dialog(0)
id = dialog(evnt)

select case( evnt )
case _wndClose
select( id )
case 1 :  gFBQuit = _zTrue
end select

case _btnClick
select( id )
case 1 : fn DoShutDown
case 2 : fn DoRestart
Case 3 : gFBQuit = _zTrue
end select

end select

end fn

on dialog fn DoDialog

fn BuildWindow

do
handleevents
until gFBQuit
end