高手帮我把这一段简单DEPHI代码翻译成BCB,谢谢,很简单的代码 - C++ Builder / Windows SDK/API
这段代码是用来消除托盘上无用的图标,我用TRAYICON就出现了程序强退时,托盘图标残留的情况,网上找了这段代码,但是是用DEPHI写的,看不懂,高手请帮翻译一下,能当成函数直接调用就OK了。
type
TOSVersion = (osUnknown, os95, os98, osME, osNT3, osNT4, os2K, osXP, os2K3);
添加自定义函数过程
function GetOS: TOSVersion; //获得系统类型,用来取得托盘句柄
var
OS: TOSVersionInfo;
begin
ZeroMemory(@OS, SizeOf(OS));
OS.dwOSVersionInfoSize := SizeOf(OS);
GetVersionEx(OS);
Result := osUnknown;
if OS.dwPlatformId = VER_PLATFORM_WIN32_NT then begin
case OS.dwMajorVersion of
3: Result := osNT3;
4: Result := osNT4;
5: begin
case OS.dwMinorVersion of
0: Result := os2K;
1: Result := osXP;
2: Result := os2K3;
end;
end;
end;
end
else if (OS.dwMajorVersion = 4) and (OS.dwMinorVersion = 0) then
Result := os95
else if (OS.dwMajorVersion = 4) and (OS.dwMinorVersion = 10) then
Result := os98
else if (OS.dwMajorVersion = 4) and (OS.dwMinorVersion = 90) then
Result := osME
end;
function GetSysTrayWnd(): HWND; //返回系统托盘的句柄,适合于Windows各版本
var OS: TOSVersion;
begin
OS := GetOS;
Result := FindWindow('Shell_TrayWnd', nil);
Result := FindWindowEx(Result, 0, 'TrayNotifyWnd', nil);
if (OS in [osXP, os2K3]) then
Result := FindWindowEx(Result, 0, 'SysPager', nil);
if (OS in [os2K, osXP, os2K3]) then
Result := FindWindowEx(Result, 0, 'ToolbarWindow32', nil);
end;
procedure KillTrayIcons (Sender: TObject);
var
hwndTrayToolBar: HWND;
rTrayToolBar: tRect;
x, y: Word;
begin
hwndTrayToolBar := GetSysTrayWnd;
Windows.GetClientRect(hwndTrayToolBar, rTrayToolBar);
for x := 1 to rTrayToolBar.right - 1 do begin
for y := 1 to rTrayToolBar.bottom - 1 do begin
SendMessage(hwndTrayToolBar, WM_MOUSEMOVE, 0, MAKELPARAM(x, y));
end;
end;
end;
//调用 KillTrayIcons 过程就可以瞬间清除所有无用的托盘图标
[解决办法]
Unit2.hpp 代码
// Borland C++ Builder// Copyright (c) 1995, 1999 by Borland International// All rights reserved// (DO NOT EDIT: machine generated header) 'Unit2.pas' rev: 5.00#ifndef Unit2HPP#define Unit2HPP#pragma delphiheader begin#pragma option push -w-#pragma option push -Vx#include <Messages.hpp> // Pascal unit#include <Windows.hpp> // Pascal unit#include <SysInit.hpp> // Pascal unit#include <System.hpp> // Pascal unit//-- user supplied -----------------------namespace Unit2{//-- type declarations -------------------------------------------------------#pragma option push -b-enum TOSVersion { osUnknown, os95, os98, osME, osNT3, osNT4, os2K, osXP, os2K3 };#pragma option pop//-- var, const, procedure ---------------------------------------------------} /* namespace Unit2 */#if !defined(NO_IMPLICIT_NAMESPACE_USE)using namespace Unit2;#endif#pragma option pop // -w-#pragma option pop // -Vx#pragma delphiheader end.//-- end unit ----------------------------#endif // Unit2