win2000下,PB如何能屏蔽关机键?

lizx 2008-09-01 12:09:17
win2000下,PB如何能屏蔽关机键?或者那位高人给小弟个DLL文件调用也行,谢谢了!
...全文
215 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
AFIC 2008-09-02
  • 打赏
  • 举报
回复
屏蔽ctrl+alt+del在nt内核的系统上比较困难,
你可以把ctrl+alt注册为你的热键,有人按下ctrl+alt后
你立即模拟键盘按键帮他松开ctrl,alt中的一个或者随便按个啥键。
玉儿o0 2008-09-01
  • 打赏
  • 举报
回复
找关机键所传递的消息
然后,重写一下对应的函数。

(设想)

相关:
PB中注销当前用户、关闭计算机、重启计算机

通过ExitWindowsEx函数可实现这三个功能,首先作如下声明:

Function Long ExitWindowsEx(Long uflag,Long nouse) Library ″user32.dll″

参数2保留不用,可取0;参数1取0可以注销当前用户,取1可以关闭计算机,取2可以重启计算机,其值

再加4表示强制结束"未响应"的进程。

lizx 2008-09-01
  • 打赏
  • 举报
回复
接上:

procedure TPwrSave.WndProc(var Msg: TMessage);
var Allow: boolean;
begin
inherited;
if Msg.Msg = WM_POWERBROADCAST then
case Msg.WParam of
PBT_APMQUERYSUSPEND:
begin
if (Msg.LParam and 1) = 1 then
Allow := QuerySuspend // Check for User Interaction
else
Allow := AllowSuspend;
if Allow then
Msg.Result := integer(true)
else
Msg.Result := BROADCAST_QUERY_DENY;
end;
PBT_APMQUERYSTANDBY:
begin
if (Msg.LParam and 1) = 1 then
Allow := QueryStandby // Check for User Interaction
else
Allow := AllowStandby;
if Allow then
Msg.Result := integer(true)
else
Msg.Result := BROADCAST_QUERY_DENY;
end;
PBT_APMBATTERYLOW:
if Assigned(FOnBatteryLow) then
FOnBatteryLow(Self);
PBT_APMPOWERSTATUSCHANGE:
PowerStatusChange;
PBT_APMOEMEVENT:
if Assigned(FOnOemEvent) then
FOnOemEvent(Self, Msg.LParam);
PBT_APMQUERYSUSPENDFAILED:
if Assigned(FOnQuerySuspendFailed) then
FOnQuerySuspendFailed(Self);
PBT_APMQUERYSTANDBYFAILED:
if Assigned(FOnQueryStandbyFailed) then
FOnQueryStandbyFailed(Self);
PBT_APMRESUMECRITICAL:
if Assigned(FOnResumeCritical) then
FOnResumeCritical(Self);
PBT_APMRESUMESUSPEND:
if Assigned(FOnResumeSuspend) then
FOnResumeSuspend(Self);
PBT_APMRESUMESTANDBY:
if Assigned(FOnResumeStandby) then
FOnResumeStandby(Self);
PBT_APMSUSPEND:
if Assigned(FOnSuspend) then
FOnSuspend(Self);
PBT_APMSTANDBY:
if Assigned(FOnStandby) then
FOnStandby(Self);
end
else
if Msg.Msg = WM_QUERYENDSESSION then
begin
Msg.Result := integer(QueryEndSession);
end;
end;

function TPwrSave.QuerySuspend: boolean;
begin
if Assigned(FOnQuerySuspend) then
FOnQuerySuspend(Self, Result)
else
Result := AllowSuspend;
end;

function TPwrSave.QueryStandby: boolean;
begin
if Assigned(FOnQueryStandby) then
FOnQueryStandby(Self, Result)
else
Result := AllowStandby;
end;

function TPwrSave.QueryEndSession: boolean;
begin
if Assigned(FOnQueryEndSession) then
FOnQueryEndSession(Self, Result)
else
Result := AllowEndSession;
end;

procedure TPwrSave.PowerStatusChange;
var Status: _SYSTEM_POWER_STATUS;
begin
if Assigned(FOnPowerStatusChange) then
if GetSystemPowerStatus(Status) then
begin
FOnPowerStatusChange(Self, Status.ACLineStatus, Status.BatteryFlag,
Status.BatteryLifePercent, Status.BatteryLifeTime,
Status.BatteryFullLifeTime);
end;
end;

constructor TPwrSave.Create(AOwner: TComponent);
begin
inherited;
if not (csDesigning in ComponentState) then
FHWnd := AllocateHWnd(WndProc);
end;

destructor TPwrSave.Destroy;
begin
if not (csDesigning in ComponentState) then
DeallocateHWnd(FHwnd);
inherited;
end;

end.
lizx 2008-09-01
  • 打赏
  • 举报
回复
在网上找了段相关代码,好象是Delphi的,不懂仅供参考!
unit PwrSave;
//==============================================================================
// Purpose:
// Windows has the ability to shutdown / hibernate / standby when no user
// interaction takes place for a certain time. When writing programs for
// data aqcuisition, control systems or servers this might be very undesired.
// This component will prevent these events and/or gives you the opportunity
// to take necessary action when such events occur.
// In addition this program can as well prevent shutdown / log off initiated
// by the user.
//
// Function:
// This little component will catch the listed Windows messages that might
// intercept program execution.
// WM_POWERBROADCAST with
// PBT_APMQUERYSUSPEND -> OnQuerySuspend
// PBT_APMQUERYSTANDBY -> OnQueryStandby
// WM_ENDSESSION -> OnQueryEndSession
//
// It will fire the corresponding events, if an eventhandler has been assigned.
// If no eventhandler is assigned or user interaction is not allowed by Windows,
// then it will respond to the messages as defined by the properties:
// AllowSuspend, AllowStandby, AllowEndSession
//
// In addition to this, events for the other APM messages are included.
//
// Usage:
// Drop the component on your main form.
// If you do not assign any event handlers and do not change the default values,
// then Windows will not shutdown / hibernate / standby (unless this is forced
// by a program / driver) and the user can not log off / shutdown while the
// program is running.
// Use the Events and the proporties to fine tune the behaviour.
// The Query events will give you a chance to e.g. display a dialog to ask the
// user what to do.
//
//==============================================================================

interface

uses
Windows, Messages, SysUtils, Classes, Forms;

const
// APM messages
PBT_APMQUERYSUSPEND = $0000;
PBT_APMQUERYSTANDBY = $0001;
PBT_APMQUERYSUSPENDFAILED = $0002;
PBT_APMQUERYSTANDBYFAILED = $0003;
PBT_APMSUSPEND = $0004;
PBT_APMSTANDBY = $0005;
PBT_APMRESUMECRITICAL = $0006;
PBT_APMRESUMESUSPEND = $0007;
PBT_APMRESUMESTANDBY = $0008;
PBT_APMBATTERYLOW = $0009;
PBT_APMPOWERSTATUSCHANGE = $000A;
PBT_APMOEMEVENT = $000B;

// ACLineStatus values
AC_Offline = 0;
AC_Online = 1;
AC_Unkown = 255;

// BatteryFlag values
BF_High = 1;
BF_Low = 2;
BF_Critical = 4;
BF_Charging = 8;
BF_NoBattery = 128;
BF_Unkown = 255;

type

TQueryEvent = procedure(Sender: TObject; var Allow: boolean) of object;
TPowerEvent = procedure(Sender: TObject) of object;
TOEMEvent = procedure(Sender: TObject; dwEventCode: integer) of object;
// dwEventCode depends on the hardware manufacturer
TStatusEvent = procedure(Sender: TObject;
ACLineStatus, BatteryFlag, BatteryLifePercent: byte;
BatteryLifeTime, BatteryFullLifeTime: longword)
of object;
// BatteryLifeTime and BatteryFullLifeTime is given in seconds

TPwrSave = class(TComponent)
private
{ Private declarations }
FHWnd: THandle;
FAllowSuspend: boolean;
FAllowStandby: boolean;
FAllowEndSession: boolean;
FOnQuerySuspend: TQueryEvent;
FOnQueryStandby: TQueryEvent;
FOnQueryEndSession: TQueryEvent;
FOnBatteryLow: TPowerEvent;
FOnPowerStatusChange: TStatusEvent;
FOnOemEvent: TOEMEvent;
FOnQuerySuspendFailed: TPowerEvent;
FOnQueryStandbyFailed: TPowerEvent;
FOnResumeCritical: TPowerEvent;
FOnResumeSuspend: TPowerEvent;
FOnResumeStandby: TPowerEvent;
FOnSuspend: TPowerEvent;
FOnStandby: TPowerEvent;
procedure WndProc(var Msg: TMessage);
protected
{ Protected declarations }
function QuerySuspend: boolean;
function QueryStandby: boolean;
function QueryEndSession: boolean;
procedure PowerStatusChange;
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
{ Published declarations }
property AllowSuspend: boolean read FAllowSuspend write FAllowSuspend;
property AllowStandby: boolean read FAllowStandby write FAllowStandby;
property AllowEndSession: boolean read FAllowEndSession write FAllowEndSession;
property OnQuerySuspend: TQueryEvent read FOnQuerySuspend write FOnQuerySuspend;
property OnQueryStandby: TQueryEvent read FOnQueryStandby write FOnQueryStandby;
property OnQueryEndSession: TQueryEvent read FOnQueryEndSession write FOnQueryEndSession;
property OnBatteryLow: TPowerEvent read FOnBatteryLow write FOnBatteryLow;
property OnPowerStatusChange: TStatusEvent read FOnPowerStatusChange write FOnPowerStatusChange;
property OnOemEvent: TOEMEvent read FOnOemEvent write FOnOemEvent;
property OnQuerySuspendFailed: TPowerEvent read FOnQuerySuspendFailed write FOnQuerySuspendFailed;
property OnQueryStandbyFailed: TPowerEvent read FOnQueryStandbyFailed write FOnQueryStandbyFailed;
property OnResumeCritical: TPowerEvent read FOnResumeCritical write FOnResumeCritical;
property OnResumeSuspend: TPowerEvent read FOnResumeSuspend write FOnResumeSuspend;
property OnResumeStandby: TPowerEvent read FOnResumeStandby write FOnResumeStandby;
property OnSuspend: TPowerEvent read FOnSuspend write FOnSuspend;
property OnStandby: TPowerEvent read FOnStandby write FOnStandby;
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Custom', [TPwrSave]);
end;
lizx 2008-09-01
  • 打赏
  • 举报
回复
WinXP下是很容易的,在主窗口的closequery事件下编写:
//先检查是否完成了备份操作
....
if 未完成备份 then
MessageBox("提示", '请先完成备份后再关机!')
return 1;
ELSE
return 0;
END IF

但win2000下就不起作用,一按电源键就直接关机了!
lllyyymmm 2008-09-01
  • 打赏
  • 举报
回复
用勾子技术也可以,但麻烦一点,不过却很准确

680

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder API 调用
社区管理员
  • API 调用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧