好了,我自己找到办法了。:如下。可惜不能给自己加分。
关闭系统时运行相关程序
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
if MessageBox(0,'当前程序正在运行,是否退出?','',MB_YESNO)=IDYES then
CanClose:=True
else
CanClose:=False;
end;
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
if MessageBox(0,'当前程序正在运行,是否退出?','',MB_YESNO)=IDNO then abort/或用exit;
end;
或者拦截消息,截获消息:
先要在Type中定义,就是:
procedure WMQueryEndSession(var Msg: TMessage);message WM_QueryEndSession;
再如下
Procedure TMainForm.WMQueryEndSession(var Msg: TMessage);
begin
//加上你的代码;
message.result:=1;
{注:如不加此句,系统便不会关闭}
end;
或在onclose事件中定义相关程序
在uses中添加mmsystem。
procedure TsystemForm.Button28Click(Sender: TObject);
begin
mcisendstring('set cdaudio door
open',nil,0,handle);//Open
end;
procedure TsystemForm.Button29Click(Sender: TObject);
begin
mcisendstring('set cdaudio door
closed',nil,0,handle);//Close
end;
包括判断是否有盘
uses mmSystem;
var
MCIO : TMCI_Open_Parms;
MCIS : TMCI_Status_Parms;
begin
MCIO.lpstrDeviceType := PChar(MCI_DEVTYPE_CD_AUDIO);
if mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE or
MCI_OPEN_TYPE_ID or
MCI_OPEN_SHAREABLE, LongInt(@MCIO) )= 0 then
begin
MCIS.dwItem := MCI_STATUS_READY;
mciSendCommand(MCIO.wDeviceID, MCI_STATUS,
MCI_STATUS_ITEM
or MCI_WAIT, LongInt(@MCIS));
if MCIS.dwReturn<> 0 then
mciSendCommand(MCIO.wDeviceID, MCI_SET,
MCI_SET_DOOR_OPEN, 0)
else
mciSendCommand(MCIO.wDeviceID, MCI_SET,
MCI_SET_DOOR_CLOSED, 0);
mciSendCommand(MCIO.wDeviceID, MCI_CLOSE, MCI_WAIT,
0);
end;
end.