急需《在Win2000下弹出U盘的代码》,高分等待 1、在程序中,通过按钮直接把U盘弹出来。 2、获取系统中的所有U盘盘符(已实现,不过如果有更好的代码,请贴上来)
解决方案 »
- delphi中如何将EXCEL中的数据导入到SQL2000中
- 数值型字符串加1
- 用Delphi操作LCD:怎么显示,怎么清空????
- 如何在状态栏中加载背景图片 !!!!!!!!!!!!!!
- 怎么在程序运行期间动态的改变某控件的名字?
- Websnap中TEnduserSessionAdapter组件的TadapterField问题~~~~~~~~~~~~~~~~~~~~~~~~~~
- 類的問題,請幫忙
- delphi+sql2000
- 如题,比如如何时时兼控计算机打开www.google.cn并输入'delphi'呢?谢谢,!
- DELPHI7使用的ExpressQuantumGrid最新版本是多少?
- 有没有办法让一个网页得到我机子的IP是我任意指定的一个IP?
- delphi如何支持多语言
我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;
[email protected]
郁闷的原来的连接,FAQ中的(估计你都没看FAQ的,汗~)http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=197585
\http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=200977