From: Heesob Park Date: 2009-03-24T00:18:05+09:00 Subject: Re: Windows : Retrive Quick Launch toolbar items Hi, 2009/3/23 Ak Newfish : > Hi Park, > > Thanks a ton! works fine. > > I have another problem pops up on my way, should need to get the > Notification area items (where you can see "volume control"), present in > the explorer/desktop area. > > How to get notification area items? > If you mean system tray icons, that's not easy as you think. Here is the code: require 'Win32API' PROCESS_QUERY_INFORMATION = 1024 PROCESS_ALL_ACCESS = 0x1F0FFF WM_USER = 0x400 TB_BUTTONCOUNT = (WM_USER+24) TB_GETBUTTON = (WM_USER+23) MEM_COMMIT = 0x1000 MEM_RELEASE = 0x8000 PAGE_READWRITE = 0x4 TBSTATE_HIDDE = 0x8 FindWindow = Win32API.new('user32', 'FindWindow', 'PP', 'L') FindWindowEx = Win32API.new('user32', 'FindWindowEx', 'LLPP', 'L') SendMessage = Win32API.new('user32', 'SendMessage', 'LILL', 'L') GetWindowThreadProcessId = Win32API.new('user32', 'GetWindowThreadProcessId', 'LP', 'L') OpenProcess = Win32API.new('kernel32', 'OpenProcess', 'LIL', 'L') GetModuleFileNameEx = Win32API.new('psapi', 'GetModuleFileNameEx', 'LLPL', 'L') CloseHandle = Win32API.new('kernel32', 'CloseHandle', 'L', 'L') ReadProcessMemory = Win32API.new('kernel32', 'ReadProcessMemory', 'LLPLP', 'L') VirtualAllocEx = Win32API.new('kernel32', 'VirtualAllocEx', 'LLLLL', 'L') VirtualFreeEx = Win32API.new('kernel32', 'VirtualFreeEx', 'LLL', 'L') def getProcessNameFromhWnd(dwhWnd) ppid = 0.chr * 4 GetWindowThreadProcessId.call(dwhWnd,ppid) pid = ppid.unpack('L').first hProcess = OpenProcess.call(PROCESS_ALL_ACCESS, 0, pid) buffer = 0.chr * 1024 cbLen = GetModuleFileNameEx.call(hProcess, 0, buffer, buffer.length) CloseHandle.call(hProcess) buffer.strip end # Get the tray window handle. ( Window XP). hWindow = FindWindow.call("Shell_TrayWnd", 0) hWindow = FindWindowEx.call(hWindow, 0, "TrayNotifyWnd", 0) hWindow = FindWindowEx.call(hWindow, 0, "SysPager", 0) hWindow = FindWindowEx.call(hWindow, 0, "ToolbarWindow32", 0) # Get the count of buttons in tray window. trayCount = SendMessage.call(hWindow, TB_BUTTONCOUNT, 0, 0) ppid = 0.chr * 4 GetWindowThreadProcessId.call(hWindow, ppid) pid = ppid.unpack('L').first hProcess = OpenProcess.call(PROCESS_ALL_ACCESS, 0, pid) addr = VirtualAllocEx.call(hProcess, 0, 24, MEM_COMMIT, PAGE_READWRITE) for cb in 0 ... trayCount tray = 0.chr * 24 tb = 0.chr * 20 SendMessage.call(hWindow,TB_GETBUTTON,cb,addr) cbRead = 0.chr * 4 ReadProcessMemory.call(hProcess,addr,tb,tb.length,cbRead) fsState = tb[8,1].unpack('c').first if fsState != TBSTATE_HIDDE ReadProcessMemory.call(hProcess,tb[12,4].unpack('L').first,tray,tray.length,cbRead) name = getProcessNameFromhWnd(tray[0,4].unpack('L').first) puts name end end VirtualFreeEx.call(hProcess,addr,0,MEM_RELEASE) CloseHandle.call(hProcess) Regards, Park Heesob