Автор: Zloy_Gelud
Дата сообщения: 10.07.2012 18:04
Unique_nickname
Необходимы некоторые заморочки с обращением к окнам созданным другими процессом.
Добавлено:
Вот рабочий код:
[more]if not SysTray then SysTray = {}; end
--[[ Функция возвращает дескиптор окна системного трея]]
SysTray.FindToolbarWindow = function()
local hWnd = -1;
local tSystemInfo = System.GetOSVersionInfo();
hWnd = tonumber(DLL.CallFunction("user32.dll", "FindWindowA", "\"Shell_TrayWnd\",0", 0, 1));
if hWnd == 0 then return -1; end
hWnd = tonumber(DLL.CallFunction("user32.dll", "FindWindowExA", hWnd..",0,\"TrayNotifyWnd\",0", 0, 1));
if hWnd == 0 then return -1; end
hWnd = tonumber(DLL.CallFunction("user32.dll", "FindWindowExA", hWnd..",0,\"SysPager\",0", 0, 1));
if hWnd == 0 then return -1; end
hWnd = tonumber(DLL.CallFunction("user32.dll", "FindWindowExA", hWnd..",0,\"ToolbarWindow32\",0", 0, 1));
if hWnd == 0 then return -1; end
return hWnd;
end
SysTray._HANDLE = SysTray.FindToolbarWindow();
SysTray.GetIconCount = function()
if not SysTray._HANDLE or SysTray._HANDLE == -1 then return -1; end
return tonumber(DLL.CallFunction("user32.dll", "SendMessageA", SysTray._HANDLE..", 1048, 0, 0", DLL_RETURN_TYPE_LONG, DLL_CALL_STDCALL));
end
---[[
SysTray.GetIconText = function(nIconIndex)
local sIconText = "";
if not SysTray._HANDLE or SysTray._HANDLE == -1 then return ""; end
local hID = Memory.Allocate(4);
DLL.CallFunction("user32.dll", "GetWindowThreadProcessId", SysTray._HANDLE..","..hID, DLL_RETURN_TYPE_LONG, DLL_CALL_STDCALL);
local nIDSysTrayProcess = Memory.GetInt(hID);
Memory.Free(hID);
local hSysTrayProcess = tonumber(DLL.CallFunction("kernel32.dll", "OpenProcess", "24, 0, "..nIDSysTrayProcess, DLL_RETURN_TYPE_LONG, DLL_CALL_STDCALL));
if hSysTrayProcess == 0 then return ""; end
local nBuffer = tonumber(DLL.CallFunction("user32.dll", "SendMessageA", SysTray._HANDLE..", 1069, "..nIconIndex..", 0", DLL_RETURN_TYPE_LONG, DLL_CALL_STDCALL));
if nBuffer == -1 then return ""; end
nBuffer = 2 * (nBuffer + 1);
local pBufferSrc = tonumber(DLL.CallFunction("kernel32.dll", "VirtualAllocEx", hSysTrayProcess..",0,"..nBuffer..",12288,4", DLL_RETURN_TYPE_LONG, DLL_CALL_STDCALL));
local pBufferDest = Memory.Allocate(nBuffer);
DLL.CallFunction("user32.dll", "SendMessageA", SysTray._HANDLE..", 1069, "..nIconIndex..", "..pBufferSrc, DLL_RETURN_TYPE_LONG, DLL_CALL_STDCALL);
local pBuffer = tonumber(DLL.CallFunction("kernel32.dll", "ReadProcessMemory", hSysTrayProcess..","..pBufferSrc..","..pBufferDest..","..nBuffer..",0", DLL_RETURN_TYPE_LONG, DLL_CALL_STDCALL));
sIconText = Memory.GetString(pBufferDest, -1, "Ascii");
DLL.CallFunction("kernel32.dll", "VirtualFreeEx", hSysTrayProcess..","..pBufferSrc..",0,32768", DLL_RETURN_TYPE_LONG, DLL_CALL_STDCALL);
Memory.Free(pBuffer);
DLL.CallFunction("kernel32.dll", "CloseHandle", hSysTrayProcess, DLL_RETURN_TYPE_LONG, DLL_CALL_STDCALL);
return sIconText;
end
n = SysTray.GetIconCount();
for i = 0, n - 1 do
Dialog.Message("Notice", SysTray.GetIconText(i), MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
end[/more]