请问如何可以保持窗口总在最前,并锁定键盘上某些键为不可用?另请教怎么实现实时监控U盘是否插入?(30分)

  • 主题发起人 主题发起人 一只菜鸟Olala
  • 开始时间 开始时间

一只菜鸟Olala

Unregistered / Unconfirmed
GUEST, unregistred user!
我想使自己做的东西运行时全屏显示,而且不通过特殊途径无法关闭(如输入密码等),要求屏蔽部分系统热键,应该怎么写呢?
写的东西里有个功能是复制文件,硬盘还好说,可是U盘的处理让我伤脑筋了.我的程序只能在U盘已经插入并识别后运行才能正常的传输文件到U盘,如果是在程序运行期间插入了U盘的话就没办法了,只能重新启动程序,这样太麻烦了.请问有什么办法可以使程序能在运行过程中实时监控U盘的插入状态呢?PS一下,在程序中要实现安全拔除U盘(也就是WINDOWS里的那个安全拔出功能)应该怎么写代码啊?
 
30分你想得到答案啊?300吧
 
30分已经是所有了,没办法......
 
procedure WMDeviceChange(var Msg: TMessage); message WM_DEVICECHANGE;
 
想干坏事啊
我曾经做过一个类似的软件 想偷教员的考试题
结果偷来一堆垃圾 哈哈
我的方法是用计时器监控系统盘符的变化,一旦变化则判断是否有移动存储 如果有则拷贝
我是直接用WINRAR加密压缩到指定目录了
整个过程是在虚拟桌面下进行的,绝对不会被发现 即便是出错 他也看不见 哈哈
 
我找到了一个监测源码,全码如下:
unit U_Usb;

interface

uses
Windows, Messages, SysUtils, Classes, Forms;

type

PDevBroadcastHdr = ^DEV_BROADCAST_HDR;
DEV_BROADCAST_HDR = packed record
dbch_size: DWORD;
dbch_devicetype: DWORD;
dbch_reserved: DWORD;
end;

PDevBroadcastDeviceInterface = ^DEV_BROADCAST_DEVICEINTERFACE;
DEV_BROADCAST_DEVICEINTERFACE = record
dbcc_size: DWORD;
dbcc_devicetype: DWORD;
dbcc_reserved: DWORD;
dbcc_classguid: TGUID;
dbcc_name: short;
end;

const
GUID_DEVINTERFACE_USB_DEVICE: TGUID = '{A5DCBF10-6530-11D2-901F-00C04FB951ED}';
DBT_DEVICEARRIVAL = $8000; // system detected a new device
DBT_DEVICEREMOVECOMPLETE = $8004; // device is gone
DBT_DEVTYP_DEVICEINTERFACE = $00000005; // device interface class

type

TComponentUSB = class(TComponent)
private
FWindowHandle: HWND;
FOnUSBArrival: TNotifyEvent;
FOnUSBRemove: TNotifyEvent;
procedure WndProc(var Msg: TMessage);
function USBRegister: Boolean;
protected
procedure WMDeviceChange(var Msg : TMessage); dynamic;
public
constructor Create(AOwner : TComponent); override;
destructor Destroy; override;
published
property OnUSBArrival: TNotifyEvent read FOnUSBArrival write FOnUSBArrival;
property OnUSBRemove: TNotifyEvent read FOnUSBRemove write FOnUSBRemove;
end;

implementation

constructor TComponentUSB.Create(AOwner : TComponent);
begin
inherited Create(AOwner);
FWindowHandle := AllocateHWnd(WndProc);
USBRegister;
end;

destructor TComponentUSB.Destroy;
begin
DeallocateHWnd(FWindowHandle);
inherited Destroy;
end;

procedure TComponentUSB.WndProc(var Msg: TMessage);
begin
if (Msg.Msg = WM_DEVICECHANGE) then begin
try
WMDeviceChange( Msg );
except
Application.HandleException(Self);
end;
end
else
Msg.Result := DefWindowProc( FWindowHandle, Msg.Msg, Msg.wParam, Msg.lParam);
end;

procedure TComponentUSB.WMDeviceChange(var Msg : TMessage);
var
devType: Integer;
Datos: PDevBroadcastHdr;
begin
if (msg.WParam=DBT_DEVICEARRIVAL) or (msg.WParam=DBT_DEVICEREMOVECOMPLETE) then begin
Datos := PDevBroadcastHdr(msg.LParam);
devType := Datos^.dbch_devicetype;
if devType=DBT_DEVTYP_DEVICEINTERFACE then begin // USB Device
if msg.WParam=DBT_DEVICEARRIVAL then begin
if Assigned( FOnUSBArrival ) then
FOnUSBArrival( Self );
end else begin
if Assigned( FOnUSBRemove ) then
FOnUSBRemove( Self );
end;
end;
end;
end;

function TComponentUSB.USBRegister: Boolean;
var
dbi: DEV_BROADCAST_DEVICEINTERFACE;
size: Integer;
r: Pointer;
begin
Result := False;
size := SizeOf(DEV_BROADCAST_DEVICEINTERFACE);
ZeroMemory( @dbi, size );
dbi.dbcc_size := size;
dbi.dbcc_devicetype := DBT_DEVTYP_DEVICEINTERFACE;
dbi.dbcc_reserved := 0;
dbi.dbcc_classguid := GUID_DEVINTERFACE_USB_DEVICE;
dbi.dbcc_name := 0;

r := RegisterDeviceNotification( FWindowHandle,
@dbi,
DEVICE_NOTIFY_WINDOW_HANDLE
);
if Assigned( r ) then Result := True;

end;

end.


====== 应用示例 ======

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
procedure UsbInserted(Sender: TObject);
procedure usbRemoved(Sender: TObject);
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

uses U_Usb;

{$R *.dfm}

procedure TForm1.UsbInserted(Sender: TObject);
begin
ShowMessage('USB Inserted');
end;

procedure TForm1.usbRemoved(Sender: TObject);
begin
ShowMessage('USB Removed');
end;

procedure TForm1.FormCreate(Sender: TObject);
var
usb:TComponentUSB;
begin
usb:=TComponentUSB.Create(self);
usb.OnUSBArrival:=UsbInserted;
usb.OnUSBRemove:=usbRemoved;
end;

end.
在Unit中没有定义Unit1我无法使用Form1,请问应该怎么办?
PS:贴出源码给和我一样的初哥学习备用,呵呵~~
 
后退
顶部