Forum: Ruby Windows : Retrive Quick Launch toolbar items

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ak N. (Guest)
on 2009-03-23 12:03
How can I get Quick Launch toolbar items, present in the explorer/
desktop area? (Where you can see "Show Desktop"  menu item)

Regards,
--AK
Heesob P. (Guest)
on 2009-03-23 12:33
(Received via mailing list)
2009/3/23 Ak Newfish <removed_email_address@domain.invalid>:
> How can I get Quick Launch toolbar items, present in the explorer/
> desktop area? (Where you can see "Show Desktop"  menu item)
>
puts Dir.entries(ENV['USERPROFILE']+'\Application
Data\Microsoft\Internet Explorer\Quick Launch')

Regards,

Park H.
Ak N. (Guest)
on 2009-03-23 13:07
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?

Regards,
--AK.
Heesob P. (Guest)
on 2009-03-23 17:21
(Received via mailing list)
Hi,

2009/3/23 Ak Newfish <removed_email_address@domain.invalid>:
> 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 H.
Ak N. (Guest)
on 2009-03-24 06:26
Hi Park,

Thanks for your code! I mean for System tray icons and code worked like
a fly :-)

Thanks a ton for your help.

Regards,
--AK
This topic is locked and can not be replied to.