在线等,高手救我啊!
解决方案 »
- delphi 当某个edit获得焦点后,其他控件就不能获得焦点,直到edit输入完成按回车进入下一个edit??
- @string 和pchar(string) 区别
- 100分~~求一计算器的完整源码..
- Memo问题
- 请教我下面的语句是那里出错了。
- 我以前在delphi写代码时候,左边有1条条,鼠标点1下,f9程序就运行到光标处,现在找不到它了
- Intraweb开发问题 : Intraweb系统支持的系统怎样加入第二个窗口并可使用?
- SkinEngine9.01 写的程序如何升级到 SkinEngine3.02 ????
- 使用Remobjects创建datasnap服务器碰到的问题
- 请教com的实现?
- length 与 "missing operator or semicolon"错误提示
- 我因工作要求,要做一个类似防火墙的程序,要求只充许指定的网址访问.其它不行.请问应点做呀.请指教
有个源码,是对注册表进行修改来实现的。
我copy人家的代碼給你:絕對可用的,100% Delphi代碼!!
http://www.yeahware.com/download/eject.zip
選擇Show hidden device後在USB Mass Storage Device處就是Eject了!!! 關鍵代碼 function CM_Get_DevNode_Status(pulStatus: PULong; pulProblemNumber: PULong;
dnDevInst: DWord; ulFlags: ULong): DWord; stdcall;
external CfgMgr32ModuleName name 'CM_Get_DevNode_Status'; function CM_Request_Device_Eject(dnDevInst: DWord; out pVetoType: TPNPVetoType;
pszVetoName: PChar; ulNameLength: ULong; ulFlags: ULong): DWord; stdcall;
external SetupApiModuleName name 'CM_Request_Device_EjectA';
if (CM_Get_DevNode_Status(@Status, @Problem, DeviceInfoData.DevInst, 0) <> CR_SUCCESS) then
begin
exit;
end;
VetoName[0] := #0;
case CM_Request_Device_Eject(DeviceInfoData.DevInst, VetoType, @VetoName, SizeOf(VetoName), 0) of
CR_SUCCESS:
begin
MessageBox(Handle, PChar(’Eject OK (Veto: ' + VetoName + ')'), 'Vetoed', MB_OK); end;
CR_REMOVE_VETOED:
begin
MessageBox(Handle, PChar('Failed to eject the Device (Veto: ' + VetoName + ')'), 'Vetoed', MB_OK);
end;
else
begin
MessageBox(Handle, PChar('Failed to eject the Device (' + SysErrorMessage(GetLastError) + ')'), 'Failure', MB_OK);
end;
end; 那個Eject原代碼是有Bug的,修正如下 添加
function TForm1.GetDevInfo(var hDevInfo: hDevInfo): boolean;
begin
// Get a handle to all devices in all classes present on system
hDevInfo := SetupDiGetClassDevs(nil, nil, 0, DIGCF_PRESENT or DIGCF_ALLCLASSES);
Result := hDevInfo <> Pointer(INVALID_HANDLE_VALUE);
end; 調用為:
procedure TForm1.FormCreate(Sender: TObject);
begin
if (not LoadSetupAPI) then
begin
ShowMessage('Could not load SetupAPI.dll');
exit;
end;
DevInfo := nil;
ShowHidden := false;
// Get a handle to all devices in all classes present on system
if not GetDevInfo(DevInfo) then
begin
ShowMessage('GetClassDevs');
exit;
end;
// Get the Images for all classes, and bind to the TreeView
ClassImageListData.cbSize := SizeOf(TSPClassImageListData);
if (not SetupDiGetClassImageList(ClassImageListData)) then
begin
ShowMessage('GetClassImageList');
exit;
end;
ImageList.Handle := ClassImageListData.ImageList;
TreeView.Images := ImageList;
// Add the devices to the TreeView window.
EnumAddDevices(ShowHidden, TreeView, DevInfo);
end; procedure TForm1.mRefreshDisplayClick(Sender: TObject);
begin
if not GetDevInfo(DevInfo) then
begin
ShowMessage('GetClassDevs');
exit;
end;
EnumAddDevices(ShowHidden, TreeView, DevInfo);
end; case CM_Request_Device_Eject(DeviceInfoData.DevInst, VetoType, @VetoName, SizeOf(VetoName), 0) of
CR_SUCCESS:
begin
MessageBox(Handle, 'Successful to eject the Device', 'Done', MB_OK);
if not GetDevInfo(DevInfo) then
begin
ShowMessage('GetClassDevs');
exit;
end;
EnumAddDevices(ShowHidden, TreeView, DevInfo);
end;